mirror of
https://github.com/Kvan7/Exiled-Exchange-2.git
synced 2026-09-25 22:25:58 +00:00
rework updater
This commit is contained in:
+6
-6
@@ -1,6 +1,6 @@
|
||||
import path from 'path'
|
||||
import { app, Tray, Menu, ipcMain, MenuItem, MenuItemConstructorOptions, shell, nativeImage } from 'electron'
|
||||
import { checkForUpdates } from './updates'
|
||||
import { checkForUpdates, UpdateState } from './updates'
|
||||
import { config } from './config'
|
||||
import { win } from './window'
|
||||
import { League } from '@/ipc/types'
|
||||
@@ -55,7 +55,7 @@ export function createTray () {
|
||||
rebuildContextMenu()
|
||||
}
|
||||
|
||||
function rebuildContextMenu () {
|
||||
export function rebuildContextMenu () {
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
...leaguesMenuItem(),
|
||||
{
|
||||
@@ -70,10 +70,10 @@ function rebuildContextMenu () {
|
||||
enabled: false
|
||||
},
|
||||
{
|
||||
label: 'Check for updates',
|
||||
click: () => {
|
||||
checkForUpdates(true)
|
||||
}
|
||||
label: UpdateState.canCheck ? 'Check for updates' : UpdateState.status,
|
||||
sublabel: UpdateState.canCheck ? UpdateState.status : undefined,
|
||||
enabled: UpdateState.canCheck,
|
||||
click: checkForUpdates
|
||||
},
|
||||
{
|
||||
label: 'Open data folder',
|
||||
|
||||
+41
-22
@@ -1,34 +1,53 @@
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
import { Notification } from 'electron'
|
||||
import { logger } from './logger'
|
||||
import { rebuildContextMenu } from './tray'
|
||||
|
||||
let _manual = false
|
||||
export const UpdateState = {
|
||||
canCheck: true,
|
||||
status: ''
|
||||
}
|
||||
|
||||
autoUpdater.on('update-available', () => {
|
||||
new Notification({
|
||||
title: 'Awakened PoE Trade',
|
||||
body: 'New update found and is downloading in the background now'
|
||||
}).show()
|
||||
|
||||
logger.info('Update is downloading', { source: 'updater' })
|
||||
autoUpdater.on('update-available', (info: { version: string }) => {
|
||||
UpdateState.canCheck = false
|
||||
if (autoUpdater.autoDownload) {
|
||||
UpdateState.status = `Downloading v${info.version} ...`
|
||||
} else {
|
||||
UpdateState.status = `Update v${info.version} available on Github`
|
||||
}
|
||||
rebuildContextMenu()
|
||||
})
|
||||
|
||||
autoUpdater.on('update-not-available', () => {
|
||||
if (_manual) {
|
||||
new Notification({
|
||||
title: 'Awakened PoE Trade',
|
||||
body: 'You already have the latest version'
|
||||
}).show()
|
||||
}
|
||||
|
||||
logger.info('No updates available', { source: 'updater' })
|
||||
UpdateState.canCheck = true
|
||||
UpdateState.status = 'No updates available'
|
||||
rebuildContextMenu()
|
||||
})
|
||||
|
||||
export async function checkForUpdates (manual: boolean = false) {
|
||||
if (process.platform === 'darwin') return
|
||||
autoUpdater.on('error', () => {
|
||||
UpdateState.canCheck = true
|
||||
UpdateState.status = 'Something went wrong, check logs'
|
||||
rebuildContextMenu()
|
||||
})
|
||||
|
||||
_manual = manual
|
||||
autoUpdater.checkForUpdatesAndNotify()
|
||||
autoUpdater.on('update-downloaded', (info: { version: string }) => {
|
||||
UpdateState.canCheck = false
|
||||
UpdateState.status = `v${info.version} will be installed on exit`
|
||||
rebuildContextMenu()
|
||||
})
|
||||
|
||||
logger.info('Checking for updates', { source: 'updater', manual })
|
||||
// on('download-progress') https://github.com/electron-userland/electron-builder/issues/2521
|
||||
|
||||
export async function checkForUpdates () {
|
||||
autoUpdater.logger = logger
|
||||
autoUpdater.autoDownload = !process.env.PORTABLE_EXECUTABLE_DIR // https://www.electron.build/configuration/nsis.html#portable
|
||||
|
||||
UpdateState.canCheck = false
|
||||
UpdateState.status = 'Checking for update...'
|
||||
rebuildContextMenu()
|
||||
|
||||
try {
|
||||
await autoUpdater.checkForUpdates()
|
||||
} catch {
|
||||
// handled by event
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user