mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-27 17:31:36 -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",
|
||||
"description": "Symphony desktop app (Foundation ODP)",
|
||||
"author": "Symphony",
|
||||
"main": "lib/src/app/main.js",
|
||||
"types": "lib/src/app/main.d.ts",
|
||||
"main": "lib/src/app/init.js",
|
||||
"types": "lib/src/app/init.d.ts",
|
||||
"scripts": {
|
||||
"compile": "npm run lint && gulp build",
|
||||
"lint": "tslint --project tsconfig.json",
|
||||
|
@ -45,11 +45,13 @@ let {
|
||||
launchOnStartup,
|
||||
alwaysOnTop: isAlwaysOnTop,
|
||||
bringToFront,
|
||||
memoryRefresh,
|
||||
} = config.getConfigFields([
|
||||
'minimizeOnClose',
|
||||
'launchOnStartup',
|
||||
'alwaysOnTop',
|
||||
'bringToFront',
|
||||
'memoryRefresh',
|
||||
]) as IConfig;
|
||||
|
||||
const menuItemsArray = Object.keys(menuSections)
|
||||
@ -220,19 +222,6 @@ export class AppMenu {
|
||||
*/
|
||||
private buildWindowMenu(): Electron.MenuItemConstructorOptions {
|
||||
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[] = [
|
||||
this.assignRoleOrLabel({ role: 'minimize', label: i18n.t('Minimize')() }),
|
||||
@ -282,8 +271,28 @@ export class AppMenu {
|
||||
: i18n.t('Bring to Front on Notifications')(),
|
||||
type: 'checkbox',
|
||||
},
|
||||
hamburgerMenuItem,
|
||||
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) => {
|
||||
if (focusedWindow && !focusedWindow.isDestroyed()) {
|
||||
@ -297,16 +306,17 @@ export class AppMenu {
|
||||
},
|
||||
label: i18n.t('Clear cache and Reload')(),
|
||||
},
|
||||
this.buildSeparator(),
|
||||
];
|
||||
|
||||
if (isWindowsOS) {
|
||||
submenu.push({
|
||||
label: i18n.t('About Symphony')(),
|
||||
click(_menuItem, focusedWindow) {
|
||||
const windowName = focusedWindow ? (focusedWindow as ICustomBrowserWindow).winName : '';
|
||||
windowHandler.createAboutAppWindow(windowName);
|
||||
submenu.push(
|
||||
{
|
||||
role: 'quit',
|
||||
visible: isWindowsOS,
|
||||
label: i18n.t('Quit Symphony')(),
|
||||
},
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
@ -358,10 +368,17 @@ export class AppMenu {
|
||||
message: i18n.t('Dev Tools has been disabled. Please contact your system administrator')(),
|
||||
});
|
||||
},
|
||||
},{
|
||||
click: () => windowHandler.createMoreInfoWindow(),
|
||||
label: i18n.t('More Information')(),
|
||||
}],
|
||||
}, {
|
||||
click: () => windowHandler.createMoreInfoWindow(),
|
||||
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() {
|
||||
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`);
|
||||
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