2019-10-26 14:46:04 +00:00
|
|
|
const { app, BrowserWindow, ipcMain } = require('electron');
|
2018-07-29 11:50:44 +00:00
|
|
|
const setupMenu = require('./menu');
|
2019-11-19 16:48:00 +00:00
|
|
|
const theme = require('../src/theme');
|
2018-07-29 11:50:44 +00:00
|
|
|
|
2019-07-16 06:59:35 +00:00
|
|
|
let mainWindow;
|
|
|
|
let winURL;
|
2018-07-29 11:50:44 +00:00
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'development') {
|
2019-07-16 06:59:35 +00:00
|
|
|
global.__static = require('path')
|
2019-09-03 09:43:16 +00:00
|
|
|
.join(__dirname, '/static')
|
2019-07-16 06:59:35 +00:00
|
|
|
.replace(/\\/g, '\\\\');
|
2019-09-03 09:43:16 +00:00
|
|
|
global.documentsPath = app.getPath('documents');
|
2018-07-29 11:50:44 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 17:08:51 +00:00
|
|
|
if (process.env.NODE_ENV === 'development') {
|
2019-07-16 06:59:35 +00:00
|
|
|
const { getAppConfig } = require('frappejs/webpack/utils');
|
2018-10-24 17:08:51 +00:00
|
|
|
const appConfig = getAppConfig();
|
|
|
|
winURL = `http://localhost:${appConfig.dev.devServerPort}`;
|
|
|
|
} else {
|
|
|
|
winURL = `file://${__dirname}/index.html`;
|
|
|
|
}
|
2018-07-29 11:50:44 +00:00
|
|
|
|
|
|
|
function createWindow() {
|
|
|
|
/**
|
|
|
|
* Initial window options
|
|
|
|
*/
|
2019-02-18 05:42:04 +00:00
|
|
|
|
2018-07-29 11:50:44 +00:00
|
|
|
mainWindow = new BrowserWindow({
|
2019-10-22 13:22:17 +00:00
|
|
|
vibrancy: 'sidebar',
|
|
|
|
transparent: true,
|
2019-10-26 14:46:04 +00:00
|
|
|
backgroundColor: '#80FFFFFF',
|
2019-10-04 17:59:05 +00:00
|
|
|
width: 1200,
|
|
|
|
height: 907,
|
2019-10-03 13:46:12 +00:00
|
|
|
frame: false,
|
2019-10-11 09:55:50 +00:00
|
|
|
resizable: false,
|
2018-10-24 17:08:51 +00:00
|
|
|
useContentSize: true,
|
|
|
|
webPreferences: {
|
2019-07-16 06:59:35 +00:00
|
|
|
webSecurity: false,
|
|
|
|
nodeIntegration: true
|
2018-10-24 17:08:51 +00:00
|
|
|
}
|
2019-07-16 06:59:35 +00:00
|
|
|
});
|
2018-07-29 11:50:44 +00:00
|
|
|
|
2019-07-16 06:59:35 +00:00
|
|
|
mainWindow.loadURL(winURL);
|
2018-07-29 11:50:44 +00:00
|
|
|
|
|
|
|
mainWindow.on('closed', () => {
|
2019-07-16 06:59:35 +00:00
|
|
|
mainWindow = null;
|
|
|
|
});
|
2018-07-29 11:50:44 +00:00
|
|
|
|
|
|
|
setupMenu();
|
|
|
|
}
|
|
|
|
|
2019-11-19 16:48:00 +00:00
|
|
|
function createSettingsWindow(tab = 'General') {
|
|
|
|
let settingsWindow = new BrowserWindow({
|
|
|
|
parent: mainWindow,
|
|
|
|
frame: false,
|
|
|
|
width: 460,
|
|
|
|
height: 577,
|
|
|
|
backgroundColor: theme.backgroundColor.gray['200'],
|
|
|
|
webPreferences: {
|
|
|
|
webSecurity: false,
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
settingsWindow.loadURL(`${winURL}/#/settings/${tab}`);
|
|
|
|
}
|
|
|
|
|
2019-11-19 19:18:27 +00:00
|
|
|
ipcMain.on('open-settings-window', (event, tab) => {
|
2019-11-19 16:48:00 +00:00
|
|
|
createSettingsWindow(tab);
|
|
|
|
});
|
|
|
|
|
2019-10-26 14:46:04 +00:00
|
|
|
ipcMain.on('reload-main-window', () => {
|
|
|
|
mainWindow.reload();
|
|
|
|
});
|
|
|
|
|
2019-07-16 06:59:35 +00:00
|
|
|
app.on('ready', createWindow);
|
2018-07-29 11:50:44 +00:00
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
if (process.platform !== 'darwin') {
|
2019-07-16 06:59:35 +00:00
|
|
|
app.quit();
|
2018-07-29 11:50:44 +00:00
|
|
|
}
|
2019-07-16 06:59:35 +00:00
|
|
|
});
|
2018-07-29 11:50:44 +00:00
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
if (mainWindow === null) {
|
2019-07-16 06:59:35 +00:00
|
|
|
createWindow();
|
2018-07-29 11:50:44 +00:00
|
|
|
}
|
2019-07-16 06:59:35 +00:00
|
|
|
});
|
2018-07-29 11:50:44 +00:00
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// Enable Auto Update
|
|
|
|
// https://www.electron.build/auto-update/
|