diff --git a/package.json b/package.json index 72bda9e..bcbd372 100644 --- a/package.json +++ b/package.json @@ -41,11 +41,13 @@ }, "dependencies": { "auto-launch": "^5.0.5", + "axios": "^0.21.1", "dayjs": "^1.10.4", "electron-log": "^4.3.2", "electron-store": "^7.0.2", "react": "^17.0.2", "react-dom": "^17.0.2", + "semver": "^7.3.5", "spectre.css": "^0.5.9", "tachyons": "^4.12.0" }, diff --git a/src/back/index.ts b/src/back/index.ts index 75104c1..5902b49 100644 --- a/src/back/index.ts +++ b/src/back/index.ts @@ -4,6 +4,7 @@ import logger from 'electron-log' import TrayUtility from './tray' import Settings from './settings' import Banner from './banner' +import Updater from './updater' export const DEV = !app.isPackaged @@ -21,6 +22,7 @@ app TrayUtility.init() Settings.init() Banner.init() + Updater.init() logger.log('Done') }) .catch((e) => { diff --git a/src/back/settings.ts b/src/back/settings.ts index 7c5ad3f..79dee76 100644 --- a/src/back/settings.ts +++ b/src/back/settings.ts @@ -75,7 +75,7 @@ export default class Settings { const entry = join(__dirname, '../front/settings/index.html') Settings.win.loadFile(entry) - if (DEV && false) { + if (DEV) { Settings.win.setSize(800, 485) Settings.win.setResizable(true) Settings.win.webContents.openDevTools() diff --git a/src/back/updater.ts b/src/back/updater.ts new file mode 100644 index 0000000..e5d93cf --- /dev/null +++ b/src/back/updater.ts @@ -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) + } + } +} diff --git a/src/front/settings/Settings.tsx b/src/front/settings/Settings.tsx index 83ac3af..042adb4 100644 --- a/src/front/settings/Settings.tsx +++ b/src/front/settings/Settings.tsx @@ -1,5 +1,4 @@ import React from 'react' -import { render } from 'react-dom' import '../base.css' diff --git a/yarn.lock b/yarn.lock index 9b67347..94c1374 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1996,6 +1996,13 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59" 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: version "2.3.3" 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: locate-path "^3.0.0" -follow-redirects@^1.0.0: +follow-redirects@^1.0.0, follow-redirects@^1.10.0: version "1.13.3" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.3.tgz#e5598ad50174c1bc4e872301e82ac2cd97f90267" 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" 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" resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7" integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==