Electron protocol handler not working on windows - javascript

I’m trying to register a protocol handler using app.setAsDefaultProtocolClient and I’ve got it working fine on macOS but on windows 10 I get a dialog saying
Error launching app
Unable to find Electron app at 'C:\Program Files(x86)\Google\Chrome\Application\60.0.3….. Ect
Cannot find module 'C:\Program Files(x86)\Google\Chrome\Application\60.0.3….. Ect
Is it right that it’s looking in Chrome\Application folder? I get the same error if I run with npm start or from a packaged app using electron-packager.
Is there something i’m missing that i need to configure for windows? Like the plist on mac? I’ve been looking round but can’t seem to find anything. let me know any info i can add to help.

I had the same problem: the protocol handler doesn't find the location of the app in development environment on Windows. Everything works on OSX, and Windows only when packaged. The fix here is to manually supply the path to your app when registering the protocol.
Originally, I had something like this, which worked on OSX and packaged.exe on Windows:
if(!app.isDefaultProtocolClient('app')) {
app.setAsDefaultProtocolClient('app');
}
Here's the fix that corrected the path problem for developing on Windows:
// remove so we can register each time as we run the app.
app.removeAsDefaultProtocolClient('app');
// If we are running a non-packaged version of the app && on windows
if(process.env.NODE_ENV === 'development' && process.platform === 'win32') {
// Set the path of electron.exe and your app.
// These two additional parameters are only available on windows.
app.setAsDefaultProtocolClient('app', process.execPath, [path.resolve(process.argv[1])]);
} else {
app.setAsDefaultProtocolClient('app');
}
I had my project setup so that process.env.NODE_ENV would tell me if I'm in development environment or not. If you're in development environment, you want to pass in two additional parameters to app.setAsDefaultProtocolClient. The first argument, of course, is the protocol you want to register, the second argument should be the path to the electron executable. process.execPath is the default value, and should evaluate to /path/to/your/project/node_modules/electron/dist/electron.exe or similar.
The third argument is an array of arguments you want to run electron.exe with. In my case, I want to run my app, so I pass in the path wrapped in an array []. process.argv[1] is simply a way to get the path of the dev app, which should evaluate to /path/to/your/project/dist/electron/main.js or similar.
For more information: https://electronjs.org/docs/api/app#appsetasdefaultprotocolclientprotocol-path-args

Related

how can i prohibit my electron to register with protocol handler while running directly from IDE?

I have an electron app which i register with protocol handler using below code in main.js
app.setAsDefaultProtocolClient('xyz');
When i tried to run it from installed location all works as expected .But launching it from visual studio code messed up the protocol handler(As while running from IDE like VS code it name the app as a electron app instead of the name I defined) as a result of which next time when I try running from installed location the protocol handler tries to find a different app which is default "Electron" app.Is there any way i can avoid this from happening .
I tried putting an if statement to check if the app.name and my expected name is same but this always returns true though i see the app name as Electron on my os.Any clue here will be helpful
You can use app.isPackaged.
A Boolean property that returns true if the app is packaged, false otherwise. For many apps, this property can be used to distinguish development and production environments.

Meteor - Meteor.Collection.get not defined in production

I'm trying to use Meteor.Collection.get(collection_name) (server side only) in production, it works well in development ; but as soon as I try to build my app with meteor --production, meteor throw
TypeError: Meteor.Collection.get is not a function
I suppose that Meteor.Collection.get was only made for debugging purposes (I can't find anything about it in the official documentation). Any idea how I can use it in production ?
I am not sure, where Meteor.Collection.get comes from in your code but I know the very reliable and long time battle proof dburles:mongo-collection-instances which allows you to retrieve a Mongo.Collection via it's name.
Add the package:
meteor add dburles:mongo-collection-instances
Create a collection:
// server/client
export const MyDocs = new Mongo.Collection('myDocs')
Get the collection:
// anywhere else
const MyDocs = Mongo.Collection.get('myDocs')
It works on the server and the client and runs fine in production.
Documentation: https://github.com/dburles/mongo-collection-instances
Edit: A note on --production
This flag is only there to simulate production minifaction. See the important message here in the docs: https://guide.meteor.com/deployment.html#never-use-production-flag
You should always use meteor build to build a production node app. More to read here: https://guide.meteor.com/deployment.html#custom-deployment

Running meteor app on Windows from MacOS

I got a Meteor project from a friend who develops on MacOS.
When trying to run it, I get:
This project uses METEOR#1.0.2.1, which isn't available on Windows. To
work with this app on all supported platforms, use meteor update
--release METEOR#1.2.1 to pin this app to the newest Windows-compatible release.
When running it, I get:
While checking for cfs:gridfs#0.0.27: no compatible binary file
found...
Then, when I try to override (use run instead of update), without actually updating, it starts proxy and Mongo, but then breaks at, but skips the first error
While building package npm-container: error: No plugin known to handle
file '../../packages.json'. If you want this file to be a static
asset, use addAssets instead of addFiles; eg,
api.addAssets('../../packages.json', 'client').
I read that this error is fixed by updating meteorhacks, but when I try to, I get the Meteor version conflicts (see very first error) and I have no idea how to break out of the loop.
Can someone shine some light on how to fix any of these error?

Yeoman angularjs-cordova app - what is next?

I created the app according to this article: https://www.npmjs.com/package/generator-angularjs-cordova with yeoman and angularjs-cordova generator.
At creation app time, I was prompted to choose plugins that I want to use in my app.
I added next cordova plugins:
cordova.device, cordova.camera and cordova.vibration.
I run the app in browser with "grunt serve" command and it works!
Now, how can I get the device data?
I tried to check the device global object in app\js\application.js but it's undefined...
EDIT:
In firebug console I get the next errors:
"NetworkError: 404 Not Found - http://127.0.0.1:9000/cordova.js"
"ReferenceError: jQuery is not defined"
Why those modules were not connected automatically?
Where do I need to place the connection to the modules?
The answer is simple!
Device is not exists on the web browser.
When I run it on the android smartphone - everything is OK.
* Remember to copy all files from the app folder to the www folder!

How can I tell if my Cordova application is running on a simulator or real device?

I'd like to be talk to a different server when running in an emulator / simulator.
It looks like device.platform used to mention the simulator, but know it just says "iOS". The user-agent doesn't seem to differentiate either.
Ideally the solution would work for all platforms, but I'll take Android and iOS, or in fact anything helpful!
For iOS I just check the model - if matches /x86/ then it's the simulator (until Apple release an Intel iOS device).
function isRunningInSimulator(device) {
// Only valid after deviceReady
return device && device.model.match(/x86/);
}
In the most recent version of the Device plugin (https://www.npmjs.com/package/cordova-plugin-device), there is now a isVirtual property that represents this.
I don't know if it is possible to detect. One "workaround" is use a task manager (grunt, gulp, whatever) to copy configuration files from on folder to other. Then instead of running "cordova run android" (example) at the command line, you would run a task that copies the config file(s) from one specific folder (i.e.: development or production) an the application read the copied file.
You can take a look here http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/ at the section "Replace Text Depending on Environment"

Categories