Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat(auto-updater): set progress bar and add to menu
Browse files Browse the repository at this point in the history
fixes #84
  • Loading branch information
Jumace authored and lkuechler committed Dec 22, 2017
1 parent c5228fb commit e024cc4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 50 deletions.
49 changes: 16 additions & 33 deletions src/electron/auto-updater.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,26 @@
import { sendStatusToWindow } from './electron';
import { dialog } from 'electron';
import { BrowserWindow, dialog } from 'electron';
import { autoUpdater } from 'electron-updater';

// autoUpdater.logger = log;

export function checkForUpdates(): void {
export function checkForUpdates(win: BrowserWindow): void {
autoUpdater.checkForUpdatesAndNotify().catch(() => {
sendStatusToWindow('Error in auto-updater.');
dialog.showErrorBox('Check for Updates', 'Error while checking for updates');
});
}

autoUpdater.checkForUpdatesAndNotify().catch(() => {
sendStatusToWindow('Error in auto-updater.');
});

autoUpdater.on('checking-for-update', info => {
sendStatusToWindow('Checking for update...');
});

autoUpdater.on('update-available', info => {
sendStatusToWindow('Update available.');
dialog.showMessageBox({ message: `There is a new Alva version: ${info.version}` });
});

autoUpdater.on('update-not-available', info => {
sendStatusToWindow('Update not available.');
});
autoUpdater.on('update-available', info => {
dialog.showMessageBox({ message: `There is a new Alva version: ${info.version}` });
});

autoUpdater.on('error', err => {
sendStatusToWindow(`Error in auto-updater. ${err}`);
});
autoUpdater.on('error', () => {
dialog.showErrorBox('Check for Updates', 'Error on receiving update. Please try manually');
});

autoUpdater.on('download-progress', progressObj => {
let log_message = `Download speed: ${progressObj.bytesPerSecond}`;
log_message = `${log_message} - Downloaded ${progressObj.percent}%`;
log_message = `${log_message} (${progressObj.transferred}/${progressObj.total})`;
sendStatusToWindow(log_message);
});
autoUpdater.on('download-progress', progressObj => {
win.setProgressBar(progressObj.percent);
});

autoUpdater.on('update-downloaded', info => {
sendStatusToWindow('Update downloaded');
});
autoUpdater.on('update-downloaded', info => {
dialog.showMessageBox({ message: 'Update downloaded. Will be installed on next restart' });
});
}
7 changes: 1 addition & 6 deletions src/electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ function createWindow(): void {
console.warn('An error occurred: ', err);
});
}
checkForUpdates();
}
export function sendStatusToWindow(text: string): void {
if (win) {
win.webContents.send('message', text);
}
checkForUpdates(win);
}

const log = require('electron-log');
Expand Down
32 changes: 21 additions & 11 deletions src/electron/menu.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { checkForUpdates } from './auto-updater';
import { BrowserWindow, MenuItem, MenuItemConstructorOptions, remote, WebContents } from 'electron';
import * as FileExtraUtils from 'fs-extra';
import { PageElement } from '../store/page/page_element';
Expand All @@ -21,18 +22,21 @@ export function createMenu(store: Store): void {

const designkitPath = PathUtils.join(appPath, 'build', 'designkit');
console.log(`Design kit path is: ${designkitPath}`);
dialog.showOpenDialog({ properties: ['openDirectory', 'createDirectory'] }, filePaths => {
if (filePaths.length <= 0) {
return;
}
dialog.showOpenDialog(
{ properties: ['openDirectory', 'createDirectory'] },
filePaths => {
if (filePaths.length <= 0) {
return;
}

FileExtraUtils.copySync(
designkitPath,
PathUtils.join(filePaths[0], 'designkit')
);
store.openStyleguide(`${filePaths[0]}/designkit`);
store.openFirstPage();
});
FileExtraUtils.copySync(
designkitPath,
PathUtils.join(filePaths[0], 'designkit')
);
store.openStyleguide(`${filePaths[0]}/designkit`);
store.openFirstPage();
}
);
}
},
{
Expand Down Expand Up @@ -272,6 +276,12 @@ export function createMenu(store: Store): void {
label: 'About ' + name,
role: 'about'
},
{
label: 'Check for Updates',
click: () => {
checkForUpdates(remote.getCurrentWindow());
}
},
{
type: 'separator'
},
Expand Down

0 comments on commit e024cc4

Please sign in to comment.