Skip to content

Commit d51183b

Browse files
littlekirkycodeclaudejonathanlab
authored
feat: Add Windows support (#1242)
Co-authored-by: littlekirkycode <littlekirky@googlemail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: JonathanLab <jonathanmieloo@gmail.com> Co-authored-by: Jonathan Mieloo <32547391+jonathanlab@users.noreply.github.com>
1 parent 2b631d9 commit d51183b

File tree

35 files changed

+916
-190
lines changed

35 files changed

+916
-190
lines changed

.github/workflows/code-release.yml

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ concurrency:
1010
cancel-in-progress: false
1111

1212
jobs:
13-
publish:
13+
publish-macos:
1414
runs-on: macos-latest
1515
permissions:
1616
id-token: write
@@ -129,3 +129,76 @@ jobs:
129129
GH_TOKEN: ${{ steps.app-token.outputs.token }}
130130
APP_VERSION: ${{ steps.version.outputs.version }}
131131
run: gh release edit "v$APP_VERSION" --repo PostHog/code --draft=false
132+
133+
publish-windows:
134+
runs-on: windows-latest
135+
permissions:
136+
id-token: write
137+
contents: write
138+
env:
139+
NODE_OPTIONS: "--max-old-space-size=8192"
140+
NODE_ENV: production
141+
VITE_POSTHOG_API_KEY: ${{ secrets.VITE_POSTHOG_API_KEY }}
142+
VITE_POSTHOG_API_HOST: ${{ secrets.VITE_POSTHOG_API_HOST }}
143+
steps:
144+
- name: Get app token
145+
id: app-token
146+
uses: getsentry/action-github-app-token@d4b5da6c5e37703f8c3b3e43abb5705b46e159cc # v3
147+
with:
148+
app_id: ${{ secrets.GH_APP_ARRAY_RELEASER_APP_ID }}
149+
private_key: ${{ secrets.GH_APP_ARRAY_RELEASER_PRIVATE_KEY }}
150+
151+
- name: Checkout
152+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
153+
with:
154+
fetch-depth: 0
155+
token: ${{ steps.app-token.outputs.token }}
156+
persist-credentials: false
157+
158+
- name: Setup pnpm
159+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4
160+
161+
- name: Setup Node.js
162+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
163+
with:
164+
node-version: 22
165+
cache: "pnpm"
166+
167+
- name: Extract version from tag
168+
id: version
169+
shell: pwsh
170+
run: |
171+
$tagVersion = "${{ github.ref }}" -replace "refs/tags/v", ""
172+
echo "Version: $tagVersion"
173+
echo "version=$tagVersion" >> $env:GITHUB_OUTPUT
174+
175+
- name: Set version in package.json
176+
shell: pwsh
177+
env:
178+
APP_VERSION: ${{ steps.version.outputs.version }}
179+
run: |
180+
$pkg = Get-Content apps/code/package.json -Raw | ConvertFrom-Json
181+
$pkg.version = "$env:APP_VERSION"
182+
$pkg | ConvertTo-Json -Depth 10 | Set-Content apps/code/package.json
183+
echo "Set apps/code/package.json version to $env:APP_VERSION"
184+
185+
- name: Install dependencies
186+
run: pnpm install --frozen-lockfile
187+
188+
- name: Build electron-trpc package
189+
run: pnpm --filter @posthog/electron-trpc run build
190+
191+
- name: Build shared package
192+
run: pnpm --filter @posthog/shared run build
193+
194+
- name: Build git package
195+
run: pnpm --filter @posthog/git run build
196+
197+
- name: Build agent package
198+
run: pnpm --filter @posthog/agent run build
199+
200+
- name: Publish with Electron Forge
201+
env:
202+
APP_VERSION: ${{ steps.version.outputs.version }}
203+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
204+
run: pnpm --filter code run publish

apps/code/forge.config.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { ChildProcess } from "node:child_process";
22
import { execSync } from "node:child_process";
3-
import { cpSync, existsSync, mkdirSync, rmSync, statSync } from "node:fs";
3+
import { cpSync, existsSync, mkdirSync, rmSync } from "node:fs";
44
import path from "node:path";
55
import { MakerDMG } from "@electron-forge/maker-dmg";
6+
import { MakerSquirrel } from "@electron-forge/maker-squirrel";
67
import { MakerZIP } from "@electron-forge/maker-zip";
78
import { VitePlugin } from "@electron-forge/plugin-vite";
89
import { PublisherGithub } from "@electron-forge/publisher-github";
@@ -181,28 +182,30 @@ const config: ForgeConfig = {
181182
}
182183
: {}),
183184
}),
184-
new MakerZIP({}, ["darwin", "linux", "win32"]),
185+
new MakerSquirrel({
186+
name: "PostHogCode",
187+
setupIcon: "./build/app-icon.ico",
188+
}),
189+
new MakerZIP({}, ["darwin", "linux"]),
185190
],
186191
hooks: {
187192
generateAssets: async () => {
188-
const isNewer = (src: string, dest: string) =>
189-
!existsSync(dest) || statSync(src).mtimeMs > statSync(dest).mtimeMs;
193+
if (process.platform !== "darwin") return;
190194

191195
if (
192196
existsSync("build/app-icon.png") &&
193-
isNewer("build/app-icon.png", "build/app-icon.icns")
197+
!existsSync("build/app-icon.icns")
194198
) {
195199
execSync("bash scripts/generate-icns.sh", { stdio: "inherit" });
196200
}
197201

198-
if (
199-
existsSync("build/icon.icon") &&
200-
isNewer("build/icon.icon/icon.json", "build/Assets.car")
201-
) {
202+
if (existsSync("build/icon.icon") && !existsSync("build/Assets.car")) {
202203
execSync("bash scripts/compile-glass-icon.sh", { stdio: "inherit" });
203204
}
204205
},
205206
prePackage: async () => {
207+
if (process.platform !== "darwin") return;
208+
206209
// Build native modules for DMG maker on Node.js 22
207210
const modules = ["macos-alias", "fs-xattr"];
208211

@@ -221,9 +224,20 @@ const config: ForgeConfig = {
221224
copyNativeDependency("node-pty", buildPath);
222225
copyNativeDependency("node-addon-api", buildPath);
223226
copyNativeDependency("@parcel/watcher", buildPath);
224-
copyNativeDependency("@parcel/watcher-darwin-arm64", buildPath);
225-
copyNativeDependency("file-icon", buildPath);
226-
copyNativeDependency("p-map", buildPath);
227+
228+
// Platform-specific native dependencies
229+
if (process.platform === "darwin") {
230+
copyNativeDependency("@parcel/watcher-darwin-arm64", buildPath);
231+
copyNativeDependency("file-icon", buildPath);
232+
copyNativeDependency("p-map", buildPath);
233+
} else if (process.platform === "win32") {
234+
const watcherPkg =
235+
process.arch === "arm64"
236+
? "@parcel/watcher-win32-arm64"
237+
: "@parcel/watcher-win32-x64";
238+
copyNativeDependency(watcherPkg, buildPath);
239+
}
240+
227241
// Copy @parcel/watcher's hoisted dependencies
228242
copyNativeDependency("micromatch", buildPath);
229243
copyNativeDependency("is-glob", buildPath);

apps/code/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"postinstall": "bash scripts/postinstall.sh",
2929
"storybook": "storybook dev -p 6006",
3030
"build-storybook": "storybook build",
31-
"clean": "rm -rf .vite .turbo out node_modules/.vite",
31+
"clean": "node ../../scripts/rimraf.mjs .vite .turbo out node_modules/.vite",
3232
"db:generate": "drizzle-kit generate",
3333
"db:migrate": "drizzle-kit migrate",
3434
"db:view": "drizzle-kit studio"
@@ -45,6 +45,7 @@
4545
"@biomejs/biome": "2.2.4",
4646
"@electron-forge/cli": "^7.11.1",
4747
"@electron-forge/maker-dmg": "^7.11.1",
48+
"@electron-forge/maker-squirrel": "^7.11.1",
4849
"@electron-forge/maker-zip": "^7.11.1",
4950
"@electron-forge/plugin-vite": "^7.11.1",
5051
"@electron-forge/publisher-github": "^7.11.1",

apps/code/src/main/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ const handleShutdownSignal = async (signal: string) => {
152152

153153
process.on("SIGTERM", () => handleShutdownSignal("SIGTERM"));
154154
process.on("SIGINT", () => handleShutdownSignal("SIGINT"));
155-
process.on("SIGHUP", () => handleShutdownSignal("SIGHUP"));
155+
if (process.platform !== "win32") {
156+
process.on("SIGHUP", () => handleShutdownSignal("SIGHUP"));
157+
}
156158

157159
process.on("uncaughtException", (error) => {
158160
if (error.message === "write EIO") {

0 commit comments

Comments
 (0)