Skip to content

Commit

Permalink
Refactor, remove unecessary code and add small UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Spl3en committed Mar 17, 2019
1 parent 7d32a01 commit 8cccc90
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 2,238 deletions.
83 changes: 4 additions & 79 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const { app, dialog, Tray, Menu } = require('electron');
const { app, Tray, Menu } = require('electron');
const path = require('path');
const fs = require('fs');
const url = require('url');
const https = require('https');
const platform = require('os').platform();
const crypto = require('crypto');
const Store = require('electron-store');
const settings = new Store({ name: 'Settings' });
const log = require('electron-log');
Expand All @@ -15,32 +13,12 @@ const IS_DEV = (process.argv[1] === 'dev' || process.argv[2] === 'dev');
const IS_DEBUG = IS_DEV || process.argv[1] === 'debug' || process.argv[2] === 'debug';
const LOG_LEVEL = IS_DEBUG ? 'debug' : 'warn';
const WALLET_CFGFILE = path.join(app.getPath('userData'), 'wconfig.txt');

const SVALINN_VERSION = app.getVersion() || '0.3.x';
const SERVICE_FILENAME = (platform === 'win32' ? `${config.walletServiceBinaryFilename}.exe` : config.walletServiceBinaryFilename);
const SERVICE_OSDIR = (platform === 'win32' ? 'win' : (platform === 'darwin' ? 'osx' : 'lin'));
const DEFAULT_SERVICE_BIN = path.join(process.resourcesPath, 'bin', SERVICE_OSDIR, SERVICE_FILENAME);

const DEFAULT_REMOTE_NODE = config.remoteNodeListFallback
.map((a) => ({ sort: Math.random(), value: a }))
.sort((a, b) => a.sort - b.sort)
.map((a) => a.value)[0];
const SVALINN_VERSION = app.getVersion();

const DEFAULT_SETTINGS = {
service_bin: DEFAULT_SERVICE_BIN,
service_host: '127.0.0.1',
service_port: config.walletServiceRpcPort,
service_password: 'passwrd',
service_timeout: 10,
node_address: DEFAULT_REMOTE_NODE,
pubnodes_last_updated: 946697799000,
pubnodes_data: config.remoteNodeListFallback,
pubnodes_custom: ['127.0.0.1:11898'],
pubnodes_exclude_offline: false,
tray_minimize: false,
tray_close: false,
darkmode: false,
service_config_format: config.walletServiceConfigFormat
};
const DEFAULT_SIZE = { width: 840, height: 840 };
const WIN_TITLE = `${config.appName} ${SVALINN_VERSION} - ${config.appDescription}`;
Expand All @@ -50,7 +28,6 @@ app.prompShown = false;
app.needToExit = false;
app.debug = IS_DEBUG;
app.walletConfig = WALLET_CFGFILE;
app.publicNodesUpdated = false;
app.setAppUserModelId(config.appId);

log.transports.console.level = LOG_LEVEL;
Expand All @@ -65,7 +42,8 @@ let trayIconHide = path.join(__dirname, 'src/assets/trayon.png');
let win;
let tray;

