Node-Webkit Ctrl-plus and Ctrl-minus - node-webkit

How do i make node-webkit (NW) accept Ctrl++ and Ctrl+- as shortcuts?
I have tried:
Ctrl++
Ctrl+Plus
Ctrl+Plus
Ctrl+Minus
Ctrl+-
Ctrl+minus
but it doesn't work. Every time it gives me a fail message.
Here is my current code:
var option = {
key : "Ctrl+plus",
active : function() {
console.log("Global desktop keyboard shortcut: " + this.key + " active.");
},
failed : function(msg) {
console.log(msg);
}
};enter code here
var shortcut = new nw.Shortcut(option);
nw.App.registerGlobalHotKey(shortcut);

I had to do something similar and ended up using JS:
$(window).keypress(function(event) {
if (!(event.which == 61)) return true;
# 61 is ctrl + plus on Mac, probably different on windows
alert("Ctrl-plus pressed");
event.preventDefault();
return false;
});

Related

nightwatch - still can't switch to the other window

The example from github doesn't work for me.
https://github.com/nightwatchjs/nightwatch/issues/369
This is my code.
When('I open a new browser window', () => {
var host = 'http://www.google.com';
client
.windowHandle(function(wh){console.log(wh.value)})
.url(host)
.waitForElementVisible('#hplogo', 1000)
.execute(function(newWindow){
window.open('http://www.twitter.com', null, "height=1024,width=768");
}, [host])
.assert.urlContains('google')
.window_handles(function(result) {
var temp = result.value[1];
this.switchWindow(temp);
})
.windowHandle(function(wh){console.log(wh.value)})
.assert.urlContains('twitter')
.end();
});
Both console.log before and after .switchWindow print out the same string.
Does anyone have any ideas please...?
EDIT
I've changed the code a bit taking into account what pcalkins said.
This is the code now:
When('I open a new browser window', () => {
var host = 'http://www.google.com';
client
.windowHandle(function(wh){console.log("\nBEFORE: " + wh.value)})
.url(host)
.waitForElementVisible('#hplogo', 1000)
.execute(function(newWindow){
window.open('http://www.twitter.com', null, "height=1024,width=768");
}, [host])
.pause(3000)
.window_handles(function(result) {
console.log("\n\nHANDLE: " + result.value + "\n");
var temp = result.value[0];
this.switchWindow(temp);
console.log("\n\ntemp0: " + temp + "\n");
temp = result.value[1];
this.switchWindow(temp);
console.log("\n\ntemp1: " + temp + "\n");
})
.pause(2000);
});
When run, this is the result:
BEFORE is the handle for the original window.
HANDLE is both windows.
temp0 and temp1 are the two different windows in sequence. Clearly temp1 is the window I want, and yet the final this.switchWindow is not doing its job.
AFTER is the current window handle at the next test step.

switchWindow does not work in IE

switchWindow does not work in IE
this.browser.windowHandles(function (result) {
var newWindow;
if (result.value.length > 1) {
this.browser.verify.equal(result.value.length, 2, 'There should be 2 windows open');
newWindow = result.value[1];
this.browser.switchWindow(newWindow)
.pause(1000, function() { // wait to load the 2nd window completly.
if(self.isInternetExplorer && self.isWin81){
self.browser.pause(20000);//IE on win 8.1 is slower
}
});
}
this.browser.waitForUrlToContain(rstl, true, 90000, function (doesIt, url) {
console.log(url);
this.browser.assert.ok(doesIt, 'URL ' + url + ' does not contain ' + rstl);
if(callback){
callback(this.browser, isFirstLogin, extraCallbackValues);
}
}.bind(this));
if (result.value.length > 1) {
this.browser.closeWindow();
this.browser.switchWindow(result.value[0]);
} else {
this.browser.back();
}
}.bind(this));
I have the code above. For some reason, switchWindow function is not working in IE. Is there an alternative?

JSON store hangs while retrieving data

