Skip to content

Commit

Permalink
feat: Update Electron to v6
Browse files Browse the repository at this point in the history
  • Loading branch information
ashchan committed Aug 17, 2019
1 parent 9bfa9b3 commit 0977897
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/neuron-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@types/uuid": "3.4.4",
"@types/webdriverio": "4.13.0",
"devtron": "1.4.0",
"electron": "5.0.7",
"electron": "6.0.0",
"electron-builder": "21.2.0",
"electron-devtools-installer": "2.2.4",
"electron-notarize": "0.1.1",
Expand Down
23 changes: 15 additions & 8 deletions packages/neuron-wallet/src/controllers/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import path from 'path'
import { dialog, shell, Menu, MenuItem, MessageBoxOptions, SaveDialogOptions, BrowserWindow } from 'electron'
import {
dialog,
shell,
Menu,
MenuItem,
MessageBoxOptions,
MessageBoxReturnValue,
SaveDialogOptions,
SaveDialogReturnValue,
BrowserWindow,
} from 'electron'
import { take } from 'rxjs/operators'
import app from 'app'

Expand Down Expand Up @@ -99,15 +109,12 @@ export default class AppController {
return WindowManager.mainWindow && winID === WindowManager.mainWindow.id
}

public static showMessageBox(
options: MessageBoxOptions,
callback?: (response: number, checkboxChecked: boolean) => void
) {
dialog.showMessageBox(options, callback)
public static showMessageBox(options: MessageBoxOptions, callback?: (returnValue: MessageBoxReturnValue) => void) {
dialog.showMessageBox(options).then(callback)
}

public static showSaveDialog(options: SaveDialogOptions, callback?: (filename?: string, bookmark?: string) => void) {
dialog.showSaveDialog(options, callback)
public static showSaveDialog(options: SaveDialogOptions, callback?: (returnValue: SaveDialogReturnValue) => void) {
dialog.showSaveDialog(options).then(callback)
}

public static toggleAddressBook() {
Expand Down
6 changes: 3 additions & 3 deletions packages/neuron-wallet/src/controllers/app/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuItemConstructorOptions, clipboard, dialog } from 'electron'
import { MenuItemConstructorOptions, clipboard, dialog, MessageBoxReturnValue } from 'electron'
import { bech32Address } from '@nervosnetwork/ckb-sdk-utils'

import WalletsService from 'services/wallets'
Expand Down Expand Up @@ -80,8 +80,8 @@ export const contextMenuTemplate: {
detail: isCurrent ? i18n.t('messageBox.remove-network.alert') : '',
buttons: [i18n.t('messageBox.button.confirm'), i18n.t('messageBox.button.discard')],
},
(btnIdx: number) => {
if (btnIdx === 0) {
(returnValue: MessageBoxReturnValue) => {
if (returnValue.response === 0) {
try {
networksService.delete(id)
} catch (err) {
Expand Down
24 changes: 11 additions & 13 deletions packages/neuron-wallet/src/controllers/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@ export default class UpdateController {

autoUpdater.on('update-available', (info: UpdateInfo) => {
const { version } = info
dialog.showMessageBox(
{
dialog
.showMessageBox({
type: 'info',
title: version,
message: i18n.t('updater.updates-found-do-you-want-to-update', { version }),
buttons: [i18n.t('updater.update-now'), i18n.t('common.no')],
},
buttonIndex => {
if (buttonIndex === 0) {
})
.then(returnValue => {
if (returnValue.response === 0) {
autoUpdater.downloadUpdate()
} else {
this.enableSender()
}
}
)
})
})

autoUpdater.on('update-not-available', () => {
Expand All @@ -56,16 +55,15 @@ export default class UpdateController {
})

autoUpdater.on('update-downloaded', () => {
dialog.showMessageBox(
{
dialog
.showMessageBox({
type: 'info',
message: i18n.t('updater.updates-downloaded-about-to-quit-and-install'),
buttons: [i18n.t('common.ok')],
},
() => {
})
.then(() => {
setImmediate(() => autoUpdater.quitAndInstall())
}
)
})
})
}

Expand Down
7 changes: 4 additions & 3 deletions packages/neuron-wallet/src/controllers/wallets/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs'
import { SaveDialogReturnValue } from 'electron'
import AppController from 'controllers/app'
import WalletsService, { Wallet, WalletProperties, FileKeystoreWallet } from 'services/wallets'
import Keystore from 'models/keys/keystore'
Expand Down Expand Up @@ -270,9 +271,9 @@ export default class WalletsController {
title: i18n.t('messages.save-keystore'),
defaultPath: wallet.name,
},
(filename?: string) => {
if (filename) {
fs.writeFileSync(filename, JSON.stringify(keystore))
(returnValue: SaveDialogReturnValue) => {
if (returnValue.filePath) {
fs.writeFileSync(returnValue.filePath, JSON.stringify(keystore))
resolve({
status: ResponseCode.Success,
result: true,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7258,10 +7258,10 @@ electron-window-state@5.0.3:
jsonfile "^4.0.0"
mkdirp "^0.5.1"

electron@5.0.7:
version "5.0.7"
resolved "https://registry.yarnpkg.com/electron/-/electron-5.0.7.tgz#a48fcbd13d30f16f7d7887908b68e52156e90259"
integrity sha512-OMMz8DhatxLuBFbnW7KYcAUjflGYFn0IQEtKR0iZhMAm89FgNOd9SVbxXWAGNxvRR6C0gORXwhTh6BCqqqcR6Q==
electron@6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/electron/-/electron-6.0.0.tgz#03712d461ac73cdf920b2336d6560d6c6b7f19cc"
integrity sha512-JVHj0dYtvVFrzVk1TgvrdXJSyLpdvlWNLhtG8ItYZsyg9XbCOQ9OoPfgLm04FjMzKMzEl4YIN0PfGC02MTx3PQ==
dependencies:
"@types/node" "^10.12.18"
electron-download "^4.1.0"
Expand Down

0 comments on commit 0977897

Please sign in to comment.