|
1 | | -import sleep from 'await-sleep'; |
2 | | -import { type BrowserWindow, autoUpdater, dialog } from 'electron'; |
| 1 | +// import sleep from 'await-sleep'; |
| 2 | +// import { type BrowserWindow, autoUpdater, dialog, FeedURLOptions } from 'electron'; |
| 3 | +import type { BrowserWindow } from 'electron'; |
| 4 | +// // const { updateElectronApp } = require('update-electron-app') |
| 5 | +import { type IUpdateElectronAppOptions, updateElectronApp, UpdateSourceType } from 'update-electron-app'; |
| 6 | +import logger, { autoUpdateLogger } from './logger'; |
| 7 | +import log from 'electron-log/main'; |
| 8 | +const updateLogger = log.scope('updater'); |
3 | 9 |
|
4 | | -import { reportEvent } from './events'; |
5 | | -import i18nMain from './i18nMain'; |
6 | | -// import logger, { autoUpdateLogger } from './logger'; |
7 | | -import logger from './logger'; |
8 | | -import { getSetIsPreReleaseUpdatesEnabled } from './state/settings'; |
| 10 | +// import { reportEvent } from './events'; |
| 11 | +// import i18nMain from './i18nMain'; |
| 12 | +// // import logger, { autoUpdateLogger } from './logger'; |
| 13 | +// import logger from './logger'; |
| 14 | +// import { getSetIsPreReleaseUpdatesEnabled } from './state/settings'; |
9 | 15 |
|
10 | | -let notifyUserIfNoUpdateAvailable: boolean; |
| 16 | +// let notifyUserIfNoUpdateAvailable: boolean; |
11 | 17 |
|
12 | | -const t = i18nMain.getFixedT(null, 'updater'); |
| 18 | +// const t = i18nMain.getFixedT(null, 'updater'); |
13 | 19 |
|
14 | | -const intiUpdateHandlers = (browserWindow: BrowserWindow) => { |
15 | | - autoUpdater.on('error', (error) => { |
16 | | - logger.error('autoUpdater:::::::::error', error); |
17 | | - }); |
| 20 | +// const intiUpdateHandlers = (browserWindow: BrowserWindow) => { |
| 21 | +// autoUpdater.on('error', (error) => { |
| 22 | +// logger.error('autoUpdater:::::::::error', error); |
| 23 | +// }); |
18 | 24 |
|
19 | | - autoUpdater.on('checking-for-update', () => { |
20 | | - logger.info('autoUpdater:::::::::checking-for-update'); |
21 | | - }); |
22 | | - autoUpdater.on('update-available', async (info: any) => { |
23 | | - logger.info('autoUpdater:::::::::update-available: ', info); |
24 | | - // Quick fix to wait for window load before showing update prompt |
25 | | - await sleep(5000); |
26 | | - dialog |
27 | | - .showMessageBox(browserWindow, { |
28 | | - type: 'info', |
29 | | - title: t('UpdateAvailable'), |
30 | | - message: `${t('UpdateNiceNode')} ${info.version}.`, |
31 | | - buttons: [t('Yes'), t('No')], |
32 | | - }) |
33 | | - .then(async (buttonIndex) => { |
34 | | - if (buttonIndex.response === 0) { |
35 | | - console.log('update accepted by user'); |
36 | | - console.log('starting download'); |
37 | | - autoUpdater.quitAndInstall(); |
38 | | - dialog.showMessageBox(browserWindow, { |
39 | | - type: 'info', |
40 | | - title: t('UpdateAvailable'), |
41 | | - message: t('DownloadingUpdate'), |
42 | | - }); |
43 | | - } else { |
44 | | - console.log('update checkbox not checked'); |
45 | | - } |
46 | | - }) |
47 | | - .catch((err) => { |
48 | | - console.error('error in update available dialog: ', err); |
49 | | - }); |
50 | | - }); |
| 25 | +// autoUpdater.on('checking-for-update', () => { |
| 26 | +// logger.info('autoUpdater:::::::::checking-for-update'); |
| 27 | +// }); |
| 28 | +// autoUpdater.on('update-available', async (info: any) => { |
| 29 | +// logger.info('autoUpdater:::::::::update-available: ', info); |
| 30 | +// // Quick fix to wait for window load before showing update prompt |
| 31 | +// await sleep(5000); |
| 32 | +// dialog |
| 33 | +// .showMessageBox(browserWindow, { |
| 34 | +// type: 'info', |
| 35 | +// title: t('UpdateAvailable'), |
| 36 | +// message: `${t('UpdateNiceNode')} ${info.version}.`, |
| 37 | +// buttons: [t('Yes'), t('No')], |
| 38 | +// }) |
| 39 | +// .then(async (buttonIndex) => { |
| 40 | +// if (buttonIndex.response === 0) { |
| 41 | +// console.log('update accepted by user'); |
| 42 | +// console.log('starting download'); |
| 43 | +// autoUpdater.quitAndInstall(); |
| 44 | +// dialog.showMessageBox(browserWindow, { |
| 45 | +// type: 'info', |
| 46 | +// title: t('UpdateAvailable'), |
| 47 | +// message: t('DownloadingUpdate'), |
| 48 | +// }); |
| 49 | +// } else { |
| 50 | +// console.log('update checkbox not checked'); |
| 51 | +// } |
| 52 | +// }) |
| 53 | +// .catch((err) => { |
| 54 | +// console.error('error in update available dialog: ', err); |
| 55 | +// }); |
| 56 | +// }); |
51 | 57 |
|
52 | | - autoUpdater.on('update-not-available', () => { |
53 | | - logger.info('autoUpdater:::::::::update-not-available'); |
54 | | - if (notifyUserIfNoUpdateAvailable) { |
55 | | - dialog.showMessageBox(browserWindow, { |
56 | | - type: 'info', |
57 | | - title: t('NoUpdateAvailable'), |
58 | | - message: t('NoUpdateAvailable'), |
59 | | - }); |
60 | | - notifyUserIfNoUpdateAvailable = false; |
61 | | - } |
62 | | - }); |
| 58 | +// autoUpdater.on('update-not-available', () => { |
| 59 | +// logger.info('autoUpdater:::::::::update-not-available'); |
| 60 | +// if (notifyUserIfNoUpdateAvailable) { |
| 61 | +// dialog.showMessageBox(browserWindow, { |
| 62 | +// type: 'info', |
| 63 | +// title: t('NoUpdateAvailable'), |
| 64 | +// message: t('NoUpdateAvailable'), |
| 65 | +// }); |
| 66 | +// notifyUserIfNoUpdateAvailable = false; |
| 67 | +// } |
| 68 | +// }); |
63 | 69 |
|
64 | | - autoUpdater.on('update-downloaded', () => { |
65 | | - logger.info('autoUpdater:::::::::update-downloaded'); |
66 | | - logger.info('Calling autoUpdater.quitAndInstall()'); |
67 | | - reportEvent('UpdatedNiceNode'); |
68 | | - try { |
69 | | - autoUpdater.quitAndInstall(); |
70 | | - } catch (err) { |
71 | | - logger.error('Error in: autoUpdater.quitAndInstall()'); |
72 | | - logger.error(err); |
73 | | - dialog.showErrorBox( |
74 | | - t('ErrorUpdating'), |
75 | | - t('UnableToInstallUpdate', { |
76 | | - downloadLink: 'https://www.nicenode.xyz/#download', |
77 | | - }), |
78 | | - ); |
79 | | - // todo: send error details |
80 | | - reportEvent('ErrorUpdatingNiceNode'); |
81 | | - } |
82 | | - }); |
83 | | -}; |
| 70 | +// autoUpdater.on('update-downloaded', () => { |
| 71 | +// logger.info('autoUpdater:::::::::update-downloaded'); |
| 72 | +// logger.info('Calling autoUpdater.quitAndInstall()'); |
| 73 | +// reportEvent('UpdatedNiceNode'); |
| 74 | +// try { |
| 75 | +// autoUpdater.quitAndInstall(); |
| 76 | +// } catch (err) { |
| 77 | +// logger.error('Error in: autoUpdater.quitAndInstall()'); |
| 78 | +// logger.error(err); |
| 79 | +// dialog.showErrorBox( |
| 80 | +// t('ErrorUpdating'), |
| 81 | +// t('UnableToInstallUpdate', { |
| 82 | +// downloadLink: 'https://www.nicenode.xyz/#download', |
| 83 | +// }), |
| 84 | +// ); |
| 85 | +// // todo: send error details |
| 86 | +// reportEvent('ErrorUpdatingNiceNode'); |
| 87 | +// } |
| 88 | +// }); |
| 89 | +// }; |
84 | 90 |
|
85 | | -export const initialize = (mainWindow: BrowserWindow) => { |
86 | | - // autoUpdater.logger = autoUpdateLogger; |
87 | | - // autoUpdater.autoDownload = false; |
88 | | - // autoUpdater.autoInstallOnAppQuit = false; |
89 | | - const isPreReleaseUpdatesEnabled = getSetIsPreReleaseUpdatesEnabled(); |
90 | | - logger.info(`isPreReleaseUpdatesEnabled: ${isPreReleaseUpdatesEnabled}`); |
91 | | - // autoUpdater.allowPrerelease = isPreReleaseUpdatesEnabled; |
92 | | - notifyUserIfNoUpdateAvailable = false; |
93 | | - intiUpdateHandlers(mainWindow); |
94 | | -}; |
| 91 | +// export const initialize = (mainWindow: BrowserWindow) => { |
| 92 | +// // autoUpdater.logger = autoUpdateLogger; |
| 93 | +// // autoUpdater.autoDownload = false; |
| 94 | +// // autoUpdater.autoInstallOnAppQuit = false; |
| 95 | +// const isPreReleaseUpdatesEnabled = getSetIsPreReleaseUpdatesEnabled(); |
| 96 | +// logger.info(`isPreReleaseUpdatesEnabled: ${isPreReleaseUpdatesEnabled}`); |
| 97 | +// // const server = 'https://github.com/NiceNode/nice-node/releases/latest' |
| 98 | +// // const url = `${server}/update/${process.platform}/${app.getVersion()}` |
| 99 | +// // autoUpdater.setFeedURL({ url }); |
| 100 | +// // autoUpdater.allowPrerelease = isPreReleaseUpdatesEnabled; |
| 101 | +// notifyUserIfNoUpdateAvailable = false; |
| 102 | +// intiUpdateHandlers(mainWindow); |
| 103 | +// }; |
95 | 104 |
|
96 | 105 | export const checkForUpdates = (notifyIfNoUpdateAvailable: boolean) => { |
97 | | - notifyUserIfNoUpdateAvailable = notifyIfNoUpdateAvailable; |
98 | | - autoUpdater.checkForUpdates(); |
| 106 | + logger.info(`updater.checkForUpdates set to: ${notifyIfNoUpdateAvailable}`); |
| 107 | + // notifyUserIfNoUpdateAvailable = notifyIfNoUpdateAvailable; |
| 108 | + // autoUpdater.checkForUpdates(); |
99 | 109 | }; |
100 | 110 |
|
101 | 111 | export const setAllowPrerelease = (isAllowPrerelease: boolean) => { |
102 | 112 | logger.info(`updater.allowPrerelease set to: ${isAllowPrerelease}`); |
103 | 113 | // pre-release: not available https://www.electronjs.org/docs/latest/api/auto-updater#event-update-available |
104 | 114 | // autoUpdater.allowPrerelease = isAllowPrerelease; |
105 | 115 | }; |
| 116 | + |
| 117 | +export const initialize = (mainWindow: BrowserWindow) => { |
| 118 | + updateLogger.info('initialize updater'); |
| 119 | + |
| 120 | + const options: IUpdateElectronAppOptions = { |
| 121 | + updateSource: { |
| 122 | + type: UpdateSourceType.ElectronPublicUpdateService, |
| 123 | + repo: 'NiceNode/nice-node', |
| 124 | + host: 'https://update.electronjs.org', |
| 125 | + }, |
| 126 | + updateInterval: '5 minutes', // testing |
| 127 | + logger: updateLogger |
| 128 | + } |
| 129 | + |
| 130 | + updateLogger.info('updater options: ', options); |
| 131 | + updateElectronApp(options); |
| 132 | +} |
0 commit comments