-
Notifications
You must be signed in to change notification settings - Fork 295
/
buildAppMenus.js
144 lines (129 loc) · 4.04 KB
/
buildAppMenus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// @flow
import { app, globalShortcut, Menu, BrowserWindow, dialog } from 'electron';
import { environment } from '../environment';
import { winLinuxMenu } from '../menus/win-linux';
import { osxMenu } from '../menus/osx';
import { logger } from './logging';
import { safeExitWithCode } from './safeExitWithCode';
import { CardanoNode } from '../cardano/CardanoNode';
import { DIALOGS, PAGES } from '../../common/ipc/constants';
import { showUiPartChannel } from '../ipc/control-ui-parts';
import { getTranslation } from './getTranslation';
export const buildAppMenus = async (
mainWindow: BrowserWindow,
cardanoNode: ?CardanoNode,
locale: string,
data: {
isUpdateAvailable: boolean,
isNavigationEnabled: boolean,
}
) => {
const { ABOUT, DAEDALUS_DIAGNOSTICS } = DIALOGS;
const { SETTINGS, WALLET_SETTINGS } = PAGES;
const { isUpdateAvailable, isNavigationEnabled } = data;
const { isMacOS, isBlankScreenFixActive } = environment;
const translations = require(`../locales/${locale}`);
const openAboutDialog = () => {
if (mainWindow) showUiPartChannel.send(ABOUT, mainWindow);
};
const openDaedalusDiagnosticsDialog = () => {
if (mainWindow) showUiPartChannel.send(DAEDALUS_DIAGNOSTICS, mainWindow);
};
const openSettingsPage = () => {
if (mainWindow) showUiPartChannel.send(SETTINGS, mainWindow);
};
const openWalletSettingsPage = () => {
if (mainWindow) showUiPartChannel.send(WALLET_SETTINGS, mainWindow);
};
const restartWithBlankScreenFix = async () => {
logger.info('Restarting in BlankScreenFix...');
if (cardanoNode) await cardanoNode.stop();
logger.info('Exiting Daedalus with code 21', { code: 21 });
safeExitWithCode(21);
};
const restartWithoutBlankScreenFix = async () => {
logger.info('Restarting without BlankScreenFix...');
if (cardanoNode) await cardanoNode.stop();
logger.info('Exiting Daedalus with code 22', { code: 22 });
safeExitWithCode(22);
};
const toggleBlankScreenFix = async (item) => {
const translation = getTranslation(translations, 'menu');
const blankScreenFixDialogOptions = {
buttons: [
translation('helpSupport.blankScreenFixDialogConfirm'),
translation('helpSupport.blankScreenFixDialogCancel'),
],
type: 'warning',
title: isBlankScreenFixActive
? translation('helpSupport.blankScreenFixDialogTitle')
: translation('helpSupport.nonBlankScreenFixDialogTitle'),
message: isBlankScreenFixActive
? translation('helpSupport.blankScreenFixDialogMessage')
: translation('helpSupport.nonBlankScreenFixDialogMessage'),
defaultId: 1,
cancelId: 1,
noLink: true,
};
const { response } = await dialog.showMessageBox(
mainWindow,
blankScreenFixDialogOptions
);
if (response === 0) {
if (isBlankScreenFixActive) {
restartWithoutBlankScreenFix();
} else {
restartWithBlankScreenFix();
}
}
item.checked = isBlankScreenFixActive;
};
const menuActions = {
openAboutDialog,
openDaedalusDiagnosticsDialog,
openSettingsPage,
openWalletSettingsPage,
toggleBlankScreenFix,
};
// Build app menus
let menu;
if (isMacOS) {
menu = Menu.buildFromTemplate(
osxMenu(
app,
mainWindow,
menuActions,
translations,
locale,
isUpdateAvailable,
isNavigationEnabled
)
);
Menu.setApplicationMenu(menu);
} else {
menu = Menu.buildFromTemplate(
winLinuxMenu(
app,
mainWindow,
menuActions,
translations,
locale,
isUpdateAvailable,
isNavigationEnabled
)
);
mainWindow.setMenu(menu);
}
// Hide application window on Cmd+H hotkey (OSX only!)
if (isMacOS) {
app.on('activate', () => {
if (!mainWindow.isVisible()) app.show();
});
mainWindow.on('focus', () => {
globalShortcut.register('CommandOrControl+H', app.hide);
});
mainWindow.on('blur', () => {
globalShortcut.unregister('CommandOrControl+H');
});
}
};