Skip to content

Commit

Permalink
add updater
Browse files Browse the repository at this point in the history
  • Loading branch information
jtvberg committed Nov 18, 2021
1 parent b195704 commit 1f4dbbe
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
13 changes: 13 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { app, Tray, clipboard } = require('electron')
const path = require('path')
const updater = require('./updater')
const isDev = !app.isPackaged

// Tray icon
let tray = null
Expand All @@ -16,10 +18,21 @@ const createTray = () => {
})
}

// Load electron-reload in dev
if (isDev) {
require('electron-reload')(__dirname, {
electron: path.join(__dirname, 'node_modules', '.bin', 'electron')
})
}

// Hide the doc icon
app.dock.hide()

// Load tray and check for updates
app.whenReady().then(() => {
createTray()
!isDev && setTimeout(updater, 3000)
})

// Empty event registration to prevent tray garbage collection
app.on('activate', () => {})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TidyPaste",
"version": "0.1.0",
"version": "0.1.1",
"description": "Tidy Pasting",
"main": "main.js",
"scripts": {
Expand Down
54 changes: 54 additions & 0 deletions updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Modules and variable definition
const { dialog } = require('electron')
const { autoUpdater } = require('electron-updater')

// Uncomment below for updater logging
// autoUpdater.logger = require('electron-log')
// autoUpdater.logger.transports.file.level = 'info'

// Disabable auto-download of updates
autoUpdater.autoDownload = false

// Check for app updates
module.exports = () => {
autoUpdater.on('error', (err) => {
console.error(err)
})
// Check for updates
autoUpdater.checkForUpdates()
// Listen for update
autoUpdater.on('update-available', () => {
// Prompt for user to update
dialog.showMessageBox({
type: 'info',
title: 'Update Available',
message: 'A new version of Temporal is available. Do you want to update now?',
buttons: ['Update', 'Cancel'],
defaultId: 0,
cancelId: 1
}).then(result => {
// Download if Update chosen
if (result.response === 0) {
autoUpdater.downloadUpdate()
}
})
})

// Listen for update
autoUpdater.on('update-downloaded', () => {
// Prompt for user to update
dialog.showMessageBox({
type: 'info',
title: 'Update Ready',
message: 'Install and restart now?',
buttons: ['Install', 'Later'],
defaultId: 0,
cancelId: 1
}).then(result => {
// Download if Update chosen
if (result.response === 0) {
autoUpdater.quitAndInstall(false, true)
}
})
})
}

0 comments on commit 1f4dbbe

Please sign in to comment.