@web-auto/camo 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +586 -586
  3. package/bin/browser-service.mjs +11 -11
  4. package/bin/camo.mjs +22 -22
  5. package/package.json +48 -48
  6. package/scripts/build.mjs +19 -19
  7. package/scripts/bump-version.mjs +34 -34
  8. package/scripts/check-file-size.mjs +80 -80
  9. package/scripts/file-size-policy.json +12 -2
  10. package/scripts/install.mjs +76 -76
  11. package/scripts/release.sh +54 -54
  12. package/src/autoscript/action-providers/index.mjs +6 -6
  13. package/src/autoscript/impact-engine.mjs +78 -78
  14. package/src/autoscript/runtime.mjs +1017 -1017
  15. package/src/autoscript/schema.mjs +376 -376
  16. package/src/cli.mjs +405 -405
  17. package/src/commands/attach.mjs +141 -141
  18. package/src/commands/autoscript.mjs +1011 -1011
  19. package/src/commands/browser.mjs +1255 -1255
  20. package/src/commands/container.mjs +401 -401
  21. package/src/commands/cookies.mjs +69 -69
  22. package/src/commands/create.mjs +98 -98
  23. package/src/commands/devtools.mjs +349 -349
  24. package/src/commands/events.mjs +152 -152
  25. package/src/commands/highlight-mode.mjs +24 -24
  26. package/src/commands/init.mjs +68 -68
  27. package/src/commands/lifecycle.mjs +275 -275
  28. package/src/commands/mouse.mjs +45 -45
  29. package/src/commands/profile.mjs +46 -46
  30. package/src/commands/record.mjs +115 -115
  31. package/src/commands/system.mjs +14 -14
  32. package/src/commands/window.mjs +123 -123
  33. package/src/container/change-notifier.mjs +362 -362
  34. package/src/container/element-filter.mjs +143 -143
  35. package/src/container/index.mjs +3 -3
  36. package/src/container/runtime-core/checkpoint.mjs +209 -209
  37. package/src/container/runtime-core/index.mjs +21 -21
  38. package/src/container/runtime-core/operations/index.mjs +774 -774
  39. package/src/container/runtime-core/operations/selector-scripts.mjs +277 -277
  40. package/src/container/runtime-core/operations/tab-pool.mjs +746 -746
  41. package/src/container/runtime-core/operations/viewport.mjs +189 -189
  42. package/src/container/runtime-core/search.mjs +190 -190
  43. package/src/container/runtime-core/subscription.mjs +224 -224
  44. package/src/container/runtime-core/utils.mjs +94 -94
  45. package/src/container/runtime-core/validation.mjs +127 -127
  46. package/src/container/runtime-core.mjs +1 -1
  47. package/src/container/subscription-registry.mjs +459 -459
  48. package/src/core/actions.mjs +561 -561
  49. package/src/core/browser.mjs +266 -266
  50. package/src/core/index.mjs +52 -52
  51. package/src/core/utils.mjs +91 -91
  52. package/src/events/daemon-entry.mjs +33 -33
  53. package/src/events/daemon.mjs +80 -80
  54. package/src/events/progress-log.mjs +109 -109
  55. package/src/events/ws-server.mjs +239 -239
  56. package/src/lib/client.mjs +200 -200
  57. package/src/lifecycle/cleanup.mjs +83 -83
  58. package/src/lifecycle/lock.mjs +126 -126
  59. package/src/lifecycle/session-registry.mjs +279 -279
  60. package/src/lifecycle/session-view.mjs +76 -76
  61. package/src/lifecycle/session-watchdog.mjs +281 -281
  62. package/src/services/browser-service/index.js +671 -671
  63. package/src/services/browser-service/internal/BrowserSession.input.test.js +389 -389
  64. package/src/services/browser-service/internal/BrowserSession.js +325 -304
  65. package/src/services/browser-service/internal/ElementRegistry.js +60 -60
  66. package/src/services/browser-service/internal/ProfileLock.js +84 -84
  67. package/src/services/browser-service/internal/SessionManager.js +184 -184
  68. package/src/services/browser-service/internal/SessionManager.test.js +39 -39
  69. package/src/services/browser-service/internal/browser-session/cookies.js +144 -144
  70. package/src/services/browser-service/internal/browser-session/input-ops.js +222 -222
  71. package/src/services/browser-service/internal/browser-session/input-pipeline.js +144 -144
  72. package/src/services/browser-service/internal/browser-session/logging.js +46 -46
  73. package/src/services/browser-service/internal/browser-session/navigation.js +38 -38
  74. package/src/services/browser-service/internal/browser-session/page-hooks.js +442 -442
  75. package/src/services/browser-service/internal/browser-session/page-management.js +302 -302
  76. package/src/services/browser-service/internal/browser-session/page-management.test.js +148 -148
  77. package/src/services/browser-service/internal/browser-session/recording.js +198 -198
  78. package/src/services/browser-service/internal/browser-session/runtime-events.js +61 -61
  79. package/src/services/browser-service/internal/browser-session/session-core.js +84 -84
  80. package/src/services/browser-service/internal/browser-session/session-state.js +38 -38
  81. package/src/services/browser-service/internal/browser-session/types.js +14 -14
  82. package/src/services/browser-service/internal/browser-session/utils.js +95 -95
  83. package/src/services/browser-service/internal/browser-session/viewport-manager.js +46 -46
  84. package/src/services/browser-service/internal/browser-session/viewport.js +215 -215
  85. package/src/services/browser-service/internal/container-matcher.js +851 -851
  86. package/src/services/browser-service/internal/container-registry.js +182 -182
  87. package/src/services/browser-service/internal/engine-manager.js +259 -259
  88. package/src/services/browser-service/internal/fingerprint.js +203 -203
  89. package/src/services/browser-service/internal/heartbeat.js +137 -137
  90. package/src/services/browser-service/internal/logging.js +46 -46
  91. package/src/services/browser-service/internal/page-runtime/runtime.js +1317 -1317
  92. package/src/services/browser-service/internal/pageRuntime.js +28 -28
  93. package/src/services/browser-service/internal/runtimeInjector.js +31 -31
  94. package/src/services/browser-service/internal/service-process-logger.js +140 -140
  95. package/src/services/browser-service/internal/state-bus.js +45 -45
  96. package/src/services/browser-service/internal/storage-paths.js +42 -42
  97. package/src/services/browser-service/internal/ws-server.js +1194 -1194
  98. package/src/services/browser-service/internal/ws-server.test.js +58 -58
  99. package/src/services/browser-service/server.mjs +6 -6
  100. package/src/services/controller/cli-bridge.js +93 -93
  101. package/src/services/controller/container-index.js +50 -50
  102. package/src/services/controller/container-storage.js +36 -36
  103. package/src/services/controller/controller-actions.js +207 -207
  104. package/src/services/controller/controller.js +1138 -1138
  105. package/src/services/controller/selectors.js +54 -54
  106. package/src/services/controller/transport.js +125 -125
  107. package/src/utils/args.mjs +26 -26
  108. package/src/utils/browser-service.mjs +544 -544
  109. package/src/utils/command-log.mjs +64 -64
  110. package/src/utils/config.mjs +214 -214
  111. package/src/utils/fingerprint.mjs +181 -181
  112. package/src/utils/help.mjs +216 -216
  113. package/src/utils/js-policy.mjs +13 -13
  114. package/src/utils/ws-client.mjs +30 -30
