diff --git a/newton/fs.js b/newton/fs.js index 4fedb43..1e9000b 100644 --- a/newton/fs.js +++ b/newton/fs.js @@ -14,30 +14,41 @@ let window = null; let watcher = null; + const getIconPath = () => { return path.join(CONFIG_PATH, "./icons/newton.png"); } const getSettingsConfigData = () => { - return getFileContents(SETTINGS_CONFIG_PATH); + return getFileContents( + SETTINGS_CONFIG_PATH, + useRelativePath = false, + watchFile = false + ); } const getLspConfigData = () => { - const config = getFileContents(LSP_CONFIG_PATH, useRelativePath = true); - return config.replaceAll("{user.home}", HOME_DIR); + return getFileContents( + LSP_CONFIG_PATH, + useRelativePath = true, + watchFile = false + ).replaceAll("{user.home}", HOME_DIR); } -const getFileContents = (_path, useRelativePath = false) => { +const getFileContents = (_path, useRelativePath = false, watchFile = true) => { console.log(`Getting Contents For: ${_path}`); try { - if (!useRelativePath) { - return fs.readFileSync(_path, 'utf8'); - } else { - let fpath = path.join(__dirname, _path); - watcher.add(fpath); - return fs.readFileSync(fpath, 'utf8'); - } + if (useRelativePath) + return fs.readFileSync( + path.join(__dirname, _path), + 'utf8' + ); + + if (watchFile) + watcher.add(_path); + + return fs.readFileSync(_path, 'utf8'); } catch(err) { return `{"message": {"type": "error", "text": "Error: Could not read ${_path}"}}`; } @@ -107,8 +118,10 @@ const loadFilesWatcher = () => { watcher.on('change', (fpath) => { console.debug("File (changed) : ", fpath); + window.webContents.send('file-changed', fpath); }).on('unlink', (fpath) => { - console.debug("File (unlinked) : ", fpath); + console.debug("File (deleted) : ", fpath); + window.webContents.send('file-deleted', fpath); }); } diff --git a/newton/main.js b/newton/main.js index e41c97c..f5df620 100644 --- a/newton/main.js +++ b/newton/main.js @@ -89,7 +89,7 @@ app.whenReady().then(async () => { app.quit(); } - newton.settings.loadsettings(); + newton.settings.loadSettings(); newton.fs.loadFilesWatcher(); loadHandlers(); diff --git a/newton/preload.js b/newton/preload.js index f1c0764..5646dfe 100644 --- a/newton/preload.js +++ b/newton/preload.js @@ -22,4 +22,6 @@ contextBridge.exposeInMainWorld('fs', { closeFile: (path) => ipcRenderer.invoke("closeFile", path), getPathForFile: (file) => webUtils.getPathForFile(file), onLoadFiles: (callback) => ipcRenderer.on('load-files', (_event, paths) => callback(paths)), + onChangedFile: (callback) => ipcRenderer.on('file-changed', (_event, path) => callback(path)), + onDeletedFile: (callback) => ipcRenderer.on('file-deleted', (_event, path) => callback(path)), }); \ No newline at end of file diff --git a/newton/settings-manager.js b/newton/settings-manager.js index 4b4b4ab..2448a25 100644 --- a/newton/settings-manager.js +++ b/newton/settings-manager.js @@ -4,7 +4,7 @@ const { newtonFs } = require('./fs'); let config = {}; -const loadsettings = () => { +const loadSettings = () => { config = JSON.parse( newtonFs.getSettingsConfigData() ); @@ -38,7 +38,7 @@ const getIconPath = () => { module.exports = { settingsManager: { getIconPath: getIconPath, - loadsettings: loadsettings, + loadSettings: loadSettings, getConfig: getConfig, saveConfig: saveConfig, } diff --git a/src/app/editor/editors.component.ts b/src/app/editor/editors.component.ts index 2aec7d5..55cac4f 100644 --- a/src/app/editor/editors.component.ts +++ b/src/app/editor/editors.component.ts @@ -134,6 +134,14 @@ export class EditorsComponent { this.setSession(file); }); + window.fs.onChangedFile(async (path: string) => { + console.log(path); + }); + + window.fs.onDeletedFile(async (path: string) => { + console.log(path); + }); + window.main.onMenuActions(async (action: string) => { let editorComponent = this.getActiveEditorComponent(); let editor = editorComponent.editor; diff --git a/src/polyfills.ts b/src/polyfills.ts index e32ca37..2ee3027 100644 --- a/src/polyfills.ts +++ b/src/polyfills.ts @@ -32,6 +32,8 @@ declare global { closeFile: (arg0: any) => Promise, getPathForFile: any, onLoadFiles: (arg0: any) => Promise, + onChangedFile: (arg0: any) => Promise, + onDeletedFile: (arg0: any) => Promise, } } } \ No newline at end of file