Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpatch-opencode-asar.py
More file actions
Latest commit
54 lines (42 loc) · 1.9 KB
/
Copy pathpatch-opencode-asar.py
File metadata and controls
54 lines (42 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
"""
Disable the OpenCode Electron app's self-updater inside a Flatpak, in place.
Sets UPDATER_ENABLED = false in out/main/index.js inside app.asar. This is a
same-length text replacement, so the asar binary is patched directly without
extract/repack (which would drop the app.asar.unpacked native-module
metadata). The asar header, all offsets, and the unpacked entries are
preserved byte-for-byte.
Flatpak provides updates via the OS updater (GNOME Software / KDE Discover /
flatpak update); the electron-updater self-updater can't install into the
read-only /app anyway, so it must be disabled. Upstream issue:
https://github.com/anomalyco/opencode/issues/39670
Usage: patch-opencode-asar.py <path/to/app.asar>
"""
importos
importsys
defmain() ->None:
iflen(sys.argv) !=2:
print(f"usage: {sys.argv[0]} <path/to/app.asar>", file=sys.stderr)
sys.exit(2)
asar_path=sys.argv[1]
ifnotos.environ.get("FLATPAK_ID"):
print("FLATPAK_ID is not set; expected to be run inside flatpak-builder", file=sys.stderr)
sys.exit(1)
withopen(asar_path, "rb") asf:
data=f.read()
# out/main/index.js: `const UPDATER_ENABLED = app.isPackaged && CHANNEL !== "dev";`
# Replace the RHS with `false` plus a comment, padded to the same byte
# length so the asar layout (offsets, unpacked entries) is unchanged.
old=b'app.isPackaged && CHANNEL !== "dev"'
new=b'false/*packed&&CHANNEL!=="dev"*/'.ljust(len(old), b" ")
iflen(old) !=len(new):
raiseSystemExit(f"length mismatch: {len(old)} vs {len(new)}")
count=data.count(old)
ifcount!=1:
raiseSystemExit(f"expected exactly 1 occurrence of UPDATER_ENABLED, found {count}")
data=data.replace(old, new, 1)
withopen(asar_path, "wb") asf:
f.write(data)
print(f"patched {asar_path}: UPDATER_ENABLED = false")
if__name__=="__main__":
main()