Skip to content

Commit

Permalink
Windows (#4)
Browse files Browse the repository at this point in the history
* Add windows

* add build script

* new logo

* added vscode debug config

* update
  • Loading branch information
Jerry Tsui authored Sep 11, 2018
1 parent c5650c2 commit 915c51e
Show file tree
Hide file tree
Showing 9 changed files with 1,683 additions and 1,111 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
node_modules
.DS_Store
.vscode
dist
deploy.sh
lib
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"program": "${workspaceRoot}/src/main.js",
"args": [
"."
],
"protocol": "inspector",
}
]
}
Binary file added assets/logo-16-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,618 changes: 1,572 additions & 1,046 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 22 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"repository": "https://github.com/peniqliotuv/robinhood-ticker",
"main": "src/main.js",
"scripts": {
"prod-start": "NODE_ENV=production electron .",
"start": "NODE_ENV=development electron .",
"build": "NODE_ENV=production cp -r src/styles lib && cp -r src/utils lib && cp -r src/views lib && babel src --out-dir lib --ignore utils",
"prod-start": "cross-env NODE_ENV=production electron .",
"start": "cross-env NODE_ENV=development electron .",
"build": "cross-env NODE_ENV=production cp -r src/styles lib && cp -r src/utils lib && cp -r src/views lib && babel src --out-dir lib --ignore utils",
"build-watch": "cp -r src/styles lib && cp -r src/utils lib && cp -r src/views lib && babel src --out-dir lib --ignore utils --watch",
"debug": "NODE_ENV=development electron --inspect=5858 .",
"pack": "NODE_ENV=production electron-builder --dir",
"dist": "NODE_ENV=production electron-builder",
"publish": "NODE_ENV=production build -p always"
"debug": "cross-env NODE_ENV=development electron --inspect=5858 .",
"pack": "cross-env NODE_ENV=production electron-builder --dir",
"dist": "cross-env NODE_ENV=production electron-builder",
"publish": "cross-env NODE_ENV=production build -p always"
},
"keywords": [
"Robinhood"
Expand All @@ -28,22 +28,28 @@
},
"dmg": {
"background": "build/background.png"
},
"win": {
"target": "nsis",
"icon": "build/icon-512.png",
"legalTrademarks": "Copyright Jerry Tsui, 2018"
}
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-env": "^1.7.0",
"babel-preset-minify": "^0.4.1",
"babel-preset-stage-0": "^6.24.1",
"cross-env": "^5.2.0",
"devtron": "^1.4.0",
"electron": "^1.8.4",
"electron-builder": "^19.55.2",
"electron-builder-squirrel-windows": "^20.2.0",
"electron": "^1.8.7",
"electron-builder": "^19.56.2",
"electron-builder-squirrel-windows": "^20.22.0",
"electron-debug": "^1.5.0",
"electron-reload": "^1.2.2",
"electron-reload": "^1.2.5",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.11.0",
"nodemon": "^1.14.11"
"nodemon": "^1.18.2"
},
"dependencies": {
"about-window": "^1.9.1",
Expand All @@ -54,13 +60,13 @@
"babel-register": "^6.26.0",
"chartist": "^0.11.0",
"chartist-plugin-tooltip": "0.0.11",
"electron-log": "^2.2.14",
"electron-log": "^2.2.16",
"electron-store": "^1.3.0",
"electron-updater": "^2.20.1",
"install": "^0.11.0",
"menubar": "^5.2.3",
"moment-timezone": "^0.5.14",
"moment-timezone": "^0.5.21",
"node-fetch": "^1.7.3",
"query-string": "^5.1.0"
"query-string": "^5.1.1"
}
}
101 changes: 58 additions & 43 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ const {
Menu,
session,
ipcMain,
dialog,
Notification,
} = require('electron');
const os = require('os');
const AutoLaunch = require('auto-launch');
const fetch = require('node-fetch');
const path = require('path');
const url = require('url');
const openAboutWindow = require('about-window');
const openAboutWindow = require('about-window').default;
console.log(openAboutWindow);
const menubar = require('menubar');
const Store = require('electron-store');
const log = require('electron-log');
const {
appUpdater
} = require('./app-updater');
const notificationMapper = require('./notification-mapper');
const {
timeout,
Expand All @@ -31,7 +28,7 @@ const StockAPI = require('./StockAPI');
const store = new Store();

const ICON_LOGO_LARGE = path.join(__dirname, '../assets/logo-512.png');
const ICON_LOGO = path.join(__dirname, '../assets/logo-16.png');
const ICON_LOGO = path.join(__dirname, os.platform() === 'darwin' ? '../assets/logo-16.png' : '../assets/logo-16-white.png');
const ELECTRON_PATH = path.join(__dirname, '../node_modules/electron');

const TIMEOUT_MS = 5000;
Expand Down Expand Up @@ -121,13 +118,12 @@ ipcMain.on('chart', (event, data) => {
symbol,
tabIndex
} = data;
console.log(data);
createStockWindow(symbol, tabIndex);
});

