NativeImage not working in setOverlayIcon() in Electron - javascript

I'm trying to make a numeric badge for my app's taskbar icon (Windows 10). I've used this code as a starting point and modified it a bit. After creating the badge, I've used the following to set it in the renderer process:
var electron=require('electron'),
remote=electron.remote,
nativeImage=electron.nativeImage;
...
var win=remote.getCurrentWindow();
...
var badgeDataURL=canvas.toDataURL();
var img=nativeImage.createFromDataURL(badgeDataURL);
win.setOverlayIcon(img,''+n);
Running this gives me the following error:
Uncaught Error: Could not call remote function 'setOverlayIcon'. Check that the function signature is correct. Underlying error: Error processing argument at index 0, conversion failure from #<Object>
Error: Could not call remote function 'setOverlayIcon'. Check that the function signature is correct. Underlying error: Error processing argument at index 0, conversion failure from #<Object>
at callFunction (A:\electron\resources\electron.asar\browser\rpc-server.js:235:11)
at EventEmitter.<anonymous> (A:\electron\resources\electron.asar\browser\rpc-server.js:342:5)
at emitMany (events.js:127:13)
at EventEmitter.emit (events.js:201:7)
at WebContents.<anonymous> (A:\electron\resources\electron.asar\browser\api\web-contents.js:231:13)
at emitTwo (events.js:106:13)
at WebContents.emit (events.js:191:7)metaToValue # A:\electron\resources\electron.asar\renderer\api\remote.js:217remoteMemberFunction # A:\electron\resources\electron.asar\renderer\api\remote.js:113electronSetBadge # app.js:81updateBadge # app.js:156initClick # app.js:183(anonymous function) # app.js:203dispatch # jquery-1.12.4.min.js:3r.handle # jquery-1.12.4.min.js:3
I've tried the following:
different versions of Electron (1.4.13 and 1.2.8)
testing the contents of badgeDataURL and img and it's a valid image
testing setOverlayIcon with a static image: win.setOverlayIcon(__dirname+'/pics/badge.png',''+n) (and it works)
win.setOverlayIcon(null,'') also works
Although the documentation says that setOverlayIcon expects the first parameter to be of the NativeImage type I haven't been able to find a working example anywhere. Any ideas?

For me, setOverlayIcon needed to be run from the main process. Here is what fixed it on my side:
In my renderer process:
ipcRenderer.send('update-badge', canvas.toDataURL())
And in my main process:
ipcMain.on('update-badge', (event, data) => {
let img = nativeImage.createFromDataURL(data)
win.setOverlayIcon(img, 'description')
}

Related

Amplify.service.api.get returns sampleCloudAPI does not exist

I'm trying to setup AWS Mobile Hub, specifically using Amplify and Angular (5). I've setup authentication, using the provided and it works great. I can login and access the username via the AWS provided sample like so:
this.amplifyService.authStateChange$
.subscribe(authState => {
this.signedIn = authState.state === 'signedIn';
if (!authState.user) {
this.user = null;
} else {
this.user = authState.user;
this.greeting = 'Hello ' + this.user.username;
console.log('greeting ' + this.greeting );
}
});
I then wanted to setup APIGateway/Lambda functions - so I enabled cloudLogic like so:
awsmobile cloud-api enable
then did the push
awsmobile push
I see the Cloudlogic sampleAPI setup in MobileHub. However, when I attempt to access, it keeps repeating not available.
newmethod(View) {
this.amplifyService.api().get('sampleCloudApi', '/items')
.then(result => console.log('result' + result));
}
The error I get in the javascript console is:
core.js:1449 ERROR Error: Uncaught (in promise): Api sampleCloudApi does not exist
at resolvePromise (zone.js:814)
at resolvePromise (zone.js:771)
at eval (zone.js:873)
at ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4751)
at ZoneDelegate.invokeTask (zone.js:420)
at Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
at ZoneTask.invokeTask [as invoke] (zone.js:500)
at invokeTask (zone.js:1540)
I'm at a loss as to what do next. I've attempted to invoke this way:
awsmobile cloud-api invoke sampleCloudApi post /items '{"body": {"testKey":"testValue"}}'
But I still don't get a 200
In case anyone else bumps into this, I simply needed to copy the awe-exports.js from the backend directory, to the aws-exports.ts in the src directory. This had to be done manually after I added the cloud-logic portion
You can also modify your "start" script in package.json to below, so you don't have to manually change it every time.
"start": "[ -f src/aws-exports.js ] && mv src/aws-exports.js src/aws-exports.ts || ng serve; ng serve"
When you run awsmobile init it ask about the src/ directory because that will be the location that aws-exports.js file is going to be saved. Every time you run push or pull this file gets updated with the latest configuration of your resources on the cloud.

WebDriverError: Cannot find elements when the xpath expression is null in javascript