@@ -1,29 +1,29 @@
1
- import { injectRuntimeBundle } from './runtimeInjector.js';
2
- const injectedPages = new WeakSet();
3
- export async function ensurePageRuntime(page, forceReinject = false) {
4
- if (!page) {
5
- throw new Error('page is required');
6
- }
7
- // 强制重新注入或首次注入
8
- if (forceReinject || !injectedPages.has(page)) {
9
- await injectRuntimeBundle({ page });
10
- injectedPages.add(page);
11
- }
12
- try {
13
- await page.waitForFunction(() => Boolean(window.__camoRuntime && window.__camoRuntime.ready), {
14
- timeout: 4000,
15
- });
16
- }
17
- catch (err) {
18
- // Runtime is best-effort for system-level mouse/keyboard commands.
19
- // If injection readiness times out (common on slow/heavy pages), we must not block
20
- // low-level commands like mouse:click/mouse:wheel.
21
- // Higher-level operations (containers:match, overlay highlight) will handle their own retries.
22
- return;
23
- }
24
- }
25
- export async function evalPageRuntime(page, fn) {
26
- await ensurePageRuntime(page);
27
- return page.evaluate(fn);
28
- }
1
+ import { injectRuntimeBundle } from './runtimeInjector.js';
2
+ const injectedPages = new WeakSet();
3
+ export async function ensurePageRuntime(page, forceReinject = false) {
4
+ if (!page) {
5
+ throw new Error('page is required');
6
+ }
7
+ // 强制重新注入或首次注入
8
+ if (forceReinject || !injectedPages.has(page)) {
9
+ await injectRuntimeBundle({ page });
10
+ injectedPages.add(page);
11
+ }
12
+ try {
13
+ await page.waitForFunction(() => Boolean(window.__camoRuntime && window.__camoRuntime.ready), {
14
+ timeout: 4000,
15
+ });
16
+ }
17
+ catch (err) {
18
+ // Runtime is best-effort for system-level mouse/keyboard commands.
19
+ // If injection readiness times out (common on slow/heavy pages), we must not block
20
+ // low-level commands like mouse:click/mouse:wheel.
21
+ // Higher-level operations (containers:match, overlay highlight) will handle their own retries.
22
+ return;
23
+ }
24
+ }
25
+ export async function evalPageRuntime(page, fn) {
26
+ await ensurePageRuntime(page);
27
+ return page.evaluate(fn);
28
+ }
29
29
  //# sourceMappingURL=pageRuntime.js.map
