Skip to content

Commit

Permalink
added version update check
Browse files Browse the repository at this point in the history
  • Loading branch information
fuatu committed Jun 26, 2020
1 parent 9aa365d commit b76ca87
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
4 changes: 4 additions & 0 deletions dev-app-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
owner: fuatu
repo: markdown-editor
provider: github
updaterCacheDirName: markdown-editor-updater
35 changes: 32 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { app, BrowserWindow, Menu } = require('electron');
const { app, BrowserWindow, Menu, shell } = require('electron');
const { autoUpdater } = require('electron-updater');
const menu = require('./menu');
const log = require('electron-log');

let window;

Expand All @@ -13,7 +14,35 @@ app.on('ready', () => {
}
});
window.loadFile('index.html');
autoUpdater.checkForUpdatesAndNotify();
// autoUpdater.checkForUpdatesAndNotify();
log.info("Checking update... on app ready");
autoUpdater.autoDownload=false;
autoUpdater.checkForUpdates();
});

Menu.setApplicationMenu(menu);
Menu.setApplicationMenu(menu);

autoUpdater.on('update-available', (event) => {
var update_url = "https://github.com/fuatu/markdown-editor/releases/download/v" + event.version + "/" + event.path;
const dialogOpts = {
type: 'info',
buttons: ['Update', 'Later'],
title: 'Application Update',
message: event.releaseName,
detail: 'New version available\n' + event.path
}


log.info("Trying an update inside. update-available");
dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) {
log.info("opening browser for downloading!");
shell.openExternal(update_url);
}
})
});

autoUpdater.on('error', message => {
log.error('There was a problem updating the application index.js')
//log.error(message)
});
13 changes: 12 additions & 1 deletion menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const {
ipcMain,
BrowserWindow,
globalShortcut,
dialog
dialog,
} = require('electron');
const { autoUpdater } = require('electron-updater');
const fs = require('fs');
const log = require('electron-log');

app.on('ready', () => {
globalShortcut.register('CommandOrControl+S', () => {
Expand Down Expand Up @@ -90,6 +92,14 @@ const template = [
click() {
saveFile();
}
},
{
label: 'Check Updates',
click() {
log.info("Checking for update by user trigger from menu")
autoUpdater.autoDownload=false;
autoUpdater.checkForUpdates();
}
}
]
},
Expand Down Expand Up @@ -156,3 +166,4 @@ if (process.env.DEBUG) {
const menu = Menu.buildFromTemplate(template);

module.exports = menu;

5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "markdown-editor",
"version": "1.0.1",
"description": "A simple markdown editor",
"version": "1.0.0",
"description": "A simple markdown editor. v1.1.0",
"main": "index.js",
"scripts": {
"start": "DEBUG=true electron .",
Expand All @@ -24,7 +24,13 @@
"electron-builder": "^22.7.0"
},
"dependencies": {
"electron-log": "^4.2.2",
"electron-updater": "^4.3.1",
"simplemde": "^1.11.2"
},
"extendInfo": {
"NSAppTransportSecurity": {
"NSAllowsArbitraryLoads": true
}
}
}

0 comments on commit b76ca87

Please sign in to comment.