-
-
Save khronokernel/122dc28114d3a3b1673fa0423b5a9b39 to your computer and use it in GitHub Desktop.
""" | |
electron_patcher.py: Enforce 'use-angle@1' in Chrome and Electron applications | |
Version 1.0.0 (2024-08-11) | |
""" | |
import enum | |
import json | |
from pathlib import Path | |
class ChromiumSettingsPatcher: | |
class AngleVariant(enum.Enum): | |
Default = "0" | |
OpenGL = "1" | |
Metal = "2" | |
def __init__(self, state_file: str) -> None: | |
self._local_state_file = Path(state_file).expanduser() | |
def patch(self) -> None: | |
""" | |
Ensure 'use-angle@1' is set in Chrome's experimental settings | |
""" | |
_desired_key = "use-angle" | |
_desired_value = self.AngleVariant.OpenGL.value | |
if not self._local_state_file.exists(): | |
print(" Local State missing, creating...") | |
self._local_state_file.parent.mkdir(parents=True, exist_ok=True) | |
state_data = {} | |
else: | |
print(" Parsing Local State file") | |
state_data = json.loads(self._local_state_file.read_bytes()) | |
if "browser" not in state_data: | |
state_data["browser"] = {} | |
if "enabled_labs_experiments" not in state_data["browser"]: | |
state_data["browser"]["enabled_labs_experiments"] = [] | |
for key in state_data["browser"]["enabled_labs_experiments"]: | |
if "@" not in key: | |
continue | |
key_pair = key.split("@") | |
if len(key_pair) < 2: | |
continue | |
if key_pair[0] != _desired_key: | |
continue | |
if key_pair[1] == _desired_value: | |
print(f" {_desired_key}@{_desired_value} is already set") | |
break | |
index = state_data["browser"]["enabled_labs_experiments"].index(key) | |
state_data["browser"]["enabled_labs_experiments"][index] = f"{_desired_key}@{_desired_value}" | |
print(f" Updated {_desired_key}@{_desired_value}") | |
if f"{_desired_key}@{_desired_value}" not in state_data["browser"]["enabled_labs_experiments"]: | |
state_data["browser"]["enabled_labs_experiments"].append(f"{_desired_key}@{_desired_value}") | |
print(f" Added {_desired_key}@{_desired_value}") | |
print(" Writing to Local State file") | |
self._local_state_file.write_text(json.dumps(state_data, indent=4)) | |
def main(): | |
# Patch all Electron applications | |
for directory in Path("~/Library/Application Support").expanduser().iterdir(): | |
if not directory.is_dir(): | |
continue | |
state_file = directory / "Local State" | |
if not state_file.exists(): | |
continue | |
print(f"Patching {directory.name}") | |
patcher = ChromiumSettingsPatcher(state_file) | |
patcher.patch() | |
# Patch all Chrome variants | |
if Path("~/Library/Application Support/Google").expanduser().exists(): | |
for directory in Path("~/Library/Application Support/Google").expanduser().iterdir(): | |
if not directory.is_dir(): | |
continue | |
state_file = directory / "Local State" | |
if not state_file.exists(): | |
continue | |
print(f"Patching {directory.name}") | |
patcher = ChromiumSettingsPatcher(state_file) | |
patcher.patch() | |
if __name__ == "__main__": | |
main() |
same as above but with Vesktop
Does not work for Microsoft Teams, though.
I - and many others more - would deeply appreciate a patch or workaround vor MS-Teams.
Please help! Thanks a lot in advance!
Not working for all Electron App (ex: Microsoft Edge, Spotify....)
I updated this to work for Microsoft Teams. Since the app is sandboxed, the Local State was buried here in my case: "~/Library/Containers/com.microsoft.teams2/Data/Library/Application Support/Microsoft/MSTeams/EBWebView/Local State"
MS Teams Fork of the script can be found here:
https://gist.github.com/matthew-mclaren/7373d551ebb11c38a6f7cb8702998dc3
For any other chromium apps which aren't found in Application Support, you will need to find the local state and add them to the main function.
I have added another script to scan the user Library for "Local State" files which you can then add to the patcher at your own risk
https://gist.github.com/matthew-mclaren/c51e860a321985f0f7e84c9468cc9965
Thanks man!!!! I was looking for this patch for some time now....
Done it also for Spotify, and worked!!!
Patch Spotify
spotify_path = Path(
"~/Library/Caches/com.spotify.client/Local State"
).expanduser()
if spotify_path.exists():
print("Patching Spotify")
patcher = ChromiumSettingsPatcher(spotify_path)
patcher.patch()
Made an update to the scripts
Features:
- macOS only: Optimized for macOS Electron applications
- Auto-detection: Automatically finds Electron applications in standard locations
- Specific apps: Has special handling for common apps like Spotify, Discord, VSCode, Microsoft Teams
- Command-line options: Can scan custom directories or patch specific applications
- Deep scanning: Can recursively search for Local State files
- Network mount protection: Avoids scanning network-mounted volumes
Usage examples:
python electron_patcher.py # Patch all detected applications
python electron_patcher.py --list-only # Just list applications without patching
python electron_patcher.py --scan-dir ~/Apps # Scan a custom directory
python electron_patcher.py --app-path ~/path/to/app/Local\ State --app-name "My App"
python electron_patcher.py --deep-scan # Perform deep scan of user's home directory
https://gist.github.com/trulow/d5c69fa07231718bbe4b3a5154dd1f44
Doesn't seem to work for VSCode? Any idea where it's stored for VSCode?
I don't have VS Code installed, but can you verify if it's in the following location in your system?
~/Library/Application\ Support/Code/User/History
I don't have VS Code installed, but can you verify if it's in the following location in your system?
~/Library/Application\ Support/Code/User/History
Jup, there is a dir like this, but no Local State
. Any idea on patching VSCode?
I have VSCode on my Open Core system and do no have any issues with it. Check you VSCode settings and search for "Acceleration" . I have an "Editor: Experimental Gpu Acceleration" which is off and "Terminal › Integrated: Gpu Acceleration" set to auto (Switch this off if you're having trouble)
A similar hardware acceleration needed to be manually disabled for Slack to work as well. There are 2x JSON files here. I searched for HwAcceleration and set the values to false in all instances.
~/Library/Application Support/Slack/local-settings.json
~/Library/Application Support/Slack/storage/root-state.json
I have VSCode on my Open Core system and do no have any issues with it. Check you VSCode settings and search for "Acceleration" . I have an "Editor: Experimental Gpu Acceleration" which is off and "Terminal › Integrated: Gpu Acceleration" set to auto (Switch this off if you're having trouble)
The issue occurred since the last VSCode update for me. I have applied the mentioned settings, which do not seem to fix the problem (permanently). The only solution (which always does it job) seems to be starting VSCode from the terminal using the following flags: --args --use-angle=gl
.
1Password used to work, but now it's got the pinks And the manual fix does not help. Any ideas? I'm on Sequoia 15.3.1 On a 2013 Mac Pro.
Hello and thanks for sharing this script!
I use most of the involved apps (Teams, VS Code, Microsoft Edge, 1Password, sometimes Chrome).
I will try the script tomorrow and keep you posted.
Update:
ran this fork of the script; Edge, Chrome and Teams are working fine now.
With this workaround I am now able to run those apps except 1Password (I can only use its browser extensions) and maybe that even other apps will use Electron when they are updated.
Is there any chance that issue #1145 is going to be fixed in a future release of OCLP?
Seems like Docker Desktop has the same problem, any solution?
Seems like Docker Desktop has the same problem, any solution?
I also ran into this. I haven't found a solution that keeps hardware acceleration and Docker Desktop GUI but if you don't need the GUI and can use just the command line version of Docker, you can use Colima. What worked for me was:
brew install docker colima
colima start --cpu 6 --memory 16 --disk 100
brew install docker-compose
If you want the GUI.. one interesting thing I noticed was that Docker Desktop worked as expected when the root patches were reverted. I wanted to restore from a Time Machine backup so I had to revert the root patches. Once the backup was done restoring, the system booted back up with root patches still off and Docker Desktop loaded as expected. Once root patches were activated again, it went back to the red screen of death. I was able to get it back up and running by manually modifying the settings-store.json file as follows.
Open '~/Library/Group Containers/group.com.docker/settings-store.json'
Add to the end of the json structure -- disableHardwareAcceleration": true
Source for the above potential workaround: https://docs.docker.com/desktop/troubleshoot-and-support/troubleshoot/topics/
Seems like Docker Desktop has the same problem, any solution?
I also ran into this. I haven't found a solution that keeps hardware acceleration and Docker Desktop GUI but if you don't need the GUI and can use just the command line version of Docker, you can use Colima. What worked for me was:
brew install docker colima colima start --cpu 6 --memory 16 --disk 100 brew install docker-compose
If you want the GUI.. one interesting thing I noticed was that Docker Desktop worked as expected when the root patches were reverted. I wanted to restore from a Time Machine backup so I had to revert the root patches. Once the backup was done restoring, the system booted back up with root patches still off and Docker Desktop loaded as expected. Once root patches were activated again, it went back to the red screen of death. I was able to get it back up and running by manually modifying the settings-store.json file as follows.
Open '~/Library/Group Containers/group.com.docker/settings-store.json' Add to the end of the json structure -- disableHardwareAcceleration": true
Source for the above potential workaround: https://docs.docker.com/desktop/troubleshoot-and-support/troubleshoot/topics/
Never mind.. I was trying to replicate getting the GUI to work with the disableHardwareAcceleration flag but it didn't work. What did sort of work was disabling the root patches and starting docker. The GUI came up and I was able to go through initial setup and set it to auto start without opening the console. At least docker still works in the CLI this way after turning root patches back on.
FYI today I installed the 15.4.1 Sequoia update on my MacPro 6,1 and after rebooting OCLP notified me that I had to reinstall some patches:
Since I had read the @edilAraujo comments about Docker Desktop I tried to start 1Password before re-applying the patches ... and it works! I was therefore able to modify some of its settings to prevent the password request to come up every day with its red-window-of-death.
@khronokernel sorry to bother again, but is there any chance that issue #1145 is going to be fixed in a future release of OCLP?
Ok I've found a workaround for 1Password, just disable "Use Hardware Acceleration" in Settings > Advanced before installing the root patches:
If you have already installed the OCLP root patches, the same result can be achieved adding this line
"app.useHardwareAcceleration": false,
to the 1Password settings file:
~/Library/Group\ Containers/2BUA8C4S2C.com.1password/Library/Application\ Support/1Password/Data/settings/settings.json
but before doing so you have to be sure that the 1Password app is not running and its menu item is disabled.
@trulow I guess that the latter could be useful for your fork of electron_patcher.py but I'm not a Python expert and this needs some specific detection/patch methods for 1Password.
I installed Sequoia on my MacPro6,1 and it works very well. Using this patcher fixed Chrome and Opera for me and the only remaining app so far is Obsidian for which I have found the following fix. First launch Obsidian from using this command
open /Applications/Obsidian.app --args --use-angle=gl
Then once you are up and running go to Settings>Appearance>Hardware Acceleration and turn it off. You can now run obsidian as normal.
For the Signals app, the file in line 76 would typically not exist, and the rest of the magic then skipped. Also manually creating the file with the right content wouldn't work.
open /Applications/Signal.app --args --use-angle=gl
however works.