function createWindow() {
function createWindow()
{
// Create the browser window.
let darkmode = settings.get('darkmode', false);
let bgColor = darkmode ? '#000000' : '#02853E';
Expand Down Expand Up @@ -152,7 +130,6 @@ function createWindow() {
tray.setToolTip(config.appSlogan);
tray.setContextMenu(contextMenu);


tray.on('click', () => {
if(!win.isFocused() && win.isVisible()){
win.focus();
Expand Down Expand Up @@ -231,59 +208,13 @@ function createWindow() {
});
}

function serviceBinCheck() {
/*
if (DEFAULT_SERVICE_BIN.startsWith('/tmp')) {
log.warn(`AppImage env, copying service bin file`);
let targetPath = path.join(app.getPath('userData'), SERVICE_FILENAME);
try {
fs.renameSync(targetPath, `${targetPath}.bak`, (err) => {
if (err) log.error(err);
});
} catch (_e) { }
try {
fs.copyFile(DEFAULT_SERVICE_BIN, targetPath, (err) => {
if (err) {
log.error(err);
return;
}
settings.set('service_bin', targetPath);
log.debug(`service binary copied to ${targetPath}`);
});
} catch (_e) { }
} else {
// don't trust user's settings, recheck
let svcbin = settings.get('service_bin');
try{
if(!fs.existsSync(svcbin)){
log.warn(`Service binary can't be found, falling back to default`);
settings.set('service_bin', DEFAULT_SERVICE_BIN);
}else{
log.info('Service binary found');
}
}catch(_e) {
log.warn('Failed to check for service binary path, falling back to default');
settings.set('service_bin', DEFAULT_SERVICE_BIN);
}
}
*/
}

function initSettings() {
Object.keys(DEFAULT_SETTINGS).forEach((k) => {
if (!settings.has(k) || settings.get(k) === null) {
settings.set(k, DEFAULT_SETTINGS[k]);
}
});
settings.set('service_password', crypto.randomBytes(32).toString('hex'));
settings.set('version', SVALINN_VERSION);
// serviceBinCheck();
/*
fs.unlink(WALLET_CFGFILE, (err) => {
if (err) log.debug(err.code === 'ENOENT' ? 'No stalled wallet config' : err.message);
});
*/
}

app.on('browser-window-created', function (e, window) {
Expand Down Expand Up @@ -343,10 +274,4 @@ app.on('ready', () => {
if (tx > 0 && ty > 0) {
try { win.setPosition(parseInt(tx, 10), parseInt(ty, 10)); } catch (_e) { }
}

// remove old settings cruft if exist
setTimeout(() => {
try { settings.delete('pubnodes_checked'); } catch (e) { }
try { settings.delete('pubnodes_date'); } catch (e) { }
}, 2500);
});
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "svalinn",
"productName": "Svalinn",
"description": "ICONation ICX Wallet",
"version": "0.1.5",
"version": "0.1.6",
"homepage": "https://github.com/ICONation/svalinn",
"repository": "https://github.com/ICONation/svalinn",
"main": "main.js",
Expand Down Expand Up @@ -37,7 +37,9 @@
"node-crypto-gcm": "^1.0.3",
"qr-image": "^3.2.0",
"request": "^2.88.0",
"request-promise-native": "^1.0.7"
"request-promise-native": "^1.0.7",
"shell": "^0.5.0",
"superagent": "^4.1.0"
},
"build": {
"appId": "org.iconation.svalinn",
Expand Down
4 changes: 4 additions & 0 deletions src/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,10 @@ h4.input-required:after{
text-shadow: 1px 1px 1px #000;
}

.dont-color-link {
color : inherit;
}

.help-hl{
color: rgba(255,255,255,1.0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/html/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="about-content-hur">
<div class="about-content-logo">
<div class="about-logo">
<p>Svalinn <span id="svalinnVersion">0.3.2</span></p>
<p>Svalinn <span id="svalinnVersion"></span></p>
<img src="../assets/splash_logo.png" class="ab" />
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions src/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<link rel="stylesheet" href="../css/ag-theme-balham-dark.css">
<!-- HTML pages (each page contains a section) -->
<link rel="import" href="./about.html">
<link rel="import" href="./settings.html">
<link rel="import" href="./create_transaction.html">
<link rel="import" href="./send_transaction.html">
<link rel="import" href="./welcome.html">
Expand Down Expand Up @@ -60,7 +59,7 @@
<div class="side-buttons">
<button tabindex="-1" class="side-button" title="About" id="button-section-about"><i class="fas fa-info-circle"></i></button>
<button tabindex="-1" class="side-button" title="Show keyboard shortcut" id="kswitch"><i class="fas fa-keyboard"></i></button>
<button tabindex="-1" class="side-button" title="Swith to dark mode" id="tswitch"><i class="fas fa-moon"></i></button>
<button tabindex="-1" class="side-button" title="Switch to dark mode" id="tswitch"><i class="fas fa-moon"></i></button>
</div>
<div id="belekok" class="borokokok off"></div>
<script>require('../js/wsui_main.js')</script>
Expand Down
8 changes: 4 additions & 4 deletions src/html/send_transaction.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ <h4 class="text-spaced input-required">Select the transaction file</h4>
<span class="form-ew form-msg text-spaced-success" id="text-send-transaction-success"></span>
</div>

<div class="input-wrap" id="send-transaction-hidden-txhash">
<h4 class="text-spaced">Transaction Hash:</h2>
<textarea title="click to copy" data-cplabel="Transaction Hash" data-hidden="1" class="ctcl overview-input default-textarea"
id="send-transaction-txhash" readonly="readonly" rows="2"></textarea>
<div class="input-wrap hideme" id="send-transaction-hidden-txhash">
<h4 class="text-spaced">Transaction Hash:</h4>
<span title="Click to see the transaction on the tracker" data-cplabel="Transaction Hash"
id="send-transaction-txhash" readonly="readonly" tabindex="0" class="text-block"></span>
</div>
</div>
<div class="action-buttons">
Expand Down
63 changes: 0 additions & 63 deletions src/html/settings.html

This file was deleted.

Loading

0 comments on commit 8cccc90

Please sign in to comment.