-
-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting wmlandscape to run not in a browser #114
base: master
Are you sure you want to change the base?
Conversation
I've been working to get the wmlandscape library to work on the commandline. This line was the only issue in that `window` doesnt exist in node.
const isDarwin = /Mac|iPod|iPhone|iPad/.test(window.navigator.platform); | ||
let onMac = null; | ||
|
||
if (typeof window === 'undefined') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I looked into this, and you are correct that undefined is a value not a string... But SURPRISE! typeof returns undefined as a string... which is totally wierd, but here we are.
[] :~/projects/wm-cli mlakewood$ node
Welcome to Node.js v16.4.2.
Type ".help" for more information.
> typeof window
'undefined'
> typeof window === 'undefined' ? 1 : 0
1
> typeof window === 'undefined' ? "its a string" : "its something else"
'its a string'
So I think this code is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, I misread the check. It does do what it says
You can simplify this check by just replacing "window" with let onMac;
if (globalThis.navigator) {
onMac = /Mac|iPod|iPhone|iPad/.test(globalThis.navigator.platform);
} else {
onMac = process.platform === 'darwin';
}
const isDarwin = onMac; But your check will also work if you fix the The browser is also acting as the rendering engine in this case, so if you're planning on rendering images with Node you'll need to experiment with node-canvas or a similar library |
With regards to the globalThis object, I attempted to use it, however it looks like there are the following drawbacks
|
I've been working to get the wmlandscape library to work on the
commandline. The
window
object doesnt exist in node. I've tried to make sure that this doesnt break anything,and the variable declarations are a bit funky to make sure we get a
const
for isDarwin. Im a bit of a newcomer to node, so open to any and all feedback.