We have observed that at certain times accessing the JSONStore API's hangs for long time, to make it work we have to call the function again or app has to be taken to background & bring to foreground again.
NOTE : when application faces this issue, behaviour is same until we reinstall the app or reboot the device.
There doesn't appear to be any proper scenarios for this, we have searched many articles but did not find any solution, any solutions are welcome.
We observed this issue on Android devices like S5 and S4.
Here is my code Snippet:
function getWidgets(w_id, getWidgetsSuccessCallback, getWidgetsFailureCallback) {
var query = { user_id : w_id };
var options = {};
WL.JSONStore.get(StorageCollections.widgets).find(query, options)
.then(function(arrayResults) {
var count = arrayResults.length;
Logger.debug("getWidgets: success, count: " + count);
...
getWidgetsSuccessCallback(widgets);
})
.fail(function(errorObject) {
Logger.error("getWidgets: failed, error: " + JSON.stringify(errorObject));
getWidgetsFailureCallback(errorObject);
});}
Logs when everything works fine http://pastebin.com/NVP8ycTG
Logs when accessing JSON store hangs, it will work only when app taken to background & bring back to foreground again http://pastebin.com/eYzx57qC
JSON store is initialised as below
var collections = {
// User
user: {
searchFields: {
user_id : 'string',
user_name : 'string',
first_name : 'string',
last_name : 'string',
}
}
}};
// Storage encryption
var options = {};
if (key) {
options.password = key;
options.localKeyGen = true;
}
// Open the collection
var promise = WL.JSONStore.init(collections, options)
.then(function() {
Logger.debug("initializeAppStorage: " + JSON.stringify(collections) + " completed");
initAppStorageSuccessCallback(true);
return true;
})
// Handle failure
.fail(function(errorObject) {
Logger.error("initializeAppStorage: failed, error: " + errorObject.toString());
initAppStorageFailureCallback(errorObject.toString());
return false;
});
return promise;
Thanks.
Try this one :
function getWidgets(w_id, getWidgetsSuccessCallback, getWidgetsFailureCallback) {
var query = { key : w_id };
var options = {};
WL.JSONStore.get(StorageCollections.widgets).find(query, options)
.then(function(arrayResults) {
var count = arrayResults.length;
Logger.debug("getWidgets: success, count: " + count);
...
getWidgetsSuccessCallback(widgets);
})
.fail(function(errorObject) {
Logger.error("getWidgets: failed, error: " + JSON.stringify(errorObject));
getWidgetsFailureCallback(errorObject);
});}

Is it possible to update text message in WL.BusyIndicator?

I create a new WL.BusyIndicator via this code just before I start a long running process...
if (gblShowBusyIndicator) {
busyIndicator = new WL.BusyIndicator('loader',
{text: 'Refreshing local sales data...',
opacity: 0.85,
fullScreen: true});
busyIndicator.show();
}
Is it possible to update the "text" parameter intermittently during that process? I tried calling this function, but it didn't work. Any ideas?
function setBusyIndicatorStatus(status) {
try {
if (busyIndicator.isVisible()) {
busyIndicator({text: status});
}
} catch (e) {
if (gblLoggerOn) WL.Logger.debug(">> setBusyIndicatorStatus(" + status + ") failure... discarding");
}
}
After some additional thought, here's how I solved the problem, but I'd like to know if there's a better way than toggling show/hide w different status messages at certain points in my code.
Thanks!
function setBusyIndicatorStatus(view, status) {
if (gblLoggerOn) WL.Logger.debug(">> setBusyIndicatorStatus(" + view + ", " + status + ")");
try {
if (busyIndicator.isVisible()) busyIndicator.hide();
} catch (e) {
if (gblLoggerOn) WL.Logger.debug(">> setBusyIndicatorStatus(" + view + ", " + status + ") failure... discarding");
}
busyIndicator = null;
var options = {text: null, opacity: 0.85, fullScreen: true};
options.text = status;
busyIndicator = new WL.BusyIndicator(view, options);
busyIndicator.show();
}

PhantomJS not returning results

I'm testing out PhantomJS and trying to return all startups listed on angel.co. I decided to go with PhantomJS since I would need to paginate through the front page by clicking "Next" at the bottom. Right now this code does not return any results. I'm completely new to PhantomJS and have read through all the code examples so any guidance would be much appreciated.
var page = require('webpage').create();
page.open('https://angel.co/startups', function(status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
page.evaluate(function() {
var list = document.querySelectorAll('div.resume');
for (var i = 0; i < list.length; i++){
console.log((i + 1) + ":" + list[i].innerText);
}
});
}
phantom.exit();
});
By default, console messages evaluated on the page will not appear in your PhantomJS console.
When you execute code under page.evaluate(...), that code is being executed in the context of the page. So when you have console.log((i + 1) + ":" + list[i].innerText);, that is being logged in the headless browser itself, rather than in PhantomJS.
If you want all console messages to be passed along to PhantomJS itself, use the following after opening your page:
page.onConsoleMessage = function (msg) { console.log(msg); };
page.onConsoleMessage is triggered whenever you print to the console from within the page. With this callback, you're asking PhantomJS to echo the message to its own standard output stream.
For reference, your final code would look like (this prints successfully for me):
var page = require('webpage').create();
page.open('https://angel.co/startups', function(status) {
page.onConsoleMessage = function (msg) { console.log(msg); };
if (status !== 'success') {
console.log('Unable to access network');
} else {
page.evaluate(function() {
var list = document.querySelectorAll('div.resume');
for (var i = 0; i < list.length; i++){
console.log((i + 1) + ":" + list[i].innerText);
}
});
}
phantom.exit();
});