@@ -1,31 +1,31 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
4
- let resolvedRuntimePath = null;
5
- function resolveRuntime() {
6
- if (resolvedRuntimePath)
7
- return resolvedRuntimePath;
8
- const base = path.dirname(fileURLToPath(import.meta.url));
9
- const candidates = [
10
- path.join(process.cwd(), 'modules/camo-backend/src/internal/page-runtime/runtime.js'),
11
- path.join(process.cwd(), 'src/services/browser-service/internal/page-runtime/runtime.js'),
12
- path.join(base, 'page-runtime/runtime.js'),
13
- ];
14
- for (const candidate of candidates) {
15
- if (fs.existsSync(candidate)) {
16
- resolvedRuntimePath = candidate;
17
- break;
18
- }
19
- }
20
- if (!resolvedRuntimePath) {
21
- throw new Error('Runtime script not found');
22
- }
23
- return resolvedRuntimePath;
24
- }
25
- export async function injectRuntimeBundle({ page }) {
26
- const runtimePath = resolveRuntime();
27
- console.log(`[runtimeInjector] injecting runtime from ${runtimePath}`);
28
- await page.addInitScript({ path: runtimePath });
29
- await page.addScriptTag({ path: runtimePath });
30
- }
31
- //# sourceMappingURL=runtimeInjector.js.map
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ let resolvedRuntimePath = null;
5
+ function resolveRuntime() {
6
+ if (resolvedRuntimePath)
7
+ return resolvedRuntimePath;
8
+ const base = path.dirname(fileURLToPath(import.meta.url));
9
+ const candidates = [
10
+ path.join(process.cwd(), 'modules/camo-backend/src/internal/page-runtime/runtime.js'),
11
+ path.join(process.cwd(), 'src/services/browser-service/internal/page-runtime/runtime.js'),
12
+ path.join(base, 'page-runtime/runtime.js'),
13
+ ];
14
+ for (const candidate of candidates) {
15
+ if (fs.existsSync(candidate)) {
16
+ resolvedRuntimePath = candidate;
17
+ break;
18
+ }
19
+ }
20
+ if (!resolvedRuntimePath) {
21
+ throw new Error('Runtime script not found');
22
+ }
23
+ return resolvedRuntimePath;
24
+ }
25
+ export async function injectRuntimeBundle({ page }) {
26
+ const runtimePath = resolveRuntime();
27
+ console.log(`[runtimeInjector] injecting runtime from ${runtimePath}`);
28
+ await page.addInitScript({ path: runtimePath });
29
+ await page.addScriptTag({ path: runtimePath });
30
+ }
31
+ //# sourceMappingURL=runtimeInjector.js.map
@@ -1,140 +1,140 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { CONFIG_DIR, ensureDir } from '../../../utils/config.mjs';
4
-
5
- const LOG_DIR = String(process.env.CAMO_LOG_DIR || '').trim() || path.join(CONFIG_DIR, 'logs');
6
- const INSTALLED = new Set();
7
-
8
- function safeAppend(filePath, line) {
9
- try {
10
- fs.appendFileSync(filePath, line, 'utf8');
11
- } catch {
12
- // ignore
13
- }
14
- }
15
-
16
- function formatError(err) {
17
- if (!err || typeof err !== 'object') return { message: String(err) };
18
- const anyErr = err;
19
- return {
20
- name: typeof anyErr.name === 'string' ? anyErr.name : undefined,
21
- message: typeof anyErr.message === 'string' ? anyErr.message : String(err),
22
- stack: typeof anyErr.stack === 'string' ? anyErr.stack : undefined,
23
- code: typeof anyErr.code === 'string' ? anyErr.code : undefined,
24
- };
25
- }
26
-
27
- function createConsoleTee(logFile) {
28
- const kWrapped = Symbol.for('camo.consoleTeeWrapped');
29
- const g = globalThis;
30
- if (g[kWrapped]) return;
31
- g[kWrapped] = true;
32
-
33
- const originals = {
34
- log: console.log.bind(console),
35
- info: console.info.bind(console),
36
- warn: console.warn.bind(console),
37
- error: console.error.bind(console),
38
- };
39
-
40
- const wrap = (level) => {
41
- return (...args) => {
42
- const ts = new Date().toISOString();
43
- const msg = args
44
- .map((a) => {
45
- if (typeof a === 'string') return a;
46
- try {
47
- return JSON.stringify(a);
48
- } catch {
49
- return String(a);
50
- }
51
- })
52
- .join(' ');
53
- safeAppend(logFile, `[${ts}] [${String(level).toUpperCase()}] ${msg}\n`);
54
- originals[level](...args);
55
- };
56
- };
57
-
58
- console.log = wrap('log');
59
- console.info = wrap('info');
60
- console.warn = wrap('warn');
61
- console.error = wrap('error');
62
- }
63
-
64
- export function installServiceProcessLogger(opts = {}) {
65
- const serviceName = String(opts.serviceName || '').trim();
66
- const id = `service:${serviceName}`;
67
- if (!serviceName) return { logEvent: () => {} };
68
- if (INSTALLED.has(id)) return { logEvent: () => {} };
69
- INSTALLED.add(id);
70
-
71
- ensureDir(LOG_DIR);
72
- const crashFile = path.join(LOG_DIR, `${serviceName}.crash.jsonl`);
73
- const consoleLogFile = path.join(LOG_DIR, `${serviceName}.log`);
74
-
75
- const tee = typeof opts.teeConsoleToFile === 'boolean'
76
- ? opts.teeConsoleToFile
77
- : !!(process.stdout.isTTY || process.stderr.isTTY);
78
- if (tee) createConsoleTee(consoleLogFile);
79
-
80
- const base = {
81
- service: serviceName,
82
- pid: process.pid,
83
- node: process.version,
84
- };
85
-
86
- const logEvent = (event, data = {}) => {
87
- safeAppend(
88
- crashFile,
89
- `${JSON.stringify({
90
- ts: new Date().toISOString(),
91
- ...base,
92
- event,
93
- ...data,
94
- })}\n`,
95
- );
96
- };
97
-
98
- logEvent('process_start', {
99
- argv: process.argv,
100
- cwd: process.cwd(),
101
- ppid: process.ppid,
102
- stdoutIsTTY: !!process.stdout.isTTY,
103
- stderrIsTTY: !!process.stderr.isTTY,
104
- });
105
-
106
- process.on('uncaughtException', (err) => {
107
- logEvent('uncaughtException', { error: formatError(err) });
108
- process.exitCode = 1;
109
- });
110
-
111
- process.on('unhandledRejection', (reason) => {
112
- logEvent('unhandledRejection', { reason: formatError(reason) });
113
- process.exitCode = 1;
114
- });
115
-
116
- const tapSignal = (signal) => {
117
- const hadExisting = process.listenerCount(signal) > 0;
118
- const handler = () => {
119
- logEvent('signal', { signal });
120
- process.off(signal, handler);
121
- if (!hadExisting) {
122
- try {
123
- process.kill(process.pid, signal);
124
- } catch {
125
- // ignore
126
- }
127
- }
128
- };
129
- process.on(signal, handler);
130
- };
131
-
132
- tapSignal('SIGINT');
133
- tapSignal('SIGTERM');
134
- tapSignal('SIGHUP');
135
-
136
- process.on('beforeExit', (code) => logEvent('beforeExit', { code }));
137
- process.on('exit', (code) => logEvent('exit', { code }));
138
-
139
- return { logEvent };
140
- }
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { CONFIG_DIR, ensureDir } from '../../../utils/config.mjs';
4
+
5
+ const LOG_DIR = String(process.env.CAMO_LOG_DIR || '').trim() || path.join(CONFIG_DIR, 'logs');
6
+ const INSTALLED = new Set();
7
+
8
+ function safeAppend(filePath, line) {
9
+ try {
10
+ fs.appendFileSync(filePath, line, 'utf8');
11
+ } catch {
12
+ // ignore
13
+ }
14
+ }
15
+
16
+ function formatError(err) {
17
+ if (!err || typeof err !== 'object') return { message: String(err) };
18
+ const anyErr = err;
19
+ return {
20
+ name: typeof anyErr.name === 'string' ? anyErr.name : undefined,
21
+ message: typeof anyErr.message === 'string' ? anyErr.message : String(err),
22
+ stack: typeof anyErr.stack === 'string' ? anyErr.stack : undefined,
23
+ code: typeof anyErr.code === 'string' ? anyErr.code : undefined,
24
+ };
25
+ }
26
+
27
+ function createConsoleTee(logFile) {
28
+ const kWrapped = Symbol.for('camo.consoleTeeWrapped');
29
+ const g = globalThis;
30
+ if (g[kWrapped]) return;
31
+ g[kWrapped] = true;
32
+
33
+ const originals = {
34
+ log: console.log.bind(console),
35
+ info: console.info.bind(console),
36
+ warn: console.warn.bind(console),
37
+ error: console.error.bind(console),
38
+ };
39
+
40
+ const wrap = (level) => {
41
+ return (...args) => {
42
+ const ts = new Date().toISOString();
43
+ const msg = args
44
+ .map((a) => {
45
+ if (typeof a === 'string') return a;
46
+ try {
47
+ return JSON.stringify(a);
48
+ } catch {
49
+ return String(a);
50
+ }
51
+ })
52
+ .join(' ');
53
+ safeAppend(logFile, `[${ts}] [${String(level).toUpperCase()}] ${msg}\n`);
54
+ originals[level](...args);
55
+ };
56
+ };
57
+
58
+ console.log = wrap('log');
59
+ console.info = wrap('info');
60
+ console.warn = wrap('warn');
61
+ console.error = wrap('error');
62
+ }
63
+
64
+ export function installServiceProcessLogger(opts = {}) {
65
+ const serviceName = String(opts.serviceName || '').trim();
66
+ const id = `service:${serviceName}`;
67
+ if (!serviceName) return { logEvent: () => {} };
68
+ if (INSTALLED.has(id)) return { logEvent: () => {} };
69
+ INSTALLED.add(id);
70
+
71
+ ensureDir(LOG_DIR);
72
+ const crashFile = path.join(LOG_DIR, `${serviceName}.crash.jsonl`);
73
+ const consoleLogFile = path.join(LOG_DIR, `${serviceName}.log`);
74
+
75
+ const tee = typeof opts.teeConsoleToFile === 'boolean'
76
+ ? opts.teeConsoleToFile
77
+ : !!(process.stdout.isTTY || process.stderr.isTTY);
78
+ if (tee) createConsoleTee(consoleLogFile);
79
+
80
+ const base = {
81
+ service: serviceName,
82
+ pid: process.pid,
83
+ node: process.version,
84
+ };
85
+
86
+ const logEvent = (event, data = {}) => {
87
+ safeAppend(
88
+ crashFile,
89
+ `${JSON.stringify({
90
+ ts: new Date().toISOString(),
91
+ ...base,
92
+ event,
93
+ ...data,
94
+ })}\n`,
95
+ );
96
+ };
97
+
98
+ logEvent('process_start', {
99
+ argv: process.argv,
100
+ cwd: process.cwd(),
101
+ ppid: process.ppid,
102
+ stdoutIsTTY: !!process.stdout.isTTY,
103
+ stderrIsTTY: !!process.stderr.isTTY,
104
+ });
105
+
106
+ process.on('uncaughtException', (err) => {
107
+ logEvent('uncaughtException', { error: formatError(err) });
108
+ process.exitCode = 1;
109
+ });
110
+
111
+ process.on('unhandledRejection', (reason) => {
112
+ logEvent('unhandledRejection', { reason: formatError(reason) });
113
+ process.exitCode = 1;
114
+ });
115
+
116
+ const tapSignal = (signal) => {
117
+ const hadExisting = process.listenerCount(signal) > 0;
118
+ const handler = () => {
119
+ logEvent('signal', { signal });
120
+ process.off(signal, handler);
121
+ if (!hadExisting) {
122
+ try {
123
+ process.kill(process.pid, signal);
124
+ } catch {
125
+ // ignore
126
+ }
127
+ }
128
+ };
129
+ process.on(signal, handler);
130
+ };
131
+
132
+ tapSignal('SIGINT');
133
+ tapSignal('SIGTERM');
134
+ tapSignal('SIGHUP');
135
+
136
+ process.on('beforeExit', (code) => logEvent('beforeExit', { code }));
137
+ process.on('exit', (code) => logEvent('exit', { code }));
138
+
139
+ return { logEvent };
140
+ }
@@ -1,46 +1,46 @@
1
- class LocalStateBus {
2
- state = new Map();
3
- subscribers = new Map();
4
- setState(key, payload) {
5
- this.state.set(key, { ...payload, lastUpdate: Date.now() });
6
- this.publish(`state:${key}`, this.state.get(key));
7
- }
8
- getState(key) {
9
- if (key)
10
- return this.state.get(key);
11
- return Object.fromEntries(this.state);
12
- }
13
- publish(event, payload) {
14
- const listeners = this.subscribers.get(event) || [];
15
- for (const listener of listeners) {
16
- try {
17
- listener(payload);
18
- }
19
- catch {
20
- // Keep runtime event pipeline resilient.
21
- }
22
- }
23
- }
24
- subscribe(event, listener) {
25
- const current = this.subscribers.get(event) || [];
26
- current.push(listener);
27
- this.subscribers.set(event, current);
28
- return () => {
29
- const next = (this.subscribers.get(event) || []).filter((fn) => fn !== listener);
30
- if (next.length === 0) {
31
- this.subscribers.delete(event);
32
- }
33
- else {
34
- this.subscribers.set(event, next);
35
- }
36
- };
37
- }
38
- }
39
- let stateBus = null;
40
- export function getStateBus() {
41
- if (!stateBus)
42
- stateBus = new LocalStateBus();
43
- return stateBus;
44
- }
45
- export { LocalStateBus };
1
+ class LocalStateBus {
2
+ state = new Map();
3
+ subscribers = new Map();
4
+ setState(key, payload) {
5
+ this.state.set(key, { ...payload, lastUpdate: Date.now() });
6
+ this.publish(`state:${key}`, this.state.get(key));
7
+ }
8
+ getState(key) {
9
+ if (key)
10
+ return this.state.get(key);
11
+ return Object.fromEntries(this.state);
12
+ }
13
+ publish(event, payload) {
14
+ const listeners = this.subscribers.get(event) || [];
15
+ for (const listener of listeners) {
16
+ try {
17
+ listener(payload);
18
+ }
19
+ catch {
20
+ // Keep runtime event pipeline resilient.
21
+ }
22
+ }
23
+ }
24
+ subscribe(event, listener) {
25
+ const current = this.subscribers.get(event) || [];
26
+ current.push(listener);
27
+ this.subscribers.set(event, current);
28
+ return () => {
29
+ const next = (this.subscribers.get(event) || []).filter((fn) => fn !== listener);
30
+ if (next.length === 0) {
31
+ this.subscribers.delete(event);
32
+ }
33
+ else {
34
+ this.subscribers.set(event, next);
35
+ }
36
+ };
37
+ }
38
+ }
39
+ let stateBus = null;
40
+ export function getStateBus() {
41
+ if (!stateBus)
42
+ stateBus = new LocalStateBus();
43
+ return stateBus;
44
+ }
45
+ export { LocalStateBus };
46
46
  //# sourceMappingURL=state-bus.js.map
