Skip to content

Add custom switches for electron mainWindow#2643

Merged
MichMich merged 3 commits into
MagicMirrorOrg:developfrom
MMRIZE:develop
Aug 31, 2021
Merged

Add custom switches for electron mainWindow#2643
MichMich merged 3 commits into
MagicMirrorOrg:developfrom
MMRIZE:develop

Conversation

@eouia

@eouia eouia commented Aug 30, 2021

Copy link
Copy Markdown
Contributor

I need some custom electron switches for my purpose. (e.g., Desktop background playing)

This feature enables adding custom switches on Electron starts by a user.

You can add switches in config.js like;

electronSwitches: ['enable-transparent-visuals'],

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #2643 (45529f7) into develop (8589d9c) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2643      +/-   ##
===========================================
+ Coverage    71.01%   71.04%   +0.03%     
===========================================
  Files           16       16              
  Lines          828      829       +1     
===========================================
+ Hits           588      589       +1     
  Misses         240      240              
Impacted Files Coverage Δ
js/electron.js 72.72% <100.00%> (+0.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8589d9c...45529f7. Read the comment docs.

@MichMich

Copy link
Copy Markdown
Collaborator

What's the difference between this and the already implemented electronOptions config option?

@eouia

eouia commented Aug 31, 2021

Copy link
Copy Markdown
Contributor Author

@MichMich
This is not about electronOption. It is about switch.
With electronOption (https://www.electronjs.org/docs/latest/api/browser-window#new-browserwindowoptions), you can control the window created by electron, but not the electron app itself.
switch (commandLine.switch) is rather for App(and some node features) itself. (https://www.electronjs.org/docs/latest/api/command-line-switches) These could not be achieved with electronOption

@MichMich

Copy link
Copy Markdown
Collaborator

Ok. If you can fix the conflict so I can merge it. Also, please create a PR in the docs repo (and if possible reference the PR in this PR).

Thanks!

@eouia

eouia commented Aug 31, 2021

Copy link
Copy Markdown
Contributor Author

Thanks. I'll do it in a few hours.
Anyway, with this feature, your MM could be located as Desktop wallpaper on the Mac or Linux machine. (That's my purpose of this PR. :D )

@MichMich

Copy link
Copy Markdown
Collaborator

Cool! Thanks for your PR!

@MichMich MichMich merged commit e40ddd4 into MagicMirrorOrg:develop Aug 31, 2021
@eouia eouia deleted the develop branch September 2, 2021 08:39
khassel pushed a commit that referenced this pull request May 3, 2026
I reviewed the CodeQL alerts for `js/electron.js`:

-
[#25](https://github.com/MagicMirrorOrg/MagicMirror/security/code-scanning/25)
https://github.com/MagicMirrorOrg/MagicMirror/security/code-scanning/25
-
[#22](https://github.com/MagicMirrorOrg/MagicMirror/security/code-scanning/22)
https://github.com/MagicMirrorOrg/MagicMirror/security/code-scanning/22

Both point to real bugs.

-
[#25](https://github.com/MagicMirrorOrg/MagicMirror/security/code-scanning/25):
The window size fallback was written as a comma expression (`(800,
600)`), so it did not produce the expected object structure `{ width,
height }`. I am not surprised it went unnoticed because it sits in a
fallback path.
-
[#22](https://github.com/MagicMirrorOrg/MagicMirror/security/code-scanning/22):
`...new Set(electronSwitchesDefaults, config.electronSwitches)` silently
ignored the second parameter. As a result, custom `electronSwitches`
were never applied. I am wondering: this has been broken since PR #2643
introduced it, so I'm quite sure it could not have worked as intended in
that form. Why didn't anyone (not even @eouia) notice that? 🤔

## Changes

- Fix for
[#25](https://github.com/MagicMirrorOrg/MagicMirror/security/code-scanning/25):
- Corrects the fallback from `(800, 600)` to a valid size object `{
width: 800, height: 600 }`.
- Fix for
[#22](https://github.com/MagicMirrorOrg/MagicMirror/security/code-scanning/22):
  - Sets the default switch explicitly as a correct key-value pair:
- `app.commandLine.appendSwitch("autoplay-policy",
"no-user-gesture-required")`
  - Applies custom `config.electronSwitches` individually afterward.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants