Set process.platform
at build time
#6784
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Set
process.platform
at build timePull Request Type
Description
For a while now I've been wondering what the best approach would be for detecting the OS that FreeTube is running on for OS specific functionality like keyboard shortcuts when we disable
nodeIntegration
. Currently we use Node.js'process.platform
property. Originally I was planning to try and detect it withnavigator.platform
andnavigator.userAgentData
like shaka-player does, but then after looking at native code in a different project I remembed that compile to native languages do the OS specific stuff at build time and there is no reason why we can't do the same, we already have various other build flags.The webpack config for the renderer and main files use the
process.platform
value of the machine that the build is running on and the web config usesundefined
which is the same as the current behaviour as theprocess
polyfill doesn't support theplatform
property. This shouldn't cause any problems as the_scripts/build.js
script that calls electron-builder for the production builds already uses the OS of the machine it is running on and during development we launch electron on the same machine that webpack is running on so it won't cause issues there either. The only case it could cause problems is if someone were to runyarn run pack
on one machine, copy the output to another machine running a different OS and runyarn run build-release
there, but nobody should be doing that.We can't get rid of the
process
polyfill just yet as the util polyfill that the web version ofnedb
uses, uses theprocess
global, I am working on a modernised fork of nedb that should resolve that though (switch to ESM, remove the callback APIs and deprecated functionality, the idea is that we will only have to change the package name in the package.json file in FreeTube without needing any code changes).All numbers are in bytes. For the platform specific after numbers, I hardcoded the
process.platform
to specific platforms in the webpack config and ranyarn run clean && yarn run pack
.main.js
beforemain.js
afterrenderer.js
beforerenderer.js
afterTesting
yarn run dev
and check that platform specific things like keyboard shortcuts still work.Desktop