Update notifications
Removed the shit tone of check for updates, made it manual Redone the function in utils Logging for autoupdater implemented
This commit is contained in:
parent
a5e22d5f0d
commit
89e0d7c104
6 changed files with 79 additions and 24 deletions
|
@ -973,27 +973,9 @@ export class BrowserWindow {
|
|||
});
|
||||
|
||||
ipcMain.on('check-for-update', async (_event) => {
|
||||
const branch = utils.getStoreValue('general.update_branch')
|
||||
let latestbranch = await fetch(`https://circleci.com/api/v1.1/project/gh/ciderapp/Cider/latest/artifacts?branch=${branch}&filter=successful`)
|
||||
if (latestbranch.status != 200) {
|
||||
console.log(`Error fetching latest artifact from the **${branch}** branch`)
|
||||
return
|
||||
}
|
||||
|
||||
let latestbranchjson = await latestbranch.json()
|
||||
let base_url = latestbranchjson[0].url
|
||||
base_url = base_url.substring(0, base_url.lastIndexOf('/'))
|
||||
|
||||
const options: any = {
|
||||
provider: 'generic',
|
||||
url: `${base_url}`,
|
||||
allowDowngrade: true,
|
||||
}
|
||||
|
||||
// Have to handle the auto updaters seperatly until we can support macOS. electron-builder limitation -q
|
||||
if (process.platform === 'win32') await new NsisUpdater(options).checkForUpdatesAndNotify() //Windows
|
||||
if (process.platform === 'linux') await new AppImageUpdater(options).checkForUpdatesAndNotify() //Linux
|
||||
await utils.checkForUpdate();
|
||||
});
|
||||
|
||||
ipcMain.on('disable-update', (event) => {
|
||||
// Check if using app store builds so people don't get pissy wen button go bonk
|
||||
if (app.isPackaged && !process.mas || !process.windowsStore) {
|
||||
|
|
|
@ -3,6 +3,9 @@ import * as path from "path";
|
|||
import {Store} from "./store";
|
||||
import {BrowserWindow as bw} from "./browserwindow";
|
||||
import {app} from "electron";
|
||||
import fetch from "electron-fetch";
|
||||
import {AppImageUpdater, NsisUpdater} from "electron-updater";
|
||||
import * as log from "electron-log";
|
||||
|
||||
export class utils {
|
||||
|
||||
|
@ -107,4 +110,54 @@ export class utils {
|
|||
bw.win.webContents.executeJavaScript("MusicKitInterop.previous()")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the application for updates
|
||||
*/
|
||||
static async checkForUpdate(): Promise<void> {
|
||||
|
||||
// Get the artifacts
|
||||
const response = await fetch(`https://circleci.com/api/v1.1/project/gh/ciderapp/Cider/latest/artifacts?branch=${utils.getStoreValue('general.update_branch')}&filter=successful`)
|
||||
if (response.status != 200) {
|
||||
bw.win.webContents.send('update-response', 'update-timeout')
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the urls
|
||||
const jsonResponse = await response.json()
|
||||
let base_url = jsonResponse[0].url
|
||||
base_url = base_url.substring(0, base_url.lastIndexOf('/'))
|
||||
|
||||
const options: any = {
|
||||
provider: 'generic',
|
||||
url: base_url,
|
||||
allowDowngrade: true,
|
||||
}
|
||||
|
||||
let autoUpdater: any = null
|
||||
if (process.platform === 'win32') { //Windows
|
||||
autoUpdater = await new NsisUpdater(options)
|
||||
} else {
|
||||
autoUpdater = await new AppImageUpdater(options) //Linux and Mac (AppImages work on macOS btw)
|
||||
}
|
||||
|
||||
autoUpdater.on('error', (error: any) => {
|
||||
console.error(`[AutoUpdater] Error: ${error}`)
|
||||
bw.win.webContents.send('update-response', "update-error")
|
||||
})
|
||||
|
||||
autoUpdater.on('update-not-available', () => {
|
||||
console.log('[AutoUpdater] Update not available.')
|
||||
bw.win.webContents.send('update-response', "update-not-available");
|
||||
})
|
||||
|
||||
autoUpdater.on('update-downloaded', () => {
|
||||
console.log('[AutoUpdater] Update downloaded.')
|
||||
bw.win.webContents.send('update-response', "update-downloaded");
|
||||
})
|
||||
|
||||
log.transports.file.level = "debug"
|
||||
autoUpdater.logger = log
|
||||
await autoUpdater.checkForUpdate()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue