Set process.platform at build time
#6784
Merged
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.platformat 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.platformproperty. Originally I was planning to try and detect it withnavigator.platformandnavigator.userAgentDatalike 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.platformvalue of the machine that the build is running on and the web config usesundefinedwhich is the same as the current behaviour as theprocesspolyfill doesn't support theplatformproperty. This shouldn't cause any problems as the_scripts/build.jsscript 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 packon one machine, copy the output to another machine running a different OS and runyarn run build-releasethere, but nobody should be doing that.We can't get rid of the
processpolyfill just yet as the util polyfill that the web version ofnedbuses, uses theprocessglobal, 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.platformto specific platforms in the webpack config and ranyarn run clean && yarn run pack.main.jsbeforemain.jsafterrenderer.jsbeforerenderer.jsafterTesting
yarn run devand check that platform specific things like keyboard shortcuts still work.Desktop