@@ -1,42 +1,42 @@
1
- import os from 'os';
2
- import path from 'path';
3
- function resolveHomeDir() {
4
- const envHome = process.platform === 'win32'
5
- ? String(process.env.USERPROFILE || '').trim()
6
- : String(process.env.HOME || '').trim();
7
- return envHome || os.homedir();
8
- }
9
- function resolvePortableRoot() {
10
- return String(process.env.CAMO_PORTABLE_ROOT || process.env.CAMO_ROOT || '').trim();
11
- }
12
- function resolveDataRoot() {
13
- const portableRoot = resolvePortableRoot();
14
- if (portableRoot)
15
- return path.join(portableRoot, '.camo');
16
- return path.join(resolveHomeDir(), '.camo');
17
- }
18
- export function resolveProfilesRoot() {
19
- const envRoot = String(process.env.CAMO_PATHS_PROFILES || '').trim();
20
- if (envRoot)
21
- return envRoot;
22
- return path.join(resolveDataRoot(), 'profiles');
23
- }
24
- export function resolveCookiesRoot() {
25
- const envRoot = String(process.env.CAMO_PATHS_COOKIES || '').trim();
26
- if (envRoot)
27
- return envRoot;
28
- return path.join(resolveDataRoot(), 'cookies');
29
- }
30
- export function resolveLocksRoot() {
31
- const envRoot = String(process.env.CAMO_PATHS_LOCKS || '').trim();
32
- if (envRoot)
33
- return envRoot;
34
- return path.join(resolveDataRoot(), 'locks');
35
- }
36
- export function resolveRecordsRoot() {
37
- const envRoot = String(process.env.CAMO_PATHS_RECORDS || '').trim();
38
- if (envRoot)
39
- return envRoot;
40
- return path.join(resolveDataRoot(), 'records');
41
- }
42
- //# sourceMappingURL=storage-paths.js.map
1
+ import os from 'os';
2
+ import path from 'path';
3
+ function resolveHomeDir() {
4
+ const envHome = process.platform === 'win32'
5
+ ? String(process.env.USERPROFILE || '').trim()
6
+ : String(process.env.HOME || '').trim();
7
+ return envHome || os.homedir();
8
+ }
9
+ function resolvePortableRoot() {
10
+ return String(process.env.CAMO_PORTABLE_ROOT || process.env.CAMO_ROOT || '').trim();
11
+ }
12
+ function resolveDataRoot() {
13
+ const portableRoot = resolvePortableRoot();
14
+ if (portableRoot)
15
+ return path.join(portableRoot, '.camo');
16
+ return path.join(resolveHomeDir(), '.camo');
17
+ }
18
+ export function resolveProfilesRoot() {
19
+ const envRoot = String(process.env.CAMO_PATHS_PROFILES || '').trim();
20
+ if (envRoot)
21
+ return envRoot;
22
+ return path.join(resolveDataRoot(), 'profiles');
23
+ }
24
+ export function resolveCookiesRoot() {
25
+ const envRoot = String(process.env.CAMO_PATHS_COOKIES || '').trim();
26
+ if (envRoot)
27
+ return envRoot;
28
+ return path.join(resolveDataRoot(), 'cookies');
29
+ }
30
+ export function resolveLocksRoot() {
31
+ const envRoot = String(process.env.CAMO_PATHS_LOCKS || '').trim();
32
+ if (envRoot)
33
+ return envRoot;
34
+ return path.join(resolveDataRoot(), 'locks');
35
+ }
36
+ export function resolveRecordsRoot() {
37
+ const envRoot = String(process.env.CAMO_PATHS_RECORDS || '').trim();
38
+ if (envRoot)
39
+ return envRoot;
40
+ return path.join(resolveDataRoot(), 'records');
41
+ }
42
+ //# sourceMappingURL=storage-paths.js.map