|
1 | 1 | import {
|
2 | 2 | BrowserWindow,
|
3 |
| - clipboard, |
4 |
| - dialog, |
5 | 3 | MenuItemConstructorOptions,
|
| 4 | + ipcMain, |
6 | 5 | shell,
|
7 | 6 | } from 'electron';
|
8 |
| -import path from 'path'; |
9 | 7 |
|
10 |
| -import { getEnvironmentInfo, getPackageJson } from '../util'; |
| 8 | +import { EnvironmentInfo, getEnvironmentInfo } from '../util'; |
| 9 | +import { IPC_MAIN_CHANNELS } from '../../common/constants'; |
| 10 | +import { AppUpdater, AppUpdaterStatus } from '../app-updater'; |
11 | 11 |
|
12 |
| -const aboutOnClick = () => { |
13 |
| - const iconPath = path.join(__dirname, '../resources/icons/64x64.png'); |
14 |
| - const title = 'Responsively'; |
15 |
| - const { description } = getPackageJson(); |
16 |
| - const { |
17 |
| - appVersion, |
18 |
| - electronVersion, |
19 |
| - chromeVersion, |
20 |
| - nodeVersion, |
21 |
| - v8Version, |
22 |
| - osInfo, |
23 |
| - } = getEnvironmentInfo(); |
| 12 | +export interface AboutDialogArgs { |
| 13 | + environmentInfo: EnvironmentInfo; |
| 14 | + updaterStatus: AppUpdaterStatus; |
| 15 | +} |
24 | 16 |
|
25 |
| - const usefulInfo = `Version: ${appVersion}\nElectron: ${electronVersion}\nChrome: ${chromeVersion}\nNode.js: ${nodeVersion}\nV8: ${v8Version}\nOS: ${osInfo}`; |
26 |
| - const detail = description ? `${description}\n\n${usefulInfo}` : usefulInfo; |
27 |
| - let buttons = ['OK', 'Copy']; |
28 |
| - let cancelId = 0; |
29 |
| - let defaultId = 1; |
30 |
| - if (process.platform === 'linux') { |
31 |
| - buttons = ['Copy', 'OK']; |
32 |
| - cancelId = 1; |
33 |
| - defaultId = 0; |
34 |
| - } |
35 |
| - dialog |
36 |
| - .showMessageBox(BrowserWindow.getAllWindows()[0], { |
37 |
| - type: 'none', |
38 |
| - buttons, |
39 |
| - title, |
40 |
| - message: title, |
41 |
| - detail, |
42 |
| - noLink: true, |
43 |
| - icon: iconPath, |
44 |
| - cancelId, |
45 |
| - defaultId, |
46 |
| - }) |
47 |
| - .then(({ response }) => { |
48 |
| - if (response === defaultId) { |
49 |
| - clipboard.writeText(usefulInfo, 'clipboard'); |
50 |
| - } |
51 |
| - return null; |
52 |
| - }) |
53 |
| - .catch((err) => { |
54 |
| - console.error('Error opening about', err); |
55 |
| - }); |
56 |
| -}; |
| 17 | +export const subMenuHelp = ( |
| 18 | + mainWindow: BrowserWindow, |
| 19 | + appUpdater: AppUpdater |
| 20 | +): MenuItemConstructorOptions => { |
| 21 | + const environmentInfo = getEnvironmentInfo(); |
| 22 | + ipcMain.handle('get-about-info', async (_): Promise<AboutDialogArgs> => { |
| 23 | + return { |
| 24 | + environmentInfo, |
| 25 | + updaterStatus: appUpdater.getStatus(), |
| 26 | + }; |
| 27 | + }); |
57 | 28 |
|
58 |
| -export const subMenuHelp: MenuItemConstructorOptions = { |
59 |
| - label: 'Help', |
60 |
| - submenu: [ |
61 |
| - { |
62 |
| - label: 'Learn More', |
63 |
| - click() { |
64 |
| - shell.openExternal('https://responsively.app'); |
| 29 | + return { |
| 30 | + label: 'Help', |
| 31 | + submenu: [ |
| 32 | + { |
| 33 | + label: 'Learn More', |
| 34 | + click() { |
| 35 | + shell.openExternal('https://responsively.app'); |
| 36 | + }, |
| 37 | + }, |
| 38 | + { |
| 39 | + label: 'Open Source', |
| 40 | + click() { |
| 41 | + shell.openExternal( |
| 42 | + 'https://github.com/responsively-org/responsively-app' |
| 43 | + ); |
| 44 | + }, |
| 45 | + }, |
| 46 | + { |
| 47 | + label: 'Join Discord', |
| 48 | + click() { |
| 49 | + shell.openExternal('https://responsively.app/join-discord/'); |
| 50 | + }, |
65 | 51 | },
|
66 |
| - }, |
67 |
| - { |
68 |
| - label: 'Open Source', |
69 |
| - click() { |
70 |
| - shell.openExternal( |
71 |
| - 'https://github.com/responsively-org/responsively-app' |
72 |
| - ); |
| 52 | + { |
| 53 | + label: 'Search Issues', |
| 54 | + click() { |
| 55 | + shell.openExternal( |
| 56 | + 'https://github.com/responsively-org/responsively-app/issues' |
| 57 | + ); |
| 58 | + }, |
73 | 59 | },
|
74 |
| - }, |
75 |
| - { |
76 |
| - label: 'Join Discord', |
77 |
| - click() { |
78 |
| - shell.openExternal('https://responsively.app/join-discord/'); |
| 60 | + { |
| 61 | + label: 'Sponsor Responsively', |
| 62 | + click() { |
| 63 | + shell.openExternal( |
| 64 | + 'https://responsively.app/sponsor?utm_source=app&utm_medium=menu&utm_campaign=sponsor' |
| 65 | + ); |
| 66 | + }, |
79 | 67 | },
|
80 |
| - }, |
81 |
| - { |
82 |
| - label: 'Search Issues', |
83 |
| - click() { |
84 |
| - shell.openExternal( |
85 |
| - 'https://github.com/responsively-org/responsively-app/issues' |
86 |
| - ); |
| 68 | + { |
| 69 | + type: 'separator', |
87 | 70 | },
|
88 |
| - }, |
89 |
| - { |
90 |
| - label: 'Sponsor Responsively', |
91 |
| - click() { |
92 |
| - shell.openExternal( |
93 |
| - 'https://responsively.app/sponsor?utm_source=app&utm_medium=menu&utm_campaign=sponsor' |
94 |
| - ); |
| 71 | + { |
| 72 | + label: 'About', |
| 73 | + accelerator: 'F1', |
| 74 | + click: () => { |
| 75 | + mainWindow.webContents.send(IPC_MAIN_CHANNELS.OPEN_ABOUT_DIALOG, { |
| 76 | + environmentInfo, |
| 77 | + updaterStatus: appUpdater.getStatus(), |
| 78 | + }); |
| 79 | + }, |
95 | 80 | },
|
96 |
| - }, |
97 |
| - { |
98 |
| - type: 'separator', |
99 |
| - }, |
100 |
| - { |
101 |
| - label: 'About', |
102 |
| - accelerator: 'F1', |
103 |
| - click: aboutOnClick, |
104 |
| - }, |
105 |
| - ], |
| 81 | + ], |
| 82 | + }; |
106 | 83 | };
|
0 commit comments