ipcMain.on('logout', async (event, arg) => {
ipcMain.on('logout', async () => {
try {
const res = await fetchWithAuth(
await fetchWithAuth(
'https://api.robinhood.com/api-token-logout/', {
method: 'POST',
Accept: 'application/json'
Expand Down Expand Up @@ -162,9 +158,7 @@ ipcMain.on('manual-refresh', async (event, arg) => {
}
});

ipcMain.on('app-quit', (event, arg) => {
app.quit();
});
ipcMain.on('app-quit', () => app.quit());

ipcMain.on('show-about', (event, arg) => {
openAboutWindow({
Expand Down Expand Up @@ -253,25 +247,25 @@ const refreshPositions = async accountNumber => {
if (res.ok) {
const transformed = await Promise.all(
json.results
.filter(result => Number(result.quantity) !== 0)
.map(async result => {
const instrument = await (await fetchWithAuth(
decodeURIComponent(result.instrument)
)).json();
const quote = await (await fetchWithAuth(
decodeURIComponent(instrument.quote)
)).json();
return {
averageBuyPrice: result.average_buy_price,
instrument: result.instrument,
quantity: Number(result.quantity),
quote: quote,
currentPrice: quote.last_traded_price,
symbol: instrument.symbol,
name: instrument.name,
instrument: instrument
};
})
.filter(result => Number(result.quantity) !== 0)
.map(async result => {
const instrument = await (await fetchWithAuth(
decodeURIComponent(result.instrument)
)).json();
const quote = await (await fetchWithAuth(
decodeURIComponent(instrument.quote)
)).json();
return {
averageBuyPrice: result.average_buy_price,
instrument: result.instrument,
quantity: Number(result.quantity),
quote: quote,
currentPrice: quote.last_traded_price,
symbol: instrument.symbol,
name: instrument.name,
instrument: instrument
};
})
);
RobinHoodAPI._positions = transformed;
} else {
Expand All @@ -295,6 +289,7 @@ const refreshPortfolio = async accountNumber => {
if (res.ok) {
RobinHoodAPI._portfolio = json;
} else {
console.log(res);
throw new Error('Could not retrieve portfolio');
}
} catch (e) {
Expand Down Expand Up @@ -345,16 +340,30 @@ const refreshWatchlist = async () => {

// The login window.
const createLoginWindow = () => {
return new BrowserWindow({
width: 300,
height: 450,
const defaultOpts = {
backgroundColor: '#61CA9D',
center: true,
title: 'RobinHood Ticker',
resizable: false,
titleBarStyle: 'hidden',
show: false
});
show: false,
};

if (os.platform() === 'darwin') {
// Mac
return new BrowserWindow(Object.assign({
width: 300,
height: 450,
}, defaultOpts));
} else {
// Windows
return new BrowserWindow(Object.assign({
width: 325,
height: 500,
frame: false,
}, defaultOpts));
}

};

// To be displayed if the user has not authenticated yet
Expand Down Expand Up @@ -382,9 +391,9 @@ const createLoginMenu = () => {
template.push({
type: 'separator'
}, {
label: 'Quit',
click: () => app.quit()
});
label: 'Quit',
click: () => app.quit()
});
return Menu.buildFromTemplate(template);
};

Expand Down Expand Up @@ -479,7 +488,9 @@ const createPreferencesWindow = () => {
const isAuthenticated = () => (store.get('data') ? true : false);

const initializeApp = () => {
app.dock.hide();
if (os.platform() === 'darwin') {
app.dock.hide();
}

const autoLaunch = new AutoLaunch({
name: 'RH-Ticker',
Expand All @@ -505,7 +516,8 @@ const initializeApp = () => {
store.set('preferences', {
refreshRate: 1,
viewChangeBy: 'gain/loss',
viewEquityBy: 'total-equity'
viewEquityBy: 'total-equity',
percent: 2,
});
}

Expand Down Expand Up @@ -564,7 +576,7 @@ const initializeApp = () => {
mb.window.webContents.once('did-frame-finish-load', () => {
/* Check for auto updates */
if (process.platform === 'darwin') {
appUpdater();
// appUpdater();
}
});

Expand All @@ -573,6 +585,9 @@ const initializeApp = () => {
console.log('not authenticated');
contextMenu = createLoginMenu();
tray.setContextMenu(contextMenu);
if (process.platform === 'win32') {
tray.on('click', () => tray.popUpContextMenu());
}
}

// Emitted when the window is closed.
Expand Down
1 change: 1 addition & 0 deletions src/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ button {
input {
font-family: 'Din-Light';
letter-spacing: 0.05em;
-webkit-app-region: no-drag;
}

#backdrop {
Expand Down
2 changes: 1 addition & 1 deletion src/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div id="backdrop">
</div>
<div id="login-container">
<input type="text" placeholder="USERNAME" id="username" value="" />
<input type="text" placeholder="USERNAME" id="username" value="" autofocus/>
<input type="password" placeholder="PASSWORD" id="password" value="" />

</div>
Expand Down
10 changes: 6 additions & 4 deletions src/views/menubar.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@
const animation = el.animate([{
transform: `translateY(${height}px)`
}], {
duration: 50,
fill: 'forwards',
easing: 'ease-in',
});
duration: 50,
fill: 'forwards',
easing: 'ease-in',
});
animation.direction = height >= 0 ? 'down' : 'up';
return animation;
}
Expand Down Expand Up @@ -393,6 +393,7 @@
/* Helper function called when data comes in from IPC. If positionsIndices, watchlistIndices == null, then
we ignore.*/
function sortData(messageData) {
console.log('messagedata', messageData);
if (positionsIndices !== null && positionsIndices.length === messageData._positions.length) {
const sortedPositions = new Array(messageData._positions.length);
messageData._positions.forEach((position) => {
Expand Down Expand Up @@ -536,6 +537,7 @@
}

fragment = document.createDocumentFragment();
console.log(data);
data._watchlist.forEach((quote) => {
// for (let position of data._positions) {
// if (position.symbol === quote.symbol) {
Expand Down

0 comments on commit 915c51e

Please sign in to comment.