Reputation: 7114
I am creating a web app which I plan to deliver both from a standard web site and as an NWJS standalone application. In NWJS, I can use the require
command, but not in a browser. I can wrap my command in an if
statement:
<script>
if (typeof require === "function") {require('nwjs-osx-menu')(window)}
</script>
Are there other ways that would be considered better practice?
EDIT: following @Kuf's suggestion
<script>
if (typeof require === "function") {
try{
require('nwjs-osx-menu')(window)
} catch (error) {}
}
</script>
Upvotes: 4
Views: 2754
Reputation: 11183
My limited understanding is that if process
is defined, you are in NWJS, and have access to fields such as process.versions['nw-flavor']
.
Upvotes: 0
Reputation: 17846
Update
If the only difference is loading that library then your code seems fine.
original post
There is a web client require module so that might be a bit risky. I used the following:
function is_nwjs(){
try{
return (typeof require('nw.gui') !== "undefined");
} catch (e){
return false;
}
}
Upvotes: 2