Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
v0.4 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveLong committed Apr 18, 2019
1 parent dd5ff79 commit e083cbd
Show file tree
Hide file tree
Showing 20 changed files with 613 additions and 460 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ tbin/*
.vscode/*
build/*
dist/*
bin/*
\.vs/plenteum-wallet-electron/v15/\.suo
\.vs/**
**/obj/**
bin/
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"boss" : false,
"debug" : false,
"eqnull" : false,
"esversion" : 6,
"esversion" : 7,
"moz" : false,
"evil" : false,
"expr" : false,
Expand Down
43 changes: 23 additions & 20 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const DEFAULT_SETTINGS = {
service_host: '127.0.0.1',
service_port: config.walletServiceRpcPort,
service_password: 'passwrd',
service_timeout: 30,
node_address: DEFAULT_REMOTE_NODE,
pubnodes_last_updated: 946697799000,
pubnodes_data: config.remoteNodeListFallback,
Expand Down Expand Up @@ -63,12 +64,9 @@ if (IS_DEV || IS_DEBUG) log.warn(`Running in ${IS_DEV ? 'dev' : 'debug'} mode`);
let trayIcon = path.join(__dirname, 'src/assets/tray.png');
let trayIconHide = path.join(__dirname, 'src/assets/trayon.png');

debug();

let win;
let tray;


function createWindow() {
// Create the browser window.
let darkmode = settings.get('darkmode', true);
Expand Down Expand Up @@ -174,9 +172,9 @@ function createWindow() {


tray.on('click', () => {
if(!win.isFocused() && win.isVisible()){
if (!win.isFocused() && win.isVisible()) {
win.focus();
}else if (settings.get('tray_minimize', false)) {
} else if (settings.get('tray_minimize', false)) {
if (win.isVisible()) {
win.hide();
} else {
Expand Down Expand Up @@ -252,15 +250,16 @@ function createWindow() {
}

function storeNodeList(pnodes) {
pnodes = pnodes || settings.get('pubnodes_data');
if(!pnodes) return;

if(!pnodes.length) return;

let validNodes = [];
if (pnodes.hasOwnProperty('nodes')) {
pnodes.nodes.forEach(addr => {
let item = `${addr.url}:${addr.port}`;
validNodes.push(item);
});
}
if (validNodes.length) settings.set('pubnodes_data', validNodes);
pnodes.forEach(node => {
let item = `${node.url}:${node.port}`;
validNodes.push(item);
});
settings.set('pubnodes_data', validNodes);
}

function doNodeListUpdate() {
Expand All @@ -276,13 +275,17 @@ function doNodeListUpdate() {
res.on('end', () => {
try {
var pnodes = JSON.parse(result);
if(pnodes.hasOwnProperty('nodes')) {
pnodes = pnodes.nodes;
}
storeNodeList(pnodes);
if(result.length) settings.set('pubnodes_raw', Buffer.from(result).toString('base64'));
settings.set('pubnodes_last_updated', new Date().getTime());
settings.delete('pubnodes_tested');
log.debug('Public node list has been updated');
} catch (e) {
log.debug(`Failed to update public node list: ${e.message}`);
storeNodeList();
storeNodeList(false);
}
});
}).on('error', (e) => {
Expand All @@ -299,11 +302,11 @@ function updatePublicNodes() {
if (config.remoteNodeListUpdateUrl) {
let last_updated = settings.get('pubnodes_last_updated', 946697799000);
let now = new Date().getTime();
if(Math.abs(now-last_updated) / 36e5 >= 24) {
if (Math.abs(now - last_updated) / 36e5 >= 24) {
//do update
log.info('Performing daily public-node list update.');
doNodeListUpdate();
}else{
} else {
log.info('Public node list up to date, skipping update');
storeNodeList(false); // from local cache
}
Expand Down Expand Up @@ -333,14 +336,14 @@ function serviceBinCheck() {
} else {
// don't trust user's settings, recheck
let svcbin = settings.get('service_bin');
try{
if(!fs.existsSync(svcbin)){
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{
} else {
log.info('Service binary found');
}
}catch(_e) {
} catch (_e) {
log.warn('Failed to check for service binary path, falling back to default');
settings.set('service_bin', DEFAULT_SERVICE_BIN);
}
Expand Down
Loading

0 comments on commit e083cbd

Please sign in to comment.