I'm testing a login page on the remote server and selenium throws me the above error. But when I test the same code on a local server, it works perfectly. I'm unable to understand as to why the remote server would throw an error and the local server won't when the selenium version on both sites is exactly the same.
Initially, I used:
browser.driver.findElement(By.xpath(desiredXpath)).click()
to click on any button. Then I tried to make a method which only performs the click operation so that every click operation could be performed by this method itself. For that I used:
browser.executeScript('arguments[0].click()', driver.findElement(By.xpath(desiredXpath)))
The above line executes perfectly on a local server but fails to recognise the xpath on the remote server and hence throws an error, WebDriverError: Cannot find elements when the xpath expression is null.
I used a console statement to print the xpath just before this line executes. It prints the xpath through which the element is to be located.
Any suggestions?
You might need to wait for the element to become present:
var elm = element(by.xpath(desiredXpath));
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(elm), 5000);
elm.click();
// or browser.executeScript("arguments[0].click();", elm.getWebElement());
My two cents on this ... I am reporting my observation below. I was able to reproduce the above stated error by passing null in xpath of theelementFinder which was passed as an argument in browser.executeScript
The below code when executed with a = null throws the error we are looking out for
it('check', function () {
browser.get("http://www.protractortest.org/");
//var a = "//a[contains(#class,'github')]";
var a = null;
browser.executeScript('arguments[0].click()', element(by.xpath(a)))
});
Error Stack
Stack:
WebDriverError: Cannot find elements when the XPath expression is null.
at WebDriverError (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:27:10)
at Object.checkLegacyResponse (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:639:15)
at parseHttpResponse (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:538:13)
at C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:472:11
at ManagedPromise.invokeCallback_ (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1379:14)
at TaskQueue.execute_ (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2913:14)
at TaskQueue.executeNext_ (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2896:21)
at C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2820:25
at C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:639:7
at process._tickCallback (node.js:369:9)
From: Task: WebDriver.findElements(By(xpath, null))
at WebDriver.schedule (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:377:17)
at WebDriver.findElements (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:926:22)
at C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\built\element.js:161:44
at ManagedPromise.invokeCallback_ (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1379:14)
at TaskQueue.execute_ (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2913:14)
at TaskQueue.executeNext_ (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2896:21)
at C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2775:27
at C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:639:7
at process._tickCallback (node.js:369:9)
From: Task: WebDriver.executeScript()
at WebDriver.schedule (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:377:17)
at WebDriver.executeScript (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:526:16)
at ProtractorBrowser.to.(anonymous function) [as executeScript] (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\built\browser.js:59:29)
at Object.<anonymous> (C:\Users\aditya\WebstormProjects\demo\demo2.js:10:17)
at C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:94:23
at new ManagedPromise (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1082:7)
at controlFlowExecute (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:80:18)
at TaskQueue.execute_ (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2913:14)
at TaskQueue.executeNext_ (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2896:21)
at C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2820:25
From: Task: Run it(" through Gmail Account") in control flow
at Object.<anonymous> (C:\Users\aditya\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:79:14)
From asynchronous test:
Error
at Suite.<anonymous> (C:\Users\aditya\WebstormProjects\demo\demo2.js:5:5)
at Object.<anonymous> (C:\Users\aditya\WebstormProjects\demo\demo2.js:4:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
1 spec, 1 failure
Finished in 1.957 seconds
Possible Root Cause could be the variable desiredXpath is being passed null and we cannot go with console.log() as they are not in sync with protractor Control flow and anything could have happened in between

l20n.js: Uncaught (in promise) TypeError: element.querySelectorAll is not a function(…)

I'm using Mozilla's l20n.js v. 3.5.0
<script defer src="/bower_components/l20n/dist/compat/web/l20n.js"></script>
and get a serious error, when script tries to parse the page.
l20n.js:2274 Uncaught (in promise) TypeError: element.querySelectorAll is not a function(…)
getTranslatables # l20n.js:2274
_translateFragment # l20n.js:2341
(anonymous function) # l20n.js:2067
translateRoots # l20n.js:2066
translateView # l20n.js:2623
(anonymous function) # l20n.js:2491
Does anyone experience the same problem? Error thrown in both Chrome and Edge.
There's a bug in the library. It was corrected but the new version is not published yet.
If you want you can correct the JavaScript file directly by replacing the content of translateRoots(), lines 2066-2068, by the following code:
var roots = Array.from(observers.get(view).roots);
return Promise.all(roots.map(function(root) {
_translateFragment(view,root)
}));
Update (26/2/2016): as stated in the comment below, now you just have to move to v3.5.1 or higher. It worked for me with FF, IE11, Chrome.

How to use the aurelia-dialog plugin with Aurelia?

I'm having trouble setting up the aurelia-dialog plugin (0.2.0) with my test Aurelia app.
Unfortunately, the README.MD file that details how to accomplish this has some serious holes. First, it doesn't mention having to inject the aureliaDialog into your class, so I tried this first:
#inject(HttpClient, DialogService)
export class MyClass{
constructor(http, dialogService) {
this.http = http;
this.dialogService = dialogService;
}
...
}
I tried to invoke the dialog box using:
this.dialogService.open({ viewModel: Prompt, model: 'Good or Bad?' })
The above results in the following errors:
Unhandled promise rejection ReferenceError: info is not defined
at Container.invoke (http://127.0.0.1:9000/jspm_packages/github/aurelia/dependency-injection#0.10.0/aurelia-dependency-injection.js:401:30)
at Array.<anonymous> (http://127.0.0.1:9000/jspm_packages/github/aurelia/dependency-injection#0.10.0/aurelia-dependency-injection.js:272:44)
at Container.get (http://127.0.0.1:9000/jspm_packages/github/aurelia/dependency-injection#0.10.0/aurelia-dependency-injection.js:329:24)
at http://127.0.0.1:9000/jspm_packages/github/aurelia/templating#0.15.1/aurelia-templating.js:3685:75
at run (http://127.0.0.1:9000/jspm_packages/npm/core-js#0.9.18/modules/es6.promise.js:91:43)
at http://127.0.0.1:9000/jspm_packages/npm/core-js#0.9.18/modules/es6.promise.js:105:11
at module.exports (http://127.0.0.1:9000/jspm_packages/npm/core-js#0.9.18/modules/$.invoke.js:6:25)
at queue.(anonymous function) (http://127.0.0.1:9000/jspm_packages/npm/core-js#0.9.18/modules/$.task.js:40:9)
at Number.run (http://127.0.0.1:9000/jspm_packages/npm/core-js#0.9.18/modules/$.task.js:27:7)
at listner (http://127.0.0.1:9000/jspm_packages/npm/core-js#0.9.18/modules/$.task.js:31:9) Unhandled promise rejection ReferenceError: info is not defined(…)(anonymous function) # es6.promise.js:139module.exports # $.invoke.js:6queue.(anonymous function) # $.task.js:40run # $.task.js:27listner # $.task.js:31
Next, I tried to add the configuration of the plugin to my main.js file:
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.plugin('aurelia-animator-css')
.plugin('aurelia-dialog'); // <----- this is what I added
aurelia.start().then(a => a.setRoot());
}
Now my app doesn't start at all and produces the following error while trying (and failing) to start:
DEBUG [aurelia] Configured plugin aurelia-dialog. aurelia-logging-console.js:38
DEBUG [templating] importing resources for undefined [] es6.promise.js:139
Unhandled promise rejection Error: Cannot read property 'querySelectorAll' of undefined(…)
(anonymous function) # es6.promise.js:139module.exports # $.invoke.js:6queue.
(anonymous function) # $.task.js:40run # $.task.js:27listner # $.task.js:31
I am now at a loss of what to try next. Thanks for any insight you can offer with this issue.
I'm also hopeful that the maintainer of the aurelia-dialog plugin revises the docs to make the setup process less painful.
Thanks,
Greg
In the end, the problem turned out to be a bug in aurelia-dialog 0.2.0. Version 0.2.1 fixes the issue I couldn't resolve on my own: https://github.com/aurelia/dialog/pull/24.
The other steps that I had to follow are still necessary - you will need to inject the DialogService class and modify your main.js file to add the configuration.

CasperJS 1.1.0-beta2 test example resulting in UncaughtError

I would love to use CasperJS to run tests against the PhantomJS headless browser. There is great documentation, but this example I would like to follow does not work. Has anyone been able to get this to work, or can someone find a problem with my implementation? I am referencing this "Advanced Technique" in the CasperJS Documentation:
//cow-test-ref.js
function Cow() {
this.mowed = false;
this.moo = function moo() {
this.mowed = true; // mootable state: don't do that at home
return 'moo!';
};
}
casper.test.begin('Cow can moo', 2, {
setUp: function(test) {
this.cow = new Cow();
},
tearDown: function(test) {
this.cow.destroy();
},
test: function(test) {
test.assertEquals(this.cow.moo(), 'moo!');
test.assert(this.cow.mowed);
test.done();
}
});
My Result is the following error:
m#mPro marketing_qa $ casperjs --version
1.1.0-beta2
m#mPro tests $ casperjs test cow-test-ref.js
Test file: cow-test-ref.js
# Cow can moo
PASS Subject equals the expected value
PASS Subject is strictly true
FAIL TypeError: 'undefined' is not a function (evaluating 'this.cow.destroy()')
# type: uncaughtError
# file: cow-test-ref.js:14
# error: 'undefined' is not a function (evaluating 'this.cow.destroy()')
# TypeError: 'undefined' is not a function (evaluating 'this.cow.destroy()')
# at cow-test-ref.js:14
# at done (/usr/local/Cellar/casperjs/1.1-beta2/libexec/modules/tester.js:1067)
# at cow-test-ref.js:20
# at /usr/local/Cellar/casperjs/1.1-beta2/libexec/modules/tester.js:986
# at /usr/local/Cellar/casperjs/1.1-beta2/libexec/bin/bootstrap.js:51
# at begin (/usr/local/Cellar/casperjs/1.1-beta2/libexec/modules/tester.js:1015)
# at cow-test-ref.js:21
# stack: not provided
FAIL 3 tests executed in 0.023s, 2 passed, 1 failed, 0 dubious, 0 skipped.
Has anyone encountered this, or worked around this successfully? I'd love to use this test pattern.
The destroy method is used as an example to highlight the concept of the principle behind tearDown. The method is not implemented in the original code, so the error you get is normal.

Categories

Resources