Skip to content

Commit

Permalink
Merge pull request #35 from dryabov/master
Browse files Browse the repository at this point in the history
twister-core 0.9.25
  • Loading branch information
dryabov committed Sep 3, 2014
2 parents 32bac67 + e8e2ecb commit b047eae
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 99 deletions.
241 changes: 193 additions & 48 deletions Gruntfile.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion app/js/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
*/
win.setWaitCursor = function (wait) {
var doc = window.getIframeDocument();
if (doc) {
if (doc && doc.body) {
doc.body.style.cursor = wait ? 'progress' : '';
}
};
Expand All @@ -162,6 +162,8 @@

if (confirm(msg)) {
twister.restart(win.onTwisterStart);
} else {
win.close();
}
});

Expand Down
9 changes: 8 additions & 1 deletion app/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @property twisterdPath
* @property twisterdDatadir
* @property proxy
* @property twisterNodes
*/
window.Settings = function () {
var that = this;
Expand All @@ -39,7 +40,13 @@ window.Settings = function () {
rpcPassword: '',
twisterdPath: '',
twisterdDatadir: '',
proxy: ''
proxy: '',
twisterNodes: [
'seed3.twister.net.co',
'seed2.twister.net.co',
'seed.twister.net.co',
'dnsseed.gombadi.com'
]
};

var fileSettings = appDir + ds + 'settings.ini';
Expand Down
3 changes: 3 additions & 0 deletions app/js/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ window.addEventListener('init', function () {
}
}
settings.theme = theme;
if (window.$ && window.$.localStorage) {
window.$.localStorage.set('options:theme', theme);
}
win.updateTheme();
}
}));
Expand Down
47 changes: 23 additions & 24 deletions app/js/twister.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,29 @@ window.Twister = function () {

function getDefaultDataDir() {
if (isMac) {
return process.env.HOME + '/.twister';
return process.env.HOME + '/Library/Application Support/Twister';
} else {
return process.env.HOME + ds + '.twister';
}
}

var isCygwin = false;
function escapePath(path) {
if (isWin32) {
path = path.split(':');
if (path[1]) {
path = '/cygdrive/' + path[0].toLowerCase() + path[1].replace(/\\/g, '/');
if (isCygwin) {
// Cygwin escaping
path = path.split(':');
if (path[1]) {
path = '/cygdrive/' + path[0].toLowerCase() + path[1].replace(/\\/g, '/');
} else {
path = path[0].replace(/\\/g, '/')
}
} else {
path = path[0].replace(/\\/g, '/')
// MinGW escaping
path = path.replace(/\//g, '\\').replace(/([()%!^"<>&|;, ])/g, '^$1');
}
} else {
path = path.replace(/ /g, '\\ ');
path = path.replace(/[^a-zA-Z0-9_]/g, '\\$1');
}
return path;
}
Expand Down Expand Up @@ -63,12 +70,6 @@ window.Twister = function () {
var that = this,
twisterd_themes_dir = './html',
twisterd_args_common = [],
twisterNodes = [
'seed3.twister.net.co',
'seed2.twister.net.co',
'seed.twister.net.co',
'dnsseed.gombadi.com'
],
curNodeIndex = Infinity,
childDaemon = null,
checkRunningId = 0,
Expand Down Expand Up @@ -99,7 +100,7 @@ window.Twister = function () {
} catch (e) {
console.log(e);
}
copyRecursiveSync(appDir + ds + 'data', settings.twisterdDatadir);
copyRecursiveSync(appDir + ds + 'bootstrap', settings.twisterdDatadir);
}
} catch (e) {
console.log(e);
Expand Down Expand Up @@ -182,20 +183,17 @@ window.Twister = function () {
}

childDaemon = rpcCall(twisterd_args_daemon, function (error) {
childDaemon = null;
if (error && error.killed === true) {
win.emit('twisterstop');
childDaemon = null;
return;
}
if (!isTwisterdOn) {
} else if (!isTwisterdOn && !isStop) {
var event = new CustomEvent('twisterfail');
event.error = {
message: error.message,
code: error.code
};
window.dispatchEvent(event);
}
childDaemon = null;
});

waitTwisterStart(callback);
Expand All @@ -207,7 +205,7 @@ window.Twister = function () {
*/
this.tryStart = function (callback) {
if (checkRunningId) {
clearInterval();
clearInterval(checkRunningId);
checkRunningId = 0;
}

Expand Down Expand Up @@ -243,12 +241,13 @@ window.Twister = function () {
win.removeAllListeners('twisterstop');
});

rpcCall(['stop'], function () {
rpcCall(['stop'], function (error) {
if (childDaemon) {
childDaemon.stdout.destroy();
childDaemon.stderr.destroy();
childDaemon.unref();
}
curNodeIndex = Infinity;
setTimeout(function () {
if (childDaemon) {
try {
Expand Down Expand Up @@ -296,8 +295,8 @@ window.Twister = function () {
*/
function loopAddNodes() {
setTimeout(function () {
if (curNodeIndex < twisterNodes.length) {
addNode(twisterNodes[curNodeIndex++]);
if (curNodeIndex < settings.twisterNodes.length) {
addNode(settings.twisterNodes[curNodeIndex++]);
loopAddNodes();
}
}, addNodeInterval);
Expand Down Expand Up @@ -352,7 +351,7 @@ window.Twister = function () {
*/
this.isWorking = function (callback) {
var req = new XMLHttpRequest();
req.open('GET', 'http://' + settings.rpcHost + ':' + settings.rpcPort + '/empty.html');
req.open('POST', 'http://' + settings.rpcHost + ':' + settings.rpcPort + '/empty.html');
req.timeout = rpcCheckTimeout;
req.withCredentials = true;
req.setRequestHeader('Authorization', 'Basic ' + btoa(settings.rpcUser + ':' + settings.rpcPassword));
Expand Down Expand Up @@ -391,4 +390,4 @@ window.Twister = function () {
var isWorking = isRunning();
window.dispatchEvent(new CustomEvent(isWorking ? 'twisterrun' : 'twisterdie'));
}
};
};
41 changes: 23 additions & 18 deletions app/js/winstate.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
'use strict';

/**
* Cross-platform window state preservation.
* Yes this code is quite complicated, but this is the best I came up with for
* current state of node-webkit Window API (v0.7.3 and later).
*
* Known issues:
* - unmaximization not always sets the window (x, y) in the lastly used coordinates
* - unmaximization animation sometimes looks wierd
* - extra height added to window, at least in linux x64 gnome-shell env. It seems that
* - Unmaximization not always sets the window (x, y) in the lastly used coordinates.
* - Unmaximization animation sometimes looks wierd.
* - Extra height added to window, at least in linux x64 gnome-shell env. It seems that
* when we read height then it returns it with window frame, but if we resize window
* then it applies dimensions only to internal document without external frame.
* Need to test in other environments with different visual themes.
*
* Change log:
* 2013.12.01
* - workaround of extra height in gnome-shell added
* 2013-12-01
* - Workaround of extra height in gnome-shell added.
*
* 2014-03-22
* - Repared workaround (from 2013-12-01) behaviour when use frameless window.
* Now it works correctly.
*/

(function () {
// var gui = require('nw.gui');
// var win = gui.Window.get();
//var gui = require('nw.gui');
//var win = gui.Window.get();
var winState;
var currWinMode;
var resizeTimeout;
var isMaximizationEvent = false;
var defaultWidth = 917;
var defaultHeight = 600;
var minHeight = 240;

// extra height added in linux x64 gnome-shell env, use it as workaround
var deltaHeight = false;
// extra height added in linux x64 gnome-shell env, use it as workaround
var deltaHeight = (function () {
// use deltaHeight only in windows with frame enabled
if (gui.App.manifest.window.frame) return true; else return 'disabled';
})();


function initWindowState() {
Expand All @@ -43,7 +50,7 @@
}
} else {
currWinMode = 'normal';
deltaHeight = 0;
if (deltaHeight !== 'disabled') deltaHeight = 0;
win.resizeTo(defaultWidth, defaultHeight);
dumpWindowState();
}
Expand Down Expand Up @@ -72,20 +79,20 @@
winState.height = win.height;

// save delta only of it is not zero
if (deltaHeight !== 0 && currWinMode !== 'maximized') {
if (deltaHeight !== 'disabled') {
winState.deltaHeight = deltaHeight;
}
}
}

function restoreWindowState() {
// deltaHeight already saved, so just restore it and adjust window height
if (typeof winState.deltaHeight !== 'undefined') {
if (deltaHeight !== 'disabled' && typeof winState.deltaHeight !== 'undefined') {
deltaHeight = winState.deltaHeight;
winState.height = winState.height - deltaHeight;
}

win.resizeTo(winState.width, winState.height);
win.resizeTo(winState.width, Math.max(winState.height, minHeight));
win.moveTo(winState.x, winState.y);
}

Expand Down Expand Up @@ -131,7 +138,7 @@
}

// there is no deltaHeight yet, calculate it and adjust window size
if (deltaHeight === false) {
if (deltaHeight !== 'disabled' && deltaHeight === false) {
deltaHeight = win.height - winState.height;

// set correct size
Expand All @@ -147,9 +154,7 @@

win.on('close', function () {
saveWindowState();
// setTimeout(function () {
// this.close(true);
// }, 50);
//this.close(true);
});

})();
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"main": "index.html",
"name": "twister",
"version": "0.9.22.0",
"version": "0.9.25.0",
"description": "P2P microbloging system",
"chromium-args": "--auth-schemes='basic'",
"window": {
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twister",
"version": "0.9.22",
"version": "0.9.25",
"description": "P2P microbloging system",
"licenses": [
{
Expand All @@ -24,13 +24,13 @@
"dependencies": {},
"devDependencies": {
"grunt-cli": "~0.1.13",
"grunt": "~0.4.3",
"grunt-contrib-clean": "~0.5.0",
"grunt": "~0.4.5",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-compress": "https://github.com/dryabov/grunt-contrib-compress/tarball/39ad2e2a5af4531ef39ebd31bef7ceb05241336c",
"grunt-contrib-copy": "~0.5.0",
"grunt-exec": "~0.4.5",
"grunt-node-webkit-builder": "~0.1.17",
"grunt-zip": "~0.13.0",
"grunt-exec": "~0.4.6",
"grunt-node-webkit-builder": "~0.2.0",
"grunt-zip": "~0.16.0",
"grunt-curl": "~2.0.2"
},
"devDependenciesBackup": {
Expand Down

0 comments on commit b047eae

Please # to comment.