Skip to content

Commit cd9bedf

Browse files
committed
fix(updater): switch update menu items
- fixed update menu items. - delete ".map" files before packing. re #56
1 parent 01cc5b5 commit cd9bedf

File tree

5 files changed

+162
-115
lines changed

5 files changed

+162
-115
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ yarn-error.log*
2828
# breader
2929
public/electron.js
3030
public/electron.js.map
31+
32+
# electron
33+
dev-app-update.yml

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
env:
22
- SENTRY_RELEASE=$TRAVIS_TAG
3+
- YARN_GPG=no
34

45
matrix:
56
include:
@@ -44,11 +45,13 @@ after_success:
4445
- if [ $TRAVIS_OS_NAME = linux ]; then cat ./coverage/lcov.info | yarn coveralls; fi
4546

4647
before_deploy:
47-
- yarn electron-pack --publish never
48+
- ls ./build
49+
- ls ./build/static/js
4850
- yarn sentry-cli releases new $SENTRY_RELEASE
4951
- yarn sentry-cli releases files $SENTRY_RELEASE upload-sourcemaps --rewrite ./build
5052
- yarn sentry-cli releases finalize $SENTRY_RELEASE
51-
- ls ./
53+
- find ./build -name "*.map" -exec rm -f {} \;
54+
- yarn electron-pack --publish never
5255
- ls ./dist
5356

5457
deploy:

main/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// Modules to control application life and create native browser window
22
import * as Sentry from '@sentry/electron'
3-
import { app, BrowserWindow, Menu } from 'electron'
3+
import { app, BrowserWindow } from 'electron'
44
import isDev from 'electron-is-dev'
55
import path from 'path'
6-
import { template as menuTemplate } from './menu'
6+
import { initMenu } from './menu'
7+
import { initUpdaterMenuItems } from './updater'
78

89
// Keep a global reference of the window object, if you don't, the window will
910
// be closed automatically when the JavaScript object is garbage collected.
1011
let mainWindow: BrowserWindow | null = null
1112
const isWindows = process.platform === 'win32'
1213

14+
initMenu()
15+
initUpdaterMenuItems()
16+
1317
function createWindow() {
1418
// Create the browser window.
1519
mainWindow = new BrowserWindow({
@@ -48,7 +52,7 @@ function createWindow() {
4852
.catch((err: any) => console.error('An error occurred: ', err))
4953
// require('devtron').install()
5054

51-
mainWindow.loadURL('http://localhost:3000/?react_perf')
55+
mainWindow.loadURL('http://localhost:3000')
5256
} else {
5357
mainWindow.loadFile(path.join(__dirname, '/../build/index.html'))
5458
}
@@ -74,10 +78,6 @@ function createWindow() {
7478
// initialization and is ready to create browser windows.
7579
// Some APIs can only be used after this event occurs.
7680
app.on('ready', createWindow)
77-
app.on('ready', () => {
78-
const menu = Menu.buildFromTemplate(menuTemplate)
79-
Menu.setApplicationMenu(menu)
80-
})
8181

8282
// Quit when all windows are closed.
8383
app.on('window-all-closed', () => {

main/menu.ts

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import {
22
app,
33
BrowserWindow,
44
Event,
5+
Menu,
56
MenuItem,
67
MenuItemConstructorOptions,
78
shell,
89
} from 'electron'
9-
import { checkForUpdates } from './updater'
10+
import { checkForUpdates, restartToUpdate, UPDATER_STATUS_MAP } from './updater'
1011

11-
export const template: MenuItemConstructorOptions[] = [
12+
const template: MenuItemConstructorOptions[] = [
1213
{
1314
label: 'Edit',
1415
submenu: [
@@ -66,6 +67,17 @@ export const template: MenuItemConstructorOptions[] = [
6667
},
6768
]
6869

70+
function addAboutMenuItem(
71+
items: MenuItemConstructorOptions[],
72+
position: number
73+
) {
74+
const aboutItem: MenuItemConstructorOptions = {
75+
label: `About ${app.getName()}`,
76+
role: 'about',
77+
}
78+
items.splice.apply(items, [position, 0, aboutItem])
79+
}
80+
6981
function addUpdateMenuItems(
7082
items: MenuItemConstructorOptions[],
7183
position: number
@@ -78,7 +90,34 @@ function addUpdateMenuItems(
7890
{
7991
click: checkForUpdates,
8092
enabled: true,
93+
id: UPDATER_STATUS_MAP.NORMAL,
8194
label: 'Check for Updates',
95+
visible: true,
96+
},
97+
{
98+
enabled: false,
99+
id: UPDATER_STATUS_MAP.CHECKING,
100+
label: 'Checking updates...',
101+
visible: false,
102+
},
103+
{
104+
enabled: false,
105+
id: UPDATER_STATUS_MAP.DOWNLOADING,
106+
label: 'Downloading updates...',
107+
visible: false,
108+
},
109+
{
110+
enabled: false,
111+
id: UPDATER_STATUS_MAP.ERROR,
112+
label: 'Update Failed',
113+
visible: false,
114+
},
115+
{
116+
click: restartToUpdate,
117+
enabled: true,
118+
id: UPDATER_STATUS_MAP.READY,
119+
label: 'Restart to update',
120+
visible: false,
82121
},
83122
]
84123

@@ -110,14 +149,10 @@ function addPreferencesMenu(
110149
}
111150

112151
if (process.platform === 'darwin') {
113-
const name = app.getName()
152+
const appName = app.getName()
114153
template.unshift({
115-
label: name,
154+
label: appName,
116155
submenu: [
117-
{
118-
label: `About ${name}`,
119-
role: 'about',
120-
},
121156
{
122157
type: 'separator',
123158
},
@@ -131,7 +166,7 @@ if (process.platform === 'darwin') {
131166
},
132167
{
133168
accelerator: 'Command+H',
134-
label: `Hide ${name}`,
169+
label: `Hide ${appName}`,
135170
role: 'hide',
136171
},
137172
{
@@ -155,15 +190,21 @@ if (process.platform === 'darwin') {
155190
},
156191
],
157192
})
158-
193+
addAboutMenuItem(template[0].submenu as MenuItemConstructorOptions[], 0)
159194
addPreferencesMenu(template[0].submenu as MenuItemConstructorOptions[], 1)
160195
addUpdateMenuItems(template[0].submenu as MenuItemConstructorOptions[], 1)
161-
// addPreferencesMenu(template, template.length - 1)
162196
}
163197

164198
if (process.platform === 'win32' || process.platform === 'linux') {
165199
const helpMenu = template[template.length - 1].submenu
166200

167-
addUpdateMenuItems(helpMenu as MenuItemConstructorOptions[], 0)
168201
addPreferencesMenu(template, template.length - 1)
202+
addUpdateMenuItems(helpMenu as MenuItemConstructorOptions[], 0)
203+
// showAboutPanel not working in windows
204+
// addAboutMenuItem(helpMenu as MenuItemConstructorOptions[], 0)
205+
}
206+
207+
export function initMenu() {
208+
const menu = Menu.buildFromTemplate(template)
209+
Menu.setApplicationMenu(menu)
169210
}

0 commit comments

Comments
 (0)