Refactored window naming; wired settings save call
This commit is contained in:
parent
18ac9b323d
commit
0eed524575
@ -18,10 +18,10 @@ let args = [];
|
||||
|
||||
// Note: https://tinydew4.gitbooks.io/electron/content/api/browser-window.html
|
||||
const createWindow = (startType = "build", debug = false, args = []) => {
|
||||
this.args = args;
|
||||
let data = settingsManager.getConfig();
|
||||
this.args = args;
|
||||
let data = settingsManager.getConfig();
|
||||
|
||||
const win = new BrowserWindow({
|
||||
const window = new BrowserWindow({
|
||||
title: "Newton",
|
||||
x: data["config"]["main_window_x"],
|
||||
y: data["config"]["main_window_y"],
|
||||
@ -44,39 +44,43 @@ const createWindow = (startType = "build", debug = false, args = []) => {
|
||||
}
|
||||
});
|
||||
|
||||
win.once('ready-to-show', () => {
|
||||
win.show();
|
||||
win.webContents.send('load-files', args);
|
||||
window.once('close', () => {
|
||||
settingsManager.saveConfig(window);
|
||||
});
|
||||
|
||||
menu.load(win);
|
||||
window.once('ready-to-show', () => {
|
||||
window.show();
|
||||
window.webContents.send('load-files', args);
|
||||
});
|
||||
|
||||
menu.load(window);
|
||||
systemTray.load(menu.menuStruct);
|
||||
|
||||
// win.setAutoHideMenuBar(true)
|
||||
// window.setAutoHideMenuBar(true)
|
||||
|
||||
if (debug == true) {
|
||||
win.webContents.openDevTools();
|
||||
window.webContents.openDevTools();
|
||||
}
|
||||
|
||||
if (startType === "build") {
|
||||
win.loadFile(
|
||||
window.loadFile(
|
||||
path.join(__dirname, `${BASE_PATH}/index.html`)
|
||||
);
|
||||
}
|
||||
|
||||
if (startType === "ng-serve") {
|
||||
win.loadURL('http://localhost:4200');
|
||||
window.loadURL('http://localhost:4200');
|
||||
}
|
||||
|
||||
// const child = new BrowserWindow({parent: win, modal: true, show: false})
|
||||
// child.loadFile(
|
||||
// const childWindow = new BrowserWindow({parent: window, modal: true, show: false})
|
||||
// childWindow.loadFile(
|
||||
// path.join(__dirname, `${BASE_PATH}/index.html`)
|
||||
// );
|
||||
// child.once('ready-to-show', () => {
|
||||
// child.show()
|
||||
// childWindow.once('ready-to-show', () => {
|
||||
// childWindow.show()
|
||||
// });
|
||||
|
||||
return win;
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,6 +47,10 @@ const setWindow = (win) => {
|
||||
window = win;
|
||||
}
|
||||
|
||||
const saveSettingsConfigData = (data) => {
|
||||
saveFile(SETTINGS_CONFIG_PATH, data);
|
||||
}
|
||||
|
||||
const saveFile = (fpath, content) => {
|
||||
fs.writeFile(fpath, content, (err) => {
|
||||
if (!err) return
|
||||
@ -130,6 +134,7 @@ module.exports = {
|
||||
getFileContents: getFileContents,
|
||||
getLspConfigData: getLspConfigData,
|
||||
getSettingsConfigData: getSettingsConfigData,
|
||||
saveSettingsConfigData: saveSettingsConfigData,
|
||||
loadFilesWatcher: loadFilesWatcher,
|
||||
unwatchFile: unwatchFile,
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ const createWindow = () => {
|
||||
|
||||
const handleExitSignal = (code) => {
|
||||
if (!hasExitSaved) {
|
||||
newton.settings.saveConfig();
|
||||
newton.settings.saveConfig(window);
|
||||
hasExitSaved = true;
|
||||
}
|
||||
|
||||
@ -108,8 +108,5 @@ app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
};
|
||||
|
||||
newton.settings.saveConfig();
|
||||
});
|
||||
|
||||
|
||||
|
@ -14,8 +14,19 @@ const getConfig = () => {
|
||||
return config;
|
||||
}
|
||||
|
||||
const saveConfig = () => {
|
||||
console.log(config);
|
||||
const saveConfig = (window) => {
|
||||
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 = () => {
|
||||
@ -31,4 +42,4 @@ module.exports = {
|
||||
getConfig: getConfig,
|
||||
saveConfig: saveConfig,
|
||||
}
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue
Block a user