mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Fixed tray icon and update issue
This commit is contained in:
parent
1e94a22986
commit
af82345eb8
@ -5,6 +5,7 @@ const url = require('url')
|
||||
const path = require('path')
|
||||
const urlUtils = require('lib/urlUtils.js');
|
||||
const { dirname, basename } = require('lib/path-utils');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
class ElectronAppWrapper {
|
||||
|
||||
@ -14,6 +15,7 @@ class ElectronAppWrapper {
|
||||
this.win_ = null;
|
||||
this.willQuitApp_ = false;
|
||||
this.tray_ = null;
|
||||
this.buildDir_ = null;
|
||||
}
|
||||
|
||||
electronApp() {
|
||||
@ -116,13 +118,20 @@ class ElectronAppWrapper {
|
||||
}
|
||||
|
||||
buildDir() {
|
||||
let dir = __dirname;
|
||||
if (dir.indexOf('.asar') >= 0 || basename(dir) === 'app') dir = dirname(dir);
|
||||
return dir + '/build';
|
||||
if (this.buildDir_) return this.buildDir_;
|
||||
let dir = __dirname + '/build';
|
||||
if (!fs.pathExistsSync(dir)) {
|
||||
dir = dirname(__dirname) + '/build';
|
||||
if (!fs.pathExistsSync(dir)) throw new Error('Cannot find build dir');
|
||||
}
|
||||
|
||||
this.buildDir_ = dir;
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Note: this must be called only after the "ready" event of the app has been dispatched
|
||||
createTray(contextMenu) {
|
||||
try {
|
||||
this.tray_ = new Tray(this.buildDir() + '/icons/16x16.png')
|
||||
this.tray_.setToolTip(this.electronApp_.getName())
|
||||
this.tray_.setContextMenu(contextMenu)
|
||||
@ -130,6 +139,9 @@ class ElectronAppWrapper {
|
||||
this.tray_.on('click', () => {
|
||||
this.window().show();
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Cannot create tray", error);
|
||||
}
|
||||
}
|
||||
|
||||
destroyTray() {
|
||||
|
@ -6,6 +6,9 @@ const { _ } = require('lib/locale.js');
|
||||
let autoUpdateLogger_ = new Logger();
|
||||
let checkInBackground_ = false;
|
||||
|
||||
// Note: Electron Builder's autoUpdater is incredibly buggy so currently it's only used
|
||||
// to detect if a new version is present. If it is, the download link is simply opened
|
||||
// in a new browser window.
|
||||
autoUpdater.autoDownload = false;
|
||||
|
||||
autoUpdater.on('error', (error) => {
|
||||
@ -14,19 +17,36 @@ autoUpdater.on('error', (error) => {
|
||||
dialog.showErrorBox(_('Error'), error == null ? "unknown" : (error.stack || error).toString())
|
||||
})
|
||||
|
||||
autoUpdater.on('update-available', () => {
|
||||
function htmlToText_(html) {
|
||||
let output = html.replace(/\n/g, '');
|
||||
output = output.replace(/<li>/g, '- ');
|
||||
output = output.replace(/<\/li>/g, '\n');
|
||||
output = output.replace(/<ul>/g, '');
|
||||
output = output.replace(/<\/ul>/g, '');
|
||||
output = output.replace(/<.*?>/g, '');
|
||||
output = output.replace(/<\/.*?>/g, '');
|
||||
return output;
|
||||
}
|
||||
|
||||
autoUpdater.on('update-available', (info) => {
|
||||
if (!info.version || !info.path) {
|
||||
if (checkInBackground_) return;
|
||||
dialog.showErrorBox(_('Error'), ('Could not get version info: ' + JSON.stringify(info)));
|
||||
return;
|
||||
}
|
||||
|
||||
const downloadUrl = 'https://github.com/laurent22/joplin/releases/download/v' + info.version + '/' + info.path;
|
||||
|
||||
let releaseNotes = info.releaseNotes + '';
|
||||
if (releaseNotes) releaseNotes = '\n\n' + _('Release notes:\n\n%s', htmlToText_(releaseNotes));
|
||||
|
||||
dialog.showMessageBox({
|
||||
type: 'info',
|
||||
message: _('An update is available, do you want to update now?'),
|
||||
message: _('An update is available, do you want to download it now?' + releaseNotes),
|
||||
buttons: [_('Yes'), _('No')]
|
||||
}, (buttonIndex) => {
|
||||
if (buttonIndex === 0) {
|
||||
try {
|
||||
autoUpdater.downloadUpdate()
|
||||
} catch (error) {
|
||||
autoUpdateLogger_.error(error);
|
||||
dialog.showErrorBox(_('Error'), _('Could not download the update: %s', error.message));
|
||||
}
|
||||
require('electron').shell.openExternal(downloadUrl);
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -37,18 +57,18 @@ autoUpdater.on('update-not-available', () => {
|
||||
dialog.showMessageBox({ message: _('Current version is up-to-date.') })
|
||||
})
|
||||
|
||||
autoUpdater.on('update-downloaded', () => {
|
||||
dialog.showMessageBox({ message: _('New version downloaded - application will quit now and update...') }, () => {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
autoUpdater.quitAndInstall();
|
||||
} catch (error) {
|
||||
autoUpdateLogger_.error(error);
|
||||
dialog.showErrorBox(_('Error'), _('Could not install the update: %s', error.message));
|
||||
}
|
||||
}, 100);
|
||||
})
|
||||
})
|
||||
// autoUpdater.on('update-downloaded', () => {
|
||||
// dialog.showMessageBox({ message: _('New version downloaded - application will quit now and update...') }, () => {
|
||||
// setTimeout(() => {
|
||||
// try {
|
||||
// autoUpdater.quitAndInstall();
|
||||
// } catch (error) {
|
||||
// autoUpdateLogger_.error(error);
|
||||
// dialog.showErrorBox(_('Error'), _('Could not install the update: %s', error.message));
|
||||
// }
|
||||
// }, 100);
|
||||
// })
|
||||
// })
|
||||
|
||||
function checkForUpdates(inBackground, logFilePath) {
|
||||
if (logFilePath && !autoUpdateLogger_.targets().length) {
|
||||
|
Loading…
Reference in New Issue
Block a user