mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-10 19:16:10 +00:00
182eaa4329
* Basic webpack build started. * Get build working with electron-packager. Not fully satisfied, might investigate electron-builder. * Custom title bar * Rewrite all webpack configs to use common function. Organize webpack utils. Split into multiple dist folders. * Replace electron build with electron-builder. Leave around packager for a bit. * Check in progress on updater. * Update modal flow. * Fix tscheck. * Adjust publish info. * Arbitrary version bump. * Bump version again. * 5.0.2 bump fix autodownload. * 5.0.2 bump again, readd dmg * 5.0.3 bump * Turn auto update back off. Log errors. Revert versions. * Add os-specific builds. Improve update failure. * Open external links in browser in electron. * Remove custom title bar temporarily. * Add info about the update download to the modal. * Turn off development changes. * Take the postBuild sorting script and move it into a webpack config. * Initial conversion to typescript and electron-webpack. * Switch from electron-webpack back to custom config, clean up unused code, typify electron bridge. * Better typing for bridge. * Remove unnecessary file. * Reminify. * Add shared folder resolving to jest config. * Add enum to electron events
98 lines
2.8 KiB
TypeScript
98 lines
2.8 KiB
TypeScript
import { App, BrowserWindow, ipcMain } from 'electron';
|
|
import { autoUpdater } from 'electron-updater';
|
|
import EVENTS from '../../shared/electronEvents';
|
|
import TEST_RELEASE from './testrelease.json';
|
|
autoUpdater.autoDownload = false;
|
|
|
|
enum AutoUpdaterEvents {
|
|
CHECKING_FOR_UPDATE = 'checking-for-update',
|
|
UPDATE_NOT_AVAILABLE = 'update-not-available',
|
|
UPDATE_AVAILABLE = 'update-available',
|
|
DOWNLOAD_PROGRESS = 'download-progress',
|
|
UPDATE_DOWNLOADED = 'update-downloaded',
|
|
ERROR = 'error'
|
|
}
|
|
|
|
export default (app: App, window: BrowserWindow) => {
|
|
// Set to 'true' if you want to test update behavior. Requires a recompile.
|
|
const shouldMockUpdate = true && process.env.NODE_ENV !== 'production';
|
|
|
|
// Report update status
|
|
autoUpdater.on(AutoUpdaterEvents.CHECKING_FOR_UPDATE, () => {
|
|
window.webContents.send(EVENTS.UPDATE.CHECKING_FOR_UPDATE);
|
|
});
|
|
|
|
autoUpdater.on(AutoUpdaterEvents.UPDATE_NOT_AVAILABLE, () => {
|
|
window.webContents.send(EVENTS.UPDATE.UPDATE_NOT_AVAILABLE);
|
|
});
|
|
|
|
autoUpdater.on(AutoUpdaterEvents.UPDATE_AVAILABLE, info => {
|
|
window.webContents.send(EVENTS.UPDATE.UPDATE_AVAILABLE, info);
|
|
});
|
|
|
|
autoUpdater.on(AutoUpdaterEvents.DOWNLOAD_PROGRESS, progress => {
|
|
window.webContents.send(EVENTS.UPDATE.DOWNLOAD_PROGRESS, progress);
|
|
});
|
|
|
|
autoUpdater.on(AutoUpdaterEvents.UPDATE_DOWNLOADED, () => {
|
|
window.webContents.send(EVENTS.UPDATE.UPDATE_DOWNLOADED);
|
|
});
|
|
|
|
autoUpdater.on(AutoUpdaterEvents.ERROR, (err, msg) => {
|
|
console.error('Update failed with an error');
|
|
console.error(err);
|
|
window.webContents.send(EVENTS.UPDATE.ERROR, msg);
|
|
});
|
|
|
|
autoUpdater.checkForUpdatesAndNotify();
|
|
|
|
// Listen for restart request
|
|
ipcMain.on(EVENTS.UPDATE.DOWNLOAD_UPDATE, () => {
|
|
if (shouldMockUpdate) {
|
|
mockDownload(window);
|
|
} else {
|
|
autoUpdater.downloadUpdate();
|
|
}
|
|
});
|
|
|
|
ipcMain.on(EVENTS.UPDATE.QUIT_AND_INSTALL, () => {
|
|
if (shouldMockUpdate) {
|
|
app.quit();
|
|
} else {
|
|
autoUpdater.quitAndInstall();
|
|
}
|
|
});
|
|
|
|
// Simulate a test release
|
|
if (shouldMockUpdate) {
|
|
mockUpdateCheck(window);
|
|
}
|
|
};
|
|
|
|
// Mock functions for dev testing
|
|
function mockUpdateCheck(window: BrowserWindow) {
|
|
window.webContents.send(EVENTS.UPDATE.CHECKING_FOR_UPDATE);
|
|
|
|
setTimeout(() => {
|
|
window.webContents.send(EVENTS.UPDATE.UPDATE_AVAILABLE, TEST_RELEASE);
|
|
}, 3000);
|
|
}
|
|
|
|
function mockDownload(window: BrowserWindow) {
|
|
for (let i = 0; i < 101; i++) {
|
|
setTimeout(() => {
|
|
const total = 150000000;
|
|
window.webContents.send(EVENTS.UPDATE.DOWNLOAD_PROGRESS, {
|
|
bytesPerSecond: Math.round(Math.random() * 100000),
|
|
percent: i,
|
|
transferred: total / i,
|
|
total
|
|
});
|
|
|
|
if (i === 100) {
|
|
window.webContents.send(EVENTS.UPDATE.UPDATE_DOWNLOADED);
|
|
}
|
|
}, 50 * i);
|
|
}
|
|
}
|