better handling of file watchers

feature/settings-window
Michael Ochmann 3 years ago
parent 5d943b1240
commit 43d1ef1e33
  1. 17
      src/Ation.js

@ -28,7 +28,7 @@ class Ation {
app.whenReady().then(async () => { app.whenReady().then(async () => {
if (this.fileToOpen) if (this.fileToOpen)
this.openFile(this.fileToOpen, true); this.openFile(this.fileToOpen);
protocol.registerFileProtocol("slideimg", (request, callback) => { protocol.registerFileProtocol("slideimg", (request, callback) => {
const uri = request.url.replace(/^slideimg:\/\//, ""); const uri = request.url.replace(/^slideimg:\/\//, "");
const extension = path.extname(uri).replace(/^\./, ""); const extension = path.extname(uri).replace(/^\./, "");
@ -64,14 +64,19 @@ class Ation {
const basePath = path.dirname(filePath); const basePath = path.dirname(filePath);
const data = parser(fileContents); const data = parser(fileContents);
if (!change) if (!change)
this.currentFile = filePath; this.currentFile = filePath;
if (this.watcher)
this.watcher = fsn.watch(filePath, () => { this.watcher.close();
this.openFile(this.currentFile, true); this.watcher = fsn.watch(filePath, (eventType, path) => {
if (path.match(/~$/)) // handling unix swap files here
setTimeout(() => this.openFile(this.currentFile, true), 1000);
else
this.openFile(this.currentFile, true);
}); });
this.windowManager.mainWindow.send("Ation::openFile", [basePath, data]); this.windowManager.mainWindow.send("Ation::openFile", [basePath, data]);
} catch { } catch (error) {
console.log(error);
return; return;
} }
} }

Loading…
Cancel
Save