Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(autoUpdates): check for updates during splashscreen and added user feedback #853

Merged
merged 4 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let mainWindow;
let splashWindow;

const isMac = process.platform === 'darwin';
const iconPath = path.join(getStaticPath(), 'icons', 'icon1024x1024.png');

function getWindowPath(productionPath, filename) {
const windowPath = isDev
Expand All @@ -42,28 +43,9 @@ function getWindowPath(productionPath, filename) {
return windowPath.includes('?') ? windowPath : `${windowPath}?`;
}

function createWindow() {
function createMainWindow() {
const framelessConfig = isMac ? { titleBarStyle: 'hidden' } : { frame: false };

const iconPath = path.join(getStaticPath(), 'icons', 'icon1024x1024.png');

// splashWindow is shown while mainWindow is loading hidden
// As it is light weight it will load almost instantly and before mainWindow
splashWindow = new BrowserWindow({
width: 320,
height: 320,
titleBarStyle: 'customButtonsOnHover',
show: false,
frame: false,
transparent: true,
icon: iconPath
});

splashWindow.loadURL(getWindowPath(getStaticPath(), 'splash.html'));
splashWindow.once('ready-to-show', () => {
splashWindow.show();
});

// Main Window
mainWindow = new BrowserWindow(
Object.assign(
Expand Down Expand Up @@ -93,26 +75,49 @@ function createWindow() {
});
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', async () => {
if (!isDev) {
function createSplashWindow() {
// splashWindow is shown while mainWindow is loading hidden
// As it is light weight it will load almost instantly and before mainWindow
splashWindow = new BrowserWindow({
width: 320,
height: 320,
titleBarStyle: 'customButtonsOnHover',
show: false,
frame: false,
transparent: true,
icon: iconPath
});

splashWindow.loadURL(getWindowPath(getStaticPath(), 'splash.html'));
splashWindow.once('ready-to-show', () => {
splashWindow.show();

autoUpdater.allowPrerelease = false;
autoUpdater.checkForUpdates();
autoUpdater.on('update-available', (info) => {
splashWindow.webContents.send('updaterMsg', `Updating nOS client to version ${info.version}`);
});
autoUpdater.on('update-not-available', () => {
createMainWindow();
});
autoUpdater.on('update-downloaded', () => {
autoUpdater.quitAndInstall();
});
}
});
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', async () => {
registerNosProtocol();
injectHeaders();

if (isDev) {
await installExtensions();
}

createWindow();
createSplashWindow();
});

// Quit when all windows are closed.
Expand All @@ -124,6 +129,6 @@ app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
createMainWindow();
}
});
1 change: 0 additions & 1 deletion src/main/util/registerNosProtocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default function registerNosProtocol() {

await stream(uri, callback);
} catch (error) {
// console.error(error);
callback({ error });
}
});
Expand Down
17 changes: 11 additions & 6 deletions static/splash.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />

<script>
if (typeof module === "object") {
if (typeof module === 'object') {
// unset module
window.module = module;
module = undefined;
}
</script>

<script>
if (window.module) {
// set module - allow script imports in electron
module = window.module;
}
</script>

<style>
html,
body {
Expand All @@ -27,13 +24,13 @@
height: 98%;
margin: 0;
overflow: hidden;
font-family: "Rubik", sans-serif;
font-family: 'Rubik', sans-serif;
}

#animation {
width: 50%;
height: 50%;
background: url("animations/nos-loader@2x.gif") no-repeat center center;
background: url('animations/nos-loader@2x.gif') no-repeat center center;
background-size: contain;
max-width: 180px;
max-height: 180px;
Expand Down Expand Up @@ -83,5 +80,13 @@
<div class="title">Decentralized Overdrive</div>
<div class="subtitle" id="info">Loading</div>
</div>

<script>
const { ipcRenderer } = require('electron');
ipcRenderer.once('updaterMsg', function(event, msg) {
document.getElementById('info').style.fontSize = '12px';
document.getElementById('info').innerHTML = msg;
});
</script>
</body>
</html>