Skip to content

Commit

Permalink
updater
Browse files Browse the repository at this point in the history
  • Loading branch information
iliyaZelenko committed Sep 12, 2018
1 parent aafa855 commit a306521
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ yarn-error.log*

#Electron-builder output
/dist_electron

electron-builder.env
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-electron-images-uploader",
"version": "0.1.1",
"version": "0.1.2",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
66 changes: 63 additions & 3 deletions src/layouts/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
<!--<v-navigation-drawer app />-->
<!--<v-toolbar app />-->
<v-content>
<v-alert
:value="updateStatus"
:type="alertType"
>
{{ alertText }}
</v-alert>

<v-container fluid>
<div id="nav">
<router-link to="/">
Expand All @@ -21,6 +28,10 @@
</v-content>
<v-footer>
<span class="ml-3">Author: Ilya Zelenko</span>
<v-spacer/>

{{ releaseName ? `Realease: ${releaseName} (${releaseAt})` : '' }}

</v-footer>
</v-app>
</template>
Expand All @@ -37,10 +48,59 @@

<script>
export default {
data: () => ({
updateStatus: null,
alertType: null,
alertText: null,
releaseName: null,
releaseDate: null
}),
computed: {
releaseAt () {
return new Date(this.releaseDate).toLocaleDateString()
}
},
created () {
console.log(123)
this.$electron.ipcRenderer.on('updater-message', (event, message) => {
console.log(event, message)
// this.$electron.remote.dialog.showMessageBox({
// type: 'question',
// buttons: ['Install and Relaunch', 'Later'],
// defaultId: 0,
// message: 'A new version of has been downloaded',
// detail: 'Привте'
// }, response => {
// console.log(response)
// })
// this.$electron.remote.dialog.showOpenDialog(
// this.$electron.remote.getCurrentWindow(),
// {
// defaultPath: 'c:/',
// filters: [
// { name: 'All Files', extensions: ['*'] },
// { name: 'Images', extensions: ['jpg13232', 'png', 'gif'] },
// { name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] }
// ],
// properties: ['openFile']
// }
// )
const alerts = {
notAvailable: { type: 'info', msg: 'Update not available.' },
available: { type: 'success', msg: 'Update available.' }
}
this.$electron.ipcRenderer.on('updater-message', (event, { status, info }) => {
const { type: alertType, msg: alertText } = alerts[status]
this.alertType = alertType
this.alertText = alertText
this.updateStatus = status
if (status === 'notAvailable') {
this.releaseName = info.releaseName
this.releaseDate = info.releaseDate
}
console.log(status, info)
})
}
}
Expand Down
55 changes: 46 additions & 9 deletions src/tools/Updater.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { app, dialog } from 'electron'
import { autoUpdater } from 'electron-updater'
import log from 'electron-log'
import * as path from 'path'
Expand All @@ -8,31 +9,67 @@ export default function (globalWindow) {
window = globalWindow

// if (isDev) {
console.log(path.join(__dirname, '../', 'app-update.yml'))
autoUpdater.updateConfigPath = path.join(__dirname, '../', 'app-update.yml')
autoUpdater.updateConfigPath = path.join(__dirname, '../app-update.yml')
// }

autoUpdater.logger = log
autoUpdater.logger.transports.file.level = 'info'
log.info('App starting...')

autoUpdater.on('checking-for-update', () => {
sendStatusToWindow('Checking for update...')
// sendStatusToWindow('Checking for update...')
})
autoUpdater.on('update-available', (info) => {
sendStatusToWindow('Update available.')
sendStatusToWindow('available', info)
})
autoUpdater.on('update-not-available', (info) => {
sendStatusToWindow('Update not available.')
// console.log(info)
sendStatusToWindow('notAvailable', info)
})
autoUpdater.on('error', (err) => {
sendStatusToWindow('Error in auto-updater: ' + err)
dialog.showErrorBox('Error: ', err === null ? 'unknown' : (err.stack || err).toString())
// sendStatusToWindow('error', err)
})

function sendStatusToWindow (msg) {
console.log(msg)
window.webContents.send('updater-message', msg)
function sendStatusToWindow (status, info = null) {
window.webContents.send('updater-message', { status, info })
}

autoUpdater.checkForUpdates() // checkForUpdatesAndNotify()
}

autoUpdater.on('update-available', () => {
dialog.showMessageBox({
type: 'info',
title: 'Found Updates',
message: 'Found updates, do you want update now?',
buttons: ['Sure', 'No']
}, (buttonIndex) => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate()
}
})
})

autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
let message = app.getName() + ' ' + releaseName + ' is now available. It will be installed the next time you restart the application.'
if (releaseNotes) {
const splitNotes = releaseNotes.split(/[^\r]\n/)
message += '\n\nRelease notes:\n'
splitNotes.forEach(notes => {
message += notes + '\n\n'
})
}
// Ask user to update the app
dialog.showMessageBox({
type: 'question',
buttons: ['Install and Relaunch', 'Later'],
defaultId: 0,
message: 'A new version of ' + app.getName() + ' has been downloaded',
detail: message
}, response => {
if (response === 0) {
setTimeout(() => autoUpdater.quitAndInstall(), 1)
}
})
})
3 changes: 2 additions & 1 deletion src/tools/events/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ function shortcut () {
// // window.webContents.send('ping', 'whoooooooh1!')
// })

globalShortcut.register('Alt+PrintScreen', () => {
// 'Alt+PrintScreen'
globalShortcut.register('CommandOrControl+Q', () => {
trayWindow.webContents.send('print-screen')
showTrayWindow()
})
Expand Down
2 changes: 1 addition & 1 deletion src/views/Home.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div>
<v-alert
type="info"
:value="!images.length"
type="info"
>
Here you will see the downloaded pictures.
</v-alert>
Expand Down

0 comments on commit a306521

Please sign in to comment.