mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-08-27 11:10:50 +08:00
Added: updateChecker
This commit is contained in:
@@ -4,6 +4,7 @@ import uploader from './utils/uploader.js'
|
|||||||
import { app, BrowserWindow, Tray, Menu, Notification, clipboard, ipcMain } from 'electron'
|
import { app, BrowserWindow, Tray, Menu, Notification, clipboard, ipcMain } from 'electron'
|
||||||
import db from '../datastore'
|
import db from '../datastore'
|
||||||
import pasteTemplate from './utils/pasteTemplate'
|
import pasteTemplate from './utils/pasteTemplate'
|
||||||
|
import updateChecker from './utils/updateChecker'
|
||||||
/**
|
/**
|
||||||
* Set `__static` path to static files in production
|
* Set `__static` path to static files in production
|
||||||
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
|
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
|
||||||
@@ -296,6 +297,7 @@ app.on('ready', () => {
|
|||||||
createWindow()
|
createWindow()
|
||||||
createTray()
|
createTray()
|
||||||
createMenu()
|
createMenu()
|
||||||
|
updateChecker()
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
|
|||||||
58
src/main/utils/updateChecker.js
Normal file
58
src/main/utils/updateChecker.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import { dialog, shell } from 'electron'
|
||||||
|
import db from '../../datastore'
|
||||||
|
import axios from 'axios'
|
||||||
|
import pkg from '../../../package.json'
|
||||||
|
const version = pkg.version
|
||||||
|
const release = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest'
|
||||||
|
const downloadUrl = 'https://github.com/Molunerfinn/PicGo/releases/latest'
|
||||||
|
|
||||||
|
const checkVersion = async () => {
|
||||||
|
let showTip = db.read().get('picBed.showUpdateTip').value()
|
||||||
|
if (showTip === undefined) {
|
||||||
|
db.read().set('picBed.showUpdateTip', true).write()
|
||||||
|
showTip = true
|
||||||
|
}
|
||||||
|
if (showTip) {
|
||||||
|
const res = await axios.get(release)
|
||||||
|
if (res.status === 200) {
|
||||||
|
const latest = res.data.name
|
||||||
|
const result = compareVersion2Update(version, latest)
|
||||||
|
if (result) {
|
||||||
|
dialog.showMessageBox({
|
||||||
|
type: 'info',
|
||||||
|
title: '发现新版本',
|
||||||
|
buttons: ['Yes', 'No'],
|
||||||
|
message: '发现新版本,是否去下载最新的版本?',
|
||||||
|
checkboxLabel: '以后不再提醒',
|
||||||
|
checkboxChecked: false
|
||||||
|
}, (res, checkboxChecked) => {
|
||||||
|
if (res === 0) { // if selected yes
|
||||||
|
shell.openExternal(downloadUrl)
|
||||||
|
}
|
||||||
|
db.read().set('picBed.showUpdateTip', !checkboxChecked).write()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if true -> update else return false
|
||||||
|
const compareVersion2Update = (current, latest) => {
|
||||||
|
const currentVersion = current.split('.').map(item => parseInt(item))
|
||||||
|
const latestVersion = latest.split('.').map(item => parseInt(item))
|
||||||
|
let flag = false
|
||||||
|
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
if (currentVersion[i] < latestVersion[i]) {
|
||||||
|
flag = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return flag
|
||||||
|
}
|
||||||
|
|
||||||
|
export default checkVersion
|
||||||
Reference in New Issue
Block a user