Wiring change detection to render process
This commit is contained in:
parent
5c19d82834
commit
c599013af4
35
newton/fs.js
35
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) {
|
||||
if (useRelativePath)
|
||||
return fs.readFileSync(
|
||||
path.join(__dirname, _path),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
if (watchFile)
|
||||
watcher.add(_path);
|
||||
|
||||
return fs.readFileSync(_path, 'utf8');
|
||||
} else {
|
||||
let fpath = path.join(__dirname, _path);
|
||||
watcher.add(fpath);
|
||||
return fs.readFileSync(fpath, '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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ app.whenReady().then(async () => {
|
||||
app.quit();
|
||||
}
|
||||
|
||||
newton.settings.loadsettings();
|
||||
newton.settings.loadSettings();
|
||||
newton.fs.loadFilesWatcher();
|
||||
|
||||
loadHandlers();
|
||||
|
@ -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)),
|
||||
});
|
@ -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,
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -32,6 +32,8 @@ declare global {
|
||||
closeFile: (arg0: any) => Promise<string>,
|
||||
getPathForFile: any,
|
||||
onLoadFiles: (arg0: any) => Promise<string>,
|
||||
onChangedFile: (arg0: any) => Promise<string>,
|
||||
onDeletedFile: (arg0: any) => Promise<string>,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user