forked from 21st-dev/1code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch-electron-dev.mjs
More file actions
37 lines (31 loc) · 1.33 KB
/
Copy pathpatch-electron-dev.mjs
File metadata and controls
37 lines (31 loc) · 1.33 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
// Patches the Electron.app bundle in node_modules to show "1Code" name and icon in macOS dock during dev mode.
import { execSync } from "child_process"
import { copyFileSync, existsSync } from "fs"
import { join, dirname } from "path"
import { fileURLToPath } from "url"
const __dirname = dirname(fileURLToPath(import.meta.url))
const root = join(__dirname, "..")
const electronApp = join(root, "node_modules/electron/dist/Electron.app")
const plistPath = join(electronApp, "Contents/Info.plist")
const icnsSource = join(root, "build/icon.icns")
const icnsDest = join(electronApp, "Contents/Resources/electron.icns")
if (process.platform !== "darwin") {
process.exit(0)
}
if (existsSync(plistPath)) {
try {
execSync(`/usr/libexec/PlistBuddy -c "Set :CFBundleName 1Code" "${plistPath}"`)
execSync(`/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName 1Code" "${plistPath}"`)
console.log("[patch-electron-dev] Updated Info.plist: name -> 1Code")
} catch (e) {
console.warn("[patch-electron-dev] Failed to update Info.plist:", e.message)
}
}
if (existsSync(icnsSource) && existsSync(icnsDest)) {
copyFileSync(icnsSource, icnsDest)
console.log("[patch-electron-dev] Replaced electron.icns with custom icon")
}
// Touch the .app bundle so macOS re-reads it
if (existsSync(electronApp)) {
execSync(`touch "${electronApp}"`)
}