Refactored window naming; wired settings save call

This commit is contained in:
itdominator 2025-06-19 00:57:55 -05:00
parent 18ac9b323d
commit 0eed524575
4 changed files with 40 additions and 23 deletions

View File

@ -18,10 +18,10 @@ let args = [];
// Note: https://tinydew4.gitbooks.io/electron/content/api/browser-window.html // Note: https://tinydew4.gitbooks.io/electron/content/api/browser-window.html
const createWindow = (startType = "build", debug = false, args = []) => { const createWindow = (startType = "build", debug = false, args = []) => {
this.args = args; this.args = args;
let data = settingsManager.getConfig(); let data = settingsManager.getConfig();
const win = new BrowserWindow({ const window = new BrowserWindow({
title: "Newton", title: "Newton",
x: data["config"]["main_window_x"], x: data["config"]["main_window_x"],
y: data["config"]["main_window_y"], y: data["config"]["main_window_y"],
@ -44,39 +44,43 @@ const createWindow = (startType = "build", debug = false, args = []) => {
} }
}); });
win.once('ready-to-show', () => { window.once('close', () => {
win.show(); settingsManager.saveConfig(window);
win.webContents.send('load-files', args);
}); });
menu.load(win); window.once('ready-to-show', () => {
window.show();
window.webContents.send('load-files', args);
});
menu.load(window);
systemTray.load(menu.menuStruct); systemTray.load(menu.menuStruct);
// win.setAutoHideMenuBar(true) // window.setAutoHideMenuBar(true)
if (debug == true) { if (debug == true) {
win.webContents.openDevTools(); window.webContents.openDevTools();
} }
if (startType === "build") { if (startType === "build") {
win.loadFile( window.loadFile(
path.join(__dirname, `${BASE_PATH}/index.html`) path.join(__dirname, `${BASE_PATH}/index.html`)
); );
} }
if (startType === "ng-serve") { if (startType === "ng-serve") {
win.loadURL('http://localhost:4200'); window.loadURL('http://localhost:4200');
} }
// const child = new BrowserWindow({parent: win, modal: true, show: false}) // const childWindow = new BrowserWindow({parent: window, modal: true, show: false})
// child.loadFile( // childWindow.loadFile(
// path.join(__dirname, `${BASE_PATH}/index.html`) // path.join(__dirname, `${BASE_PATH}/index.html`)
// ); // );
// child.once('ready-to-show', () => { // childWindow.once('ready-to-show', () => {
// child.show() // childWindow.show()
// }); // });
return win; return window;
} }

View File

@ -47,6 +47,10 @@ const setWindow = (win) => {
window = win; window = win;
} }
const saveSettingsConfigData = (data) => {
saveFile(SETTINGS_CONFIG_PATH, data);
}
const saveFile = (fpath, content) => { const saveFile = (fpath, content) => {
fs.writeFile(fpath, content, (err) => { fs.writeFile(fpath, content, (err) => {
if (!err) return if (!err) return
@ -130,6 +134,7 @@ module.exports = {
getFileContents: getFileContents, getFileContents: getFileContents,
getLspConfigData: getLspConfigData, getLspConfigData: getLspConfigData,
getSettingsConfigData: getSettingsConfigData, getSettingsConfigData: getSettingsConfigData,
saveSettingsConfigData: saveSettingsConfigData,
loadFilesWatcher: loadFilesWatcher, loadFilesWatcher: loadFilesWatcher,
unwatchFile: unwatchFile, unwatchFile: unwatchFile,
} }

View File

@ -23,7 +23,7 @@ const createWindow = () => {
const handleExitSignal = (code) => { const handleExitSignal = (code) => {
if (!hasExitSaved) { if (!hasExitSaved) {
newton.settings.saveConfig(); newton.settings.saveConfig(window);
hasExitSaved = true; hasExitSaved = true;
} }
@ -108,8 +108,5 @@ app.on('window-all-closed', () => {
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {
app.quit() app.quit()
}; };
newton.settings.saveConfig();
}); });

View File

@ -14,8 +14,19 @@ const getConfig = () => {
return config; return config;
} }
const saveConfig = () => { const saveConfig = (window) => {
console.log(config); if (!window) return;
const windowBounds = window.getBounds();
config["config"]["main_window_x"] = windowBounds.x;
config["config"]["main_window_y"] = windowBounds.y;
config["config"]["main_window_width"] = windowBounds.width;
config["config"]["main_window_height"] = windowBounds.height;
newtonFs.saveSettingsConfigData(
JSON.stringify(config, null, 4)
);
} }
const getIconPath = () => { const getIconPath = () => {