mirror of
https://github.com/cupcakearmy/unpixel.git
synced 2024-12-22 08:06:33 +00:00
auto updater
This commit is contained in:
parent
87a9aa6425
commit
dd74820963
@ -41,11 +41,13 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"auto-launch": "^5.0.5",
|
"auto-launch": "^5.0.5",
|
||||||
|
"axios": "^0.21.1",
|
||||||
"dayjs": "^1.10.4",
|
"dayjs": "^1.10.4",
|
||||||
"electron-log": "^4.3.2",
|
"electron-log": "^4.3.2",
|
||||||
"electron-store": "^7.0.2",
|
"electron-store": "^7.0.2",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
|
"semver": "^7.3.5",
|
||||||
"spectre.css": "^0.5.9",
|
"spectre.css": "^0.5.9",
|
||||||
"tachyons": "^4.12.0"
|
"tachyons": "^4.12.0"
|
||||||
},
|
},
|
||||||
|
@ -4,6 +4,7 @@ import logger from 'electron-log'
|
|||||||
import TrayUtility from './tray'
|
import TrayUtility from './tray'
|
||||||
import Settings from './settings'
|
import Settings from './settings'
|
||||||
import Banner from './banner'
|
import Banner from './banner'
|
||||||
|
import Updater from './updater'
|
||||||
|
|
||||||
export const DEV = !app.isPackaged
|
export const DEV = !app.isPackaged
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ app
|
|||||||
TrayUtility.init()
|
TrayUtility.init()
|
||||||
Settings.init()
|
Settings.init()
|
||||||
Banner.init()
|
Banner.init()
|
||||||
|
Updater.init()
|
||||||
logger.log('Done')
|
logger.log('Done')
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
@ -75,7 +75,7 @@ export default class Settings {
|
|||||||
const entry = join(__dirname, '../front/settings/index.html')
|
const entry = join(__dirname, '../front/settings/index.html')
|
||||||
Settings.win.loadFile(entry)
|
Settings.win.loadFile(entry)
|
||||||
|
|
||||||
if (DEV && false) {
|
if (DEV) {
|
||||||
Settings.win.setSize(800, 485)
|
Settings.win.setSize(800, 485)
|
||||||
Settings.win.setResizable(true)
|
Settings.win.setResizable(true)
|
||||||
Settings.win.webContents.openDevTools()
|
Settings.win.webContents.openDevTools()
|
||||||
|
45
src/back/updater.ts
Normal file
45
src/back/updater.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import semver from 'semver'
|
||||||
|
import axios from 'axios'
|
||||||
|
import logger from 'electron-log'
|
||||||
|
import { dialog, shell } from 'electron'
|
||||||
|
|
||||||
|
import pkg from '../../package.json'
|
||||||
|
|
||||||
|
const current = semver.coerce(pkg.version)
|
||||||
|
const url = 'https://api.github.com/repos/cupcakearmy/unpixel/tags'
|
||||||
|
const interval = 1000 * 60 * 60 * 10 // 10 Minutes
|
||||||
|
|
||||||
|
export default class Updater {
|
||||||
|
static init() {
|
||||||
|
this.check()
|
||||||
|
}
|
||||||
|
|
||||||
|
static async check() {
|
||||||
|
const { data } = await axios({
|
||||||
|
method: 'get',
|
||||||
|
url,
|
||||||
|
})
|
||||||
|
// parse tags and reverse sort them to get the highest
|
||||||
|
const tags = data.map((d) => semver.coerce(d.name)).sort(semver.rcompare)
|
||||||
|
const latest = tags[0]
|
||||||
|
if (semver.lt(current, latest)) {
|
||||||
|
logger.info('New version available')
|
||||||
|
dialog
|
||||||
|
.showMessageBox(null, {
|
||||||
|
title: 'Update available',
|
||||||
|
message: 'A newer version is available, please download.',
|
||||||
|
buttons: ['Download', 'Later'],
|
||||||
|
cancelId: 1,
|
||||||
|
})
|
||||||
|
.then(({ response }) => {
|
||||||
|
if (response === 0) {
|
||||||
|
shell.openExternal('https://github.com/cupcakearmy/unpixel/releases')
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
logger.info('Up to date')
|
||||||
|
setTimeout(() => this.check(), interval)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render } from 'react-dom'
|
|
||||||
|
|
||||||
import '../base.css'
|
import '../base.css'
|
||||||
|
|
||||||
|
11
yarn.lock
11
yarn.lock
@ -1996,6 +1996,13 @@ aws4@^1.8.0:
|
|||||||
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
|
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
|
||||||
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
|
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
|
||||||
|
|
||||||
|
axios@^0.21.1:
|
||||||
|
version "0.21.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
|
||||||
|
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
|
||||||
|
dependencies:
|
||||||
|
follow-redirects "^1.10.0"
|
||||||
|
|
||||||
babel-plugin-dynamic-import-node@^2.3.3:
|
babel-plugin-dynamic-import-node@^2.3.3:
|
||||||
version "2.3.3"
|
version "2.3.3"
|
||||||
resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz#84fda19c976ec5c6defef57f9427b3def66e17a3"
|
resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz#84fda19c976ec5c6defef57f9427b3def66e17a3"
|
||||||
@ -3726,7 +3733,7 @@ find-up@^3.0.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
locate-path "^3.0.0"
|
locate-path "^3.0.0"
|
||||||
|
|
||||||
follow-redirects@^1.0.0:
|
follow-redirects@^1.0.0, follow-redirects@^1.10.0:
|
||||||
version "1.13.3"
|
version "1.13.3"
|
||||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.3.tgz#e5598ad50174c1bc4e872301e82ac2cd97f90267"
|
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.3.tgz#e5598ad50174c1bc4e872301e82ac2cd97f90267"
|
||||||
integrity sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==
|
integrity sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==
|
||||||
@ -6575,7 +6582,7 @@ semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.2.0, semver@^6.3.0:
|
|||||||
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
|
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
|
||||||
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
|
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
|
||||||
|
|
||||||
semver@^7.3.2, semver@^7.3.4:
|
semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
|
||||||
version "7.3.5"
|
version "7.3.5"
|
||||||
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
|
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
|
||||||
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
|
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
|
||||||
|
Loading…
Reference in New Issue
Block a user