mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-28 09:51:06 -06:00
Typescript (Fix custom user data path and menu items) (#655)
* Typescript - Fix custom user data path * Typescript - Fix menu items for Windows OS * Typescript - Fix indentation & menu items
This commit is contained in:
parent
eccb062635
commit
586e0f0f25
@ -6,8 +6,8 @@
|
|||||||
"buildNumber": "0",
|
"buildNumber": "0",
|
||||||
"description": "Symphony desktop app (Foundation ODP)",
|
"description": "Symphony desktop app (Foundation ODP)",
|
||||||
"author": "Symphony",
|
"author": "Symphony",
|
||||||
"main": "lib/src/app/main.js",
|
"main": "lib/src/app/init.js",
|
||||||
"types": "lib/src/app/main.d.ts",
|
"types": "lib/src/app/init.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "npm run lint && gulp build",
|
"compile": "npm run lint && gulp build",
|
||||||
"lint": "tslint --project tsconfig.json",
|
"lint": "tslint --project tsconfig.json",
|
||||||
|
@ -45,11 +45,13 @@ let {
|
|||||||
launchOnStartup,
|
launchOnStartup,
|
||||||
alwaysOnTop: isAlwaysOnTop,
|
alwaysOnTop: isAlwaysOnTop,
|
||||||
bringToFront,
|
bringToFront,
|
||||||
|
memoryRefresh,
|
||||||
} = config.getConfigFields([
|
} = config.getConfigFields([
|
||||||
'minimizeOnClose',
|
'minimizeOnClose',
|
||||||
'launchOnStartup',
|
'launchOnStartup',
|
||||||
'alwaysOnTop',
|
'alwaysOnTop',
|
||||||
'bringToFront',
|
'bringToFront',
|
||||||
|
'memoryRefresh',
|
||||||
]) as IConfig;
|
]) as IConfig;
|
||||||
|
|
||||||
const menuItemsArray = Object.keys(menuSections)
|
const menuItemsArray = Object.keys(menuSections)
|
||||||
@ -220,19 +222,6 @@ export class AppMenu {
|
|||||||
*/
|
*/
|
||||||
private buildWindowMenu(): Electron.MenuItemConstructorOptions {
|
private buildWindowMenu(): Electron.MenuItemConstructorOptions {
|
||||||
logger.info(`app-menu: building window menu`);
|
logger.info(`app-menu: building window menu`);
|
||||||
const hamburgerMenuItem = isWindowsOS
|
|
||||||
? {
|
|
||||||
label: this.titleBarStyle === TitleBarStyles.NATIVE
|
|
||||||
? i18n.t('Enable Hamburger menu')()
|
|
||||||
: i18n.t('Disable Hamburger menu')(),
|
|
||||||
click: () => {
|
|
||||||
const isNativeStyle = this.titleBarStyle === TitleBarStyles.NATIVE;
|
|
||||||
|
|
||||||
this.titleBarStyle = isNativeStyle ? TitleBarStyles.NATIVE : TitleBarStyles.CUSTOM;
|
|
||||||
titleBarChangeDialog(isNativeStyle);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: this.buildSeparator();
|
|
||||||
|
|
||||||
const submenu: MenuItemConstructorOptions[] = [
|
const submenu: MenuItemConstructorOptions[] = [
|
||||||
this.assignRoleOrLabel({ role: 'minimize', label: i18n.t('Minimize')() }),
|
this.assignRoleOrLabel({ role: 'minimize', label: i18n.t('Minimize')() }),
|
||||||
@ -282,8 +271,28 @@ export class AppMenu {
|
|||||||
: i18n.t('Bring to Front on Notifications')(),
|
: i18n.t('Bring to Front on Notifications')(),
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
},
|
},
|
||||||
hamburgerMenuItem,
|
|
||||||
this.buildSeparator(),
|
this.buildSeparator(),
|
||||||
|
{
|
||||||
|
label: this.titleBarStyle === TitleBarStyles.NATIVE
|
||||||
|
? i18n.t('Enable Hamburger menu')()
|
||||||
|
: i18n.t('Disable Hamburger menu')(),
|
||||||
|
visible: isWindowsOS,
|
||||||
|
click: () => {
|
||||||
|
const isNativeStyle = this.titleBarStyle === TitleBarStyles.NATIVE;
|
||||||
|
|
||||||
|
this.titleBarStyle = isNativeStyle ? TitleBarStyles.NATIVE : TitleBarStyles.CUSTOM;
|
||||||
|
titleBarChangeDialog(isNativeStyle);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
checked: memoryRefresh,
|
||||||
|
click: async (item) => {
|
||||||
|
memoryRefresh = item.checked;
|
||||||
|
await config.updateUserConfig({ memoryRefresh });
|
||||||
|
},
|
||||||
|
label: i18n.t('Refresh app when idle')(),
|
||||||
|
type: 'checkbox',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
click: (_item, focusedWindow) => {
|
click: (_item, focusedWindow) => {
|
||||||
if (focusedWindow && !focusedWindow.isDestroyed()) {
|
if (focusedWindow && !focusedWindow.isDestroyed()) {
|
||||||
@ -297,16 +306,17 @@ export class AppMenu {
|
|||||||
},
|
},
|
||||||
label: i18n.t('Clear cache and Reload')(),
|
label: i18n.t('Clear cache and Reload')(),
|
||||||
},
|
},
|
||||||
|
this.buildSeparator(),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (isWindowsOS) {
|
if (isWindowsOS) {
|
||||||
submenu.push({
|
submenu.push(
|
||||||
label: i18n.t('About Symphony')(),
|
{
|
||||||
click(_menuItem, focusedWindow) {
|
role: 'quit',
|
||||||
const windowName = focusedWindow ? (focusedWindow as ICustomBrowserWindow).winName : '';
|
visible: isWindowsOS,
|
||||||
windowHandler.createAboutAppWindow(windowName);
|
label: i18n.t('Quit Symphony')(),
|
||||||
},
|
},
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -358,10 +368,17 @@ export class AppMenu {
|
|||||||
message: i18n.t('Dev Tools has been disabled. Please contact your system administrator')(),
|
message: i18n.t('Dev Tools has been disabled. Please contact your system administrator')(),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},{
|
}, {
|
||||||
click: () => windowHandler.createMoreInfoWindow(),
|
click: () => windowHandler.createMoreInfoWindow(),
|
||||||
label: i18n.t('More Information')(),
|
label: i18n.t('More Information')(),
|
||||||
}],
|
} ],
|
||||||
|
}, {
|
||||||
|
label: i18n.t('About Symphony')(),
|
||||||
|
visible: isWindowsOS,
|
||||||
|
click(_menuItem, focusedWindow) {
|
||||||
|
const windowName = focusedWindow ? (focusedWindow as ICustomBrowserWindow).winName : '';
|
||||||
|
windowHandler.createAboutAppWindow(windowName);
|
||||||
|
},
|
||||||
} ],
|
} ],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -200,6 +200,8 @@ class Config {
|
|||||||
*/
|
*/
|
||||||
private async readUserConfig() {
|
private async readUserConfig() {
|
||||||
if (!fs.existsSync(this.userConfigPath)) {
|
if (!fs.existsSync(this.userConfigPath)) {
|
||||||
|
// Need to wait until app ready event to access user data
|
||||||
|
await app.whenReady();
|
||||||
logger.info(`config-handler: user config doesn't exist! will create new one and update config`);
|
logger.info(`config-handler: user config doesn't exist! will create new one and update config`);
|
||||||
await this.updateUserConfig({ configVersion: app.getVersion().toString(), buildNumber } as IConfig);
|
await this.updateUserConfig({ configVersion: app.getVersion().toString(), buildNumber } as IConfig);
|
||||||
}
|
}
|
||||||
|
22
src/app/init.ts
Normal file
22
src/app/init.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { app } from 'electron';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
import { isDevEnv } from '../common/env';
|
||||||
|
import { getCommandLineArgs } from '../common/utils';
|
||||||
|
|
||||||
|
// Handle custom user data path from process.argv
|
||||||
|
const userDataPathArg: string | null = getCommandLineArgs(process.argv, '--userDataPath=', false);
|
||||||
|
const userDataPath = userDataPathArg && userDataPathArg.substring(userDataPathArg.indexOf('=') + 1);
|
||||||
|
|
||||||
|
// Set user data path before app ready event
|
||||||
|
if (isDevEnv) {
|
||||||
|
const appDataPath = app.getPath('appData');
|
||||||
|
app.setPath('userData', path.join(appDataPath, 'Symphony-dev'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userDataPath) {
|
||||||
|
app.setPath('userData', userDataPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// tslint:disable-next-line
|
||||||
|
require('./main');
|
Loading…
Reference in New Issue
Block a user