Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Commit c5b6836

Browse files
DanSallauborisyankov
authored andcommitted
Nuru/fix electron latest (#538)
* Fix latest electron * Remove unwanted console message * update package.json add url and icons to linux and windows builds * Appid for electron * Clean main js * Add update support * Its logger.debug not log * Use binary cloud instead
1 parent a93c129 commit c5b6836

File tree

6 files changed

+149
-61
lines changed

6 files changed

+149
-61
lines changed

build/icon.ico

38.6 KB
Binary file not shown.

package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"build:apk": "npm run build:dev && cordova build --release android && jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore tick-trade-key.keystore ./platforms/android/build/outputs/apk/android-release-unsigned.apk TickTrade && ~/Library/Android/sdk/build-tools/24.0.0/zipalign -v 4 ./platforms/android/build/outputs/apk/android-release-unsigned.apk ./platforms/android/build/outputs/apk/android-release-aligned.apk",
2222
"build:webpack": "NODE_ENV=production webpack --config webpack.config.js",
2323
"lint": "eslint src",
24-
"electron": "NODE_ENV=developement electron ./www",
24+
"electron": "NODE_ENV=production electron ./www/main.js",
2525
"translate": "bash fetch-translation.sh",
26-
"dist": "NODE_ENV=developement build -owl --ia32 --x64",
26+
"dist": "build -owl --ia32 --x64",
2727
"prerelease:osx": "rm -rf ./release/osx && mkdirp release/osx",
2828
"release:osx": "cp -rv ./dist/osx/*.{dmg,zip} ./release/osx && PACKAGE_VERSION=$(cat app/package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && echo $PACKAGE_VERSION >> ./release/osx/VERSION",
2929
"prerelease:win32": "rm -rf ./release/win32 && mkdirp release/win32",
@@ -37,7 +37,7 @@
3737
},
3838
"build": {
3939
"appId": "app.binary.com",
40-
"app-category-type": "public.app-category.trading",
40+
"category": "Binary Trading",
4141
"productName": "Binary.com",
4242
"osx": {
4343
"title": "Binary.com",
@@ -62,13 +62,18 @@
6262
},
6363
"win": {
6464
"iconUrl": "https://www.binary.com/images/favicons/favicon-192x192.png",
65-
"target": "zip",
65+
"target": "squirrel",
66+
"title": "Binary.com",
67+
"icon": "build/icon.ico",
6668
"loadingGif": "",
6769
"msi": true
6870
},
6971
"linux": {
7072
"description": "Sharp Prices. Smart Trading",
71-
"target": "zip"
73+
"title": "Binary.com",
74+
"icon": "build/icon.ico",
75+
"target": "AppImage",
76+
"vendor": "Binary (IOM) Ltd"
7277
}
7378
},
7479
"keywords": [

src/_data/Auth.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { history, accountExclusion } from '../_store/root.js';
55
import { api } from './LiveData';
66
import { updateAppState, removePersonalData, updateToken, updateBoot } from '../_actions';
77

8+
let authWindow = null;
9+
const electron = window.electron;
10+
811
export const tryAuth = async token => {
912
store.dispatch(updateAppState('authorized', false));
1013
try {
@@ -30,8 +33,31 @@ export const signOut = () => {
3033

3134
export const signIn = () => {
3235
const oAuthUrl = `https://oauth.binary.com/oauth2/authorize?app_id=${window.BinaryBoot.appId}&l=${window.BinaryBoot.language}`;
33-
34-
if (window.cordova) {
36+
if (electron) {
37+
const { BrowserWindow } = electron.remote;
38+
authWindow = new BrowserWindow({
39+
name: 'Binary.com',
40+
title: 'Login',
41+
width: 1024,
42+
height: 680,
43+
show: false,
44+
});
45+
authWindow.loadURL(oAuthUrl);
46+
authWindow.once('ready-to-show', () => {
47+
authWindow.show();
48+
});
49+
authWindow.setResizable(false);
50+
authWindow.on('close', () => {
51+
authWindow = null;
52+
}, false);
53+
authWindow.webContents.on('did-get-redirect-request', (e, oldUrl, newUrl) => {
54+
const accounts = window.BinaryBoot.parseUrl(newUrl);
55+
store.dispatch(updateBoot('accounts', accounts));
56+
store.dispatch(updateToken(accounts[0].token));
57+
tryAuth(accounts[0].token);
58+
authWindow.close();
59+
});
60+
} else if (window.cordova) {
3561
const winAuth = window.cordova.InAppBrowser.open(oAuthUrl, '_blank', 'location=no');
3662
winAuth.addEventListener('loadstart', e => {
3763
if (e.url.indexOf('acct1') > -1) {

www/boot.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@
6161
readConfig();
6262
parseUrlAndStoreAccountInfo(window.location.href);
6363
window.BinaryBoot.parseUrl = parseOAuthResponse;
64-
window.BinaryBoot.appId = window.cordova ? 1006 : 1001;
64+
if(window.cordova) {
65+
window.BinaryBoot.appId = 1006;
66+
} else if(window.electron) {
67+
window.BinaryBoot.appId = 1306;
68+
} else {
69+
window.BinaryBoot.appId = 1001;
70+
}
6571
var lang = window.BinaryBoot.language;
6672

6773
var redirectIndex = window.location.href.indexOf('?');

www/main.html

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
6+
<meta name="theme-color" content="#2a3052" />
7+
<meta name="msapplication-navbutton-color" content="#2a3052">
8+
<meta name="mobile-web-app-capable" content="yes">
9+
<meta name="apple-mobile-web-app-status-bar-style" content="#2a3052">
10+
<meta name="apple-mobile-web-app-capable" content="yes">
11+
<meta http-equiv="Content-Security-Policy"
12+
content="default-src https://codepush.azurewebsites.net http://github.com https://*.googleapis.com:* https://*.polyfill.io:* https://*.google-analytics.com:* wss://*.binaryws.com:* https://*.github.io:* https://*.binary.com:* https://binary.com:* https://*.gstatic.com:* https://*.cloudflare.com:* https://*.wordpress.com:* https://*.youtube.com:* https://*.trackjs.com:* 'self' data: gap: https://ssl.gstatic.com 'unsafe-inline' 'unsafe-eval' 'self'; media-src *; img-src * data:;">
13+
<link rel="icon" href="https://binary.com/images/favicons/apple-touch-icon-57x57.png" rel="apple-touch-icon" sizes="57x57" />
14+
<link rel="stylesheet" href="fonts.css" />
15+
<link rel="stylesheet" href="styles.css" />
16+
<title>Binary.com - nextGen</title>
17+
<style id="antiClickjack">body{display:none !important;}</style>
18+
<script>
19+
if (self === top) {
20+
var antiClickjack = document.getElementById('antiClickjack');
21+
antiClickjack.parentNode.removeChild(antiClickjack);
22+
} else {
23+
top.location = self.location;
24+
}
25+
26+
(function(l) {
27+
if (l.search) {
28+
var q = {};
29+
l.search.slice(1).split('&').forEach(function(v) {
30+
var a = v.split('=');
31+
q[a[0]] = a.slice(1).join('=').replace(/~and~/g, '&');
32+
});
33+
if (q.p !== undefined) {
34+
window.history.replaceState(null, null,
35+
(q.p || '') +
36+
(q.q ? ('?' + q.q) : '') +
37+
l.hash
38+
);
39+
}
40+
}
41+
}(window.location))
42+
</script>
43+
</head>
44+
45+
<body>
46+
47+
<div id="root" class="root app">
48+
<div class="loading-page">
49+
<div class="logo-full">
50+
<img src="img/binary-symbol-logo.svg" alt="Logo" /><img src="img/binary-type-logo.svg" alt="Binary.com" />
51+
</div>
52+
<div class="barspinner">
53+
<div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div><div class="rect5"></div>
54+
</div>
55+
</div>
56+
</div>
57+
<script>
58+
window.electron = require('electron');
59+
</script>
60+
61+
<script src="boot.js"></script>
62+
<script async src="app.js"></script>
63+
64+
<script>
65+
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
66+
ga('create', 'UA-40877026-8', 'auto');
67+
ga('send', 'pageview');
68+
</script>
69+
<script async src='https://www.google-analytics.com/analytics.js'></script>
70+
71+
</body>
72+
</html>

www/main.js

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,69 @@
11
// Handle Squirrel events for Windows immediately on start
22
if (require('electron-squirrel-startup')) { return; }
33

4+
const pack = require('./package.json');
5+
6+
const appVersion = pack.version;
7+
48
const electron = require('electron');
59
const { app } = electron;
610
const { BrowserWindow } = electron;
711
const { autoUpdater } = electron;
812
const os = require('os');
913
let mainWindow = null;
1014
const { Menu } = electron;
11-
let forceQuit = false;
12-
const name = app.getName();
15+
let feedLink = '';
16+
17+
app.setName(pack.productName);
18+
1319
let updateFeed = 'http://localhost:3000/updates/latest';
1420
const isDevelopment = process.env.NODE_ENV === 'development';
1521

1622
const logger = require('winston');
17-
1823
logger.level = 'debug';
1924
global.logger = logger;
25+
2026
const path = require('path');
2127

22-
// Don't use auto-updater if we are in development
2328
if (!isDevelopment) {
2429
if (os.platform() === 'darwin') {
25-
updateFeed = 'http://app-binary.herokuapp.com/updates/latest';
30+
updateFeed = 'http://binary.herokuapp.com/updates/latest';
2631
} else if (os.platform() === 'win32') {
2732
updateFeed = 'http://app-binary.s3.amazonaws.com/updates/latest/win' + (os.arch() === 'x64' ? '64' : '32');
2833
}
2934

30-
autoUpdater.addListener('update-available', function(event) {
31-
logger.log('A new update is available');
35+
autoUpdater.addListener('update-available', function (event) {
36+
logger.debug('A new update is available');
3237
if (mainWindow) {
3338
mainWindow.webContents.send('update-message', 'update-available');
3439
}
3540
});
3641
autoUpdater.addListener('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateURL) {
37-
logger.log('A new update is ready to install', `Version ${releaseName} is downloaded from ${updateURL} and will be automatically installed on Quit`);
42+
logger.debug('A new update is ready to install', `Version ${releaseName} is downloaded from ${updateURL} and will be automatically installed on Quit`);
3843
if (mainWindow) {
3944
mainWindow.webContents.send('update-message', 'update-downloaded');
4045
}
4146
});
4247
autoUpdater.addListener('error', function (error) {
43-
logger.log(error);
48+
logger.debug(`error is ${error}`);
4449
if (mainWindow) {
4550
mainWindow.webContents.send('update-message', 'update-error');
4651
}
4752
});
4853
autoUpdater.addListener('checking-for-update', function (event) {
49-
logger.log('checking-for-update');
54+
logger.debug('checking-for-update');
5055
if (mainWindow) {
5156
mainWindow.webContents.send('update-message', 'checking-for-update');
5257
}
5358
});
54-
autoUpdater.addListener("update-not-available", function () {
55-
logger.log('update-not-available');
59+
autoUpdater.addListener('update-not-available', function () {
60+
logger.debug('update-not-available');
5661
if (mainWindow) {
5762
mainWindow.webContents.send('update-message', 'update-not-available');
5863
}
5964
});
6065

61-
const appVersion = require('./package.json').version;
62-
const feedLink = updateFeed + '?v=' + appVersion;
66+
feedLink = updateFeed + '?v=' + appVersion;
6367
autoUpdater.setFeedURL(feedLink);
6468
}
6569

@@ -70,11 +74,12 @@ electron.crashReporter.start({
7074
autoSubmit: true,
7175
});
7276

73-
app.on('window-all-closed', function() {
74-
if (process.platform !== 'darwin') {
77+
app.on('window-all-closed', function () {
7578
app.quit();
76-
}
7779
});
80+
81+
const name = app.getName();
82+
7883
const template = [
7984
{
8085
label: 'View',
@@ -99,7 +104,7 @@ const template = [
99104
label: 'Toggle Developer Tools',
100105
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
101106
click(item, focusedWindow) {
102-
if (focusedWindow && isDevelopment) {
107+
if (focusedWindow) {
103108
focusedWindow.webContents.toggleDevTools();
104109
}
105110
},
@@ -122,7 +127,6 @@ const template = [
122127
label: 'Quit',
123128
accelerator: 'Command+Q',
124129
click() {
125-
forceQuit = true;
126130
app.quit();
127131
},
128132
},
@@ -142,7 +146,7 @@ const template = [
142146
submenu: [
143147
{
144148
label: 'Learn More',
145-
click() { require('electron').shell.openExternal('http://app.binary.com'); },
149+
click() { electron.shell.openExternal('http://app.binary.com'); },
146150
},
147151
],
148152
},
@@ -174,7 +178,6 @@ if (process.platform === 'darwin') {
174178
label: 'Quit',
175179
accelerator: 'Command+Q',
176180
click() {
177-
forceQuit = true;
178181
app.quit();
179182
},
180183
},
@@ -196,42 +199,18 @@ app.on('ready', function() {
196199
toolbar: false,
197200
});
198201

199-
mainWindow.loadURL(path.join('file://', __dirname, '/index.html'));
202+
203+
mainWindow.loadURL(path.join('file://', __dirname, '/main.html'));
200204

201205
mainWindow.on('closed', function () {
202-
console.log('closed');
203206
mainWindow = null;
204-
app.quit();
205207
});
206208

207-
// Uncomment to use Chrome developer tools
208-
// mainWindow.webContents.openDevTools({ detach: true });
209-
210-
mainWindow.on('close', function (e) {
211-
if (!forceQuit) {
212-
e.preventDefault();
213-
mainWindow.hide();
214-
} else {
215-
app.quit();
216-
}
217-
});
218-
app.on('activate', function () {
219-
mainWindow.show();
220-
});
221-
222-
mainWindow.on('show', function (e) {
223-
mainWindow.show();
224-
});
225-
226-
mainWindow.on('hide', function (e) {
227-
mainWindow.hide();
228-
});
229-
});
230-
231-
app.on('activate', function (e) {
232-
mainWindow.show();
233-
});
234-
app.on('before-quit', function (e) {
235-
forceQuit = true;
209+
if (!isDevelopment) {
210+
mainWindow.webContents.on('did-frame-finish-load', function() {
211+
logger.debug('Checking for updates: ' + feedLink);
212+
autoUpdater.checkForUpdates();
213+
});
214+
}
236215
});
237216

0 commit comments

Comments
 (0)