Commit 57e1550b authored by 神楽坂玲奈's avatar 神楽坂玲奈

auto update

parent 61a1858b
...@@ -42,7 +42,7 @@ script: ...@@ -42,7 +42,7 @@ script:
deploy: deploy:
provider: script provider: script
script: bash -c 'ssh-keyscan wudizhanche.mycard.moe >> ~/.ssh/known_hosts; if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then scp dist/mac/MyCard-$TRAVIS_TAG.dmg dist/mac/MyCard-$TRAVIS_TAG-mac.zip root@wudizhanche.mycard.moe:/data/uploads; else scp dist/mycard-$TRAVIS_TAG-x86_64.AppImage root@wudizhanche.mycard.moe:/data/uploads; fi' script: bash -c 'ssh-keyscan wudizhanche.mycard.moe >> ~/.ssh/known_hosts; if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then env; scp -v dist/mac/MyCard-$TRAVIS_TAG.dmg dist/mac/MyCard-$TRAVIS_TAG-mac.zip root@wudizhanche.mycard.moe:/data/uploads; else scp dist/mycard-$TRAVIS_TAG-x86_64.AppImage root@wudizhanche.mycard.moe:/data/uploads; fi'
skip_cleanup: true skip_cleanup: true
on: on:
tags: true tags: true
\ No newline at end of file
'use strict'; 'use strict';
const electron = require('electron'); const {ipcMain, app, BrowserWindow} = require('electron');
const autoUpdater = require("electron-auto-updater").autoUpdater; const {autoUpdater} = require("electron-auto-updater");
if (process.platform == 'darwin') { if (process.platform == 'darwin') {
autoUpdater.setFeedURL("https://wudizhanche.mycard.moe/update"); try {
autoUpdater.setFeedURL("https://wudizhanche.mycard.moe/update");
} catch (err) {
}
} }
autoUpdater.on('error', (event)=>console.log('error', event)); autoUpdater.on('error', (event)=>console.log('error', event));
autoUpdater.on('checking-for-update', (event)=>console.log('checking-for-update', event)); autoUpdater.on('checking-for-update', (event)=>console.log('checking-for-update', event));
autoUpdater.on('update-available', (event)=>console.log('update-available', event)); autoUpdater.on('update-available', (event)=>console.log('update-available', event));
autoUpdater.on('update-not-available', (event)=>console.log('update-not-available', event)); autoUpdater.on('update-not-available', (event)=>console.log('update-not-available', event));
autoUpdater.checkForUpdates();
console.log(1);
let updateWindow; let updateWindow;
autoUpdater.on('update-downloaded', (event)=> { autoUpdater.on('update-downloaded', (event)=> {
updateWindow = new BrowserWindow({ updateWindow = new BrowserWindow({
width: 640, width: 640,
height: 480, height: 480,
// frame: process.platform == 'darwin',
// titleBarStyle: process.platform == 'darwin' ? 'hidden' : null
}); });
// and load the index.html of the app.
updateWindow.loadURL(`file://${__dirname}/update.html`); updateWindow.loadURL(`file://${__dirname}/update.html`);
// Open the DevTools.
// updateWindow.webContents.openDevTools();
// Emitted when the window is closed.
updateWindow.on('closed', function () { updateWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
updateWindow = null updateWindow = null
});
ipcMain.on('update', (event, arg) => {
autoUpdater.quitAndInstall()
}) })
}); });
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const child_process = require('child_process'); const child_process = require('child_process');
const path = require('path'); const path = require('path');
...@@ -179,7 +172,10 @@ function createWindow() { ...@@ -179,7 +172,10 @@ function createWindow() {
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.on('ready', createWindow); app.on('ready', ()=> {
autoUpdater.checkForUpdates();
createWindow()
});
// Quit when all windows are closed. // Quit when all windows are closed.
app.on('window-all-closed', function () { app.on('window-all-closed', function () {
......
update <!DOCTYPE html>
\ No newline at end of file <html>
<head>
<meta charset="UTF-8">
<title>更新</title>
</head>
<body>
有新版本,点击更新
<button id="update">更新</button>
如果自动更新失败,请至 https://mycard.moe 手动下载最新版本
<script>
const {ipcRenderer} = require('electron');
document.getElementById('update').addEventListener('click', ()=> {
ipcRenderer.send('update');
})
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment