Skip to content

Commit

Permalink
Improve annoying livereload reload behaviour for main/webview processes
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Jan 5, 2018
1 parent d375d08 commit f9cb20f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 0 additions & 2 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ export function watch() {
export function webserver() {
gulp.src([
paths.dest,
`!${paths.dest}/electron/**`,
`!${paths.dest}/webview/**`,
])
.pipe(server({
livereload: true,
Expand Down
18 changes: 18 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@
s.async = true;
s.setAttribute('src', lrHost + '/livereload.js');
document.body.appendChild(s);

s.onload = () => {
console.log('livereload loaded');
const originalReloadBehaviour = window._onLiveReloadFileChanged;

window._onLiveReloadFileChanged = (file) => {
if (!file.path.includes('/build/webview/') && !file.path.includes('/build/index.js') && !file.path.includes('/build/electron/')) {
originalReloadBehaviour(file);
} else {
if (file.path.includes('/build/webview/')) {
console.log('Livereload: Reloading all webvies');
const webviews = document.querySelectorAll('webview').forEach(webview => webview.reload());
} else {
console.log('Livereload: skip reload as only main process files have changed');
}
}
}
}
})();
}
</script>
Expand Down

0 comments on commit f9cb20f

Please sign in to comment.