Skip to content

Commit cbabeb5

Browse files
committed
fix: run dev and prod at the same time
1 parent ad85ad6 commit cbabeb5

9 files changed

Lines changed: 52 additions & 36 deletions

File tree

apps/array/forge.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ const config: ForgeConfig = {
230230
new VitePlugin({
231231
build: [
232232
{
233-
entry: "src/main/index.ts",
233+
entry: "src/main/bootstrap.ts",
234234
config: "vite.main.config.mts",
235235
target: "main",
236236
},

apps/array/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@posthog/array",
33
"version": "0.0.0-dev",
44
"description": "Array - PostHog desktop task manager",
5-
"main": ".vite/build/index.js",
5+
"main": ".vite/build/bootstrap.js",
66
"versionHash": "dynamic",
77
"engines": {
88
"node": ">=22.0.0",
@@ -22,7 +22,7 @@
2222
"typecheck": "tsc -p tsconfig.node.json --noEmit && tsc -p tsconfig.web.json --noEmit",
2323
"generate-client": "tsx scripts/update-openapi-client.ts",
2424
"test": "vitest run",
25-
"postinstall": "cd ../.. && npx @electron/rebuild -f -m node_modules/node-pty || true"
25+
"postinstall": "cd ../.. && npx @electron/rebuild -f -m node_modules/node-pty || true && bash apps/array/scripts/patch-electron-name.sh"
2626
},
2727
"keywords": [
2828
"posthog",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# Patches the Electron binary's Info.plist to show "Array (Development)" in the macOS menu bar
3+
4+
set -e
5+
6+
REPO_ROOT="$(git rev-parse --show-toplevel)"
7+
PLIST_FILE="$REPO_ROOT/node_modules/electron/dist/Electron.app/Contents/Info.plist"
8+
9+
if [ ! -f "$PLIST_FILE" ]; then
10+
exit 0
11+
fi
12+
13+
if /usr/libexec/PlistBuddy -c "Print :CFBundleName" "$PLIST_FILE" | grep -q "Array (Development)"; then
14+
exit 0
15+
fi
16+
17+
/usr/libexec/PlistBuddy -c "Set :CFBundleName 'Array (Development)'" "$PLIST_FILE"
18+
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName 'Array (Development)'" "$PLIST_FILE"
19+
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier 'com.posthog.array.dev'" "$PLIST_FILE"

apps/array/src/main/bootstrap.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Bootstrap entry point - sets userData path before any service initialization.
3+
*
4+
* This MUST be the entry point for both dev and prod builds. It ensures the
5+
* userData path is set BEFORE any imports that might trigger electron-store
6+
* instantiation (which calls app.getPath('userData') in their constructors).
7+
*
8+
*/
9+
import path from "node:path";
10+
import { app } from "electron";
11+
12+
const isDev = !app.isPackaged;
13+
14+
// Set different app names for separate single-instance locks
15+
const appName = isDev ? "array-dev" : "Array";
16+
app.setName(isDev ? "Array (Development)" : "Array");
17+
18+
const userDataPath = path.join(app.getPath("appData"), "@posthog", appName);
19+
app.setPath("userData", userDataPath);
20+
21+
// Now dynamically import the rest of the application
22+
// Dynamic import ensures the path is set BEFORE index.js is evaluated
23+
// Static imports are hoisted and would run before our setPath() call
24+
import("./index.js");

apps/array/src/main/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ let mainWindow: BrowserWindow | null = null;
5252
// instead of ::1. This matches how the renderer already reaches the PostHog API.
5353
dns.setDefaultResultOrder("ipv4first");
5454

55-
// Set app name to ensure consistent userData path across platforms
56-
app.setName("Array");
57-
5855
// Single instance lock must be acquired FIRST before any other app setup
5956
// This ensures deep links go to the existing instance, not a new one
6057
// In development, we need to pass the same args that setAsDefaultProtocolClient uses

apps/array/src/main/services/external-apps/service.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { exec } from "node:child_process";
22
import fs from "node:fs/promises";
3-
import path from "node:path";
43
import { promisify } from "node:util";
54
import { app, clipboard } from "electron";
65
import Store from "electron-store";
@@ -63,21 +62,13 @@ export class ExternalAppsService {
6362
constructor() {
6463
this.prefsStore = new Store<ExternalAppsSchema>({
6564
name: "external-apps",
66-
cwd: this.getStorePath(),
65+
cwd: app.getPath("userData"),
6766
defaults: {
6867
externalAppsPrefs: {},
6968
},
7069
});
7170
}
7271

73-
private getStorePath(): string {
74-
const userDataPath = app.getPath("userData");
75-
if (userDataPath.includes("@posthog")) {
76-
return path.join(path.dirname(userDataPath), "Array");
77-
}
78-
return userDataPath;
79-
}
80-
8172
private async getFileIcon() {
8273
if (!this.fileIconModule) {
8374
this.fileIconModule = await import("file-icon");

apps/array/src/main/services/settingsStore.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ interface SettingsSchema {
77
worktreeLocation: string;
88
}
99

10-
function getStorePath(): string {
11-
const userDataPath = app.getPath("userData");
12-
if (userDataPath.includes("@posthog")) {
13-
return path.join(path.dirname(userDataPath), "Array");
14-
}
15-
return userDataPath;
16-
}
17-
1810
function getDefaultWorktreeLocation(): string {
1911
return path.join(os.homedir(), ".array");
2012
}
@@ -29,7 +21,7 @@ const schema = {
2921
export const settingsStore = new Store<SettingsSchema>({
3022
name: "settings",
3123
schema,
32-
cwd: getStorePath(),
24+
cwd: app.getPath("userData"),
3325
defaults: {
3426
worktreeLocation: getDefaultWorktreeLocation(),
3527
},

apps/array/src/main/utils/store.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import path from "node:path";
21
import { WorktreeManager } from "@posthog/agent";
32
import { app } from "electron";
43
import Store from "electron-store";
@@ -59,23 +58,15 @@ const schema = {
5958
},
6059
};
6160

62-
function getStorePath(): string {
63-
const userDataPath = app.getPath("userData");
64-
if (userDataPath.includes("@posthog")) {
65-
return path.join(path.dirname(userDataPath), "Array");
66-
}
67-
return userDataPath;
68-
}
69-
7061
export const rendererStore = new Store<RendererStoreSchema>({
7162
name: "renderer-storage",
72-
cwd: getStorePath(),
63+
cwd: app.getPath("userData"),
7364
});
7465

7566
export const foldersStore = new Store<FoldersSchema>({
7667
name: "folders",
7768
schema,
78-
cwd: getStorePath(),
69+
cwd: app.getPath("userData"),
7970
defaults: {
8071
folders: [],
8172
taskAssociations: [],

apps/array/src/renderer/main.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import React from "react";
66
import ReactDOM from "react-dom/client";
77
import "./styles/globals.css";
88

9+
document.title = import.meta.env.DEV ? "Array (Development)" : "Array";
10+
911
const rootElement = document.getElementById("root");
1012
if (!rootElement) throw new Error("Root element not found");
1113

0 commit comments

Comments
 (0)