@seekskyworld/open-browser 0.3.0 → 0.3.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.
- package/CONTRIBUTING.md +2 -0
- package/Docs/desktop-packages.md +45 -0
- package/Docs//350/267/250/345/271/263/345/217/260/350/257/225/347/224/250/344/270/216/345/217/221/350/241/214.md +1 -1
- package/README.md +8 -6
- package/README.zh-CN.md +2 -0
- package/api-contract.mjs +2 -1
- package/browser-extension/_locales/en/messages.json +8 -0
- package/browser-extension/_locales/zh_CN/messages.json +8 -0
- package/browser-extension/i18n.js +84 -0
- package/browser-extension/manifest.json +5 -4
- package/browser-extension/messages.js +266 -0
- package/browser-extension/newtab.css +4 -0
- package/browser-extension/newtab.html +9 -9
- package/browser-extension/newtab.js +38 -36
- package/browser-extension/page-locale.js +23 -0
- package/browser-extension/phase-labels.js +33 -6
- package/browser-extension/popup.css +2 -2
- package/browser-extension/popup.html +24 -26
- package/browser-extension/popup.js +72 -49
- package/browser-extension/tab-action.js +29 -24
- package/browser-extension/worker.js +29 -5
- package/browser-extension/workspace-title.js +2 -2
- package/build-profile.mjs +10 -2
- package/chromium-host.mjs +22 -11
- package/chromium-shell.mjs +5 -3
- package/cli.mjs +33 -30
- package/control.mjs +9 -8
- package/desktop/Info.plist +3 -1
- package/desktop/Launcher.m +10 -2
- package/desktop/OBControlBar.m +12 -8
- package/desktop/OBLocalization.h +20 -0
- package/desktop/OBPageView.m +2 -1
- package/desktop/WorkspacePanel.m +84 -83
- package/desktop/archive-release.py +5 -1
- package/desktop/build-macos.mjs +11 -5
- package/desktop/build-managed-input.mjs +2 -1
- package/desktop/build-portable.mjs +5 -3
- package/desktop/build-profile.mjs +2 -1
- package/desktop/build.mjs +2 -1
- package/desktop/create-shortcut.ps1 +7 -1
- package/desktop/en.lproj/Localizable.strings +106 -0
- package/desktop/install-menu-entry.mjs +2 -0
- package/desktop/notarize-macos.mjs +21 -24
- package/desktop/package-macos.mjs +4 -3
- package/desktop/sign.mjs +5 -4
- package/desktop/start-profile.mjs +2 -1
- package/desktop/start.mjs +3 -1
- package/desktop/verify-macos-release.mjs +9 -8
- package/desktop/zh-Hans.lproj/Localizable.strings +106 -0
- package/engine-service.mjs +1 -1
- package/hosted/cli.mjs +2 -1
- package/hosted/init.mjs +2 -1
- package/i18n.mjs +41 -0
- package/mcp-http.mjs +3 -2
- package/mcp-server.mjs +4 -3
- package/messages.zh-CN.mjs +175 -0
- package/package.json +4 -1
- package/page-activity.mjs +8 -6
- package/paths.mjs +2 -5
- package/runtime.mjs +4 -3
- package/sdk.mjs +40 -39
- package/service.mjs +2 -1
- package/skills/open-browser/SKILL.md +11 -9
- package/skills/open-browser/SKILL.zh-CN.md +22 -0
- package/skills/open-browser/references/macos.en.md +3 -0
- package/skills/open-browser/references/macos.md +2 -0
- package/skills/open-browser/references/operations.en.md +54 -0
- package/skills/open-browser/references/operations.md +2 -0
- package/skills/open-browser/references/recovery.en.md +36 -0
- package/skills/open-browser/references/recovery.md +2 -0
- package/skills/open-browser/references/windows.en.md +3 -0
- package/skills/open-browser/references/windows.md +2 -0
- package/skills/open-browser/scripts/bootstrap.mjs +6 -4
- package/skills/open-browser/scripts/guide.mjs +7 -4
- package/skills/open-browser/scripts/open-browser +5 -1
- package/studio/demo-site.mjs +5 -4
- package/studio/index.html +37 -33
- package/studio/index.mjs +10 -3
- package/studio/native-demo.mjs +8 -7
- package/studio/studio.css +3 -0
- package/studio/studio.js +98 -68
- package/system-i18n.mjs +19 -0
package/chromium-shell.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { interfaceLanguage, locale, t } from './i18n.mjs';
|
|
1
2
|
import { execFile } from 'node:child_process';
|
|
2
3
|
import { randomUUID } from 'node:crypto';
|
|
3
4
|
import { copyFile, link, lstat, mkdir, mkdtemp, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
@@ -52,7 +53,7 @@ async function macPersistentEngine() {
|
|
|
52
53
|
await run('/usr/bin/codesign', ['--verify', '-R=' + requirement, path.resolve(executable, '../../..')]);
|
|
53
54
|
return executable;
|
|
54
55
|
} catch (cause) {
|
|
55
|
-
throw new Error(
|
|
56
|
+
throw new Error(t("Persistent browsing on macOS requires an Open Browser v2 engine signed with Developer ID. Run npm run build in the project directory and restart."), { cause });
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -73,7 +74,7 @@ async function prepareProfile(profileDir) {
|
|
|
73
74
|
// Its existence is the migration record, even if the user later deletes all bookmarks.
|
|
74
75
|
await mkdir(stateDir, { recursive: true, mode: 0o700 });
|
|
75
76
|
try {
|
|
76
|
-
if (!(await lstat(profileDir)).isDirectory()) throw new Error(
|
|
77
|
+
if (!(await lstat(profileDir)).isDirectory()) throw new Error(t("Invalid Open Browser v2 profile directory."));
|
|
77
78
|
return;
|
|
78
79
|
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
79
80
|
const staging = await mkdtemp(path.join(stateDir, '.open-browser-profile-v2-'));
|
|
@@ -135,6 +136,7 @@ export async function launchChromiumShell({ profileDir = defaultProfile, headles
|
|
|
135
136
|
ignoreDefaultArgs: ['--disable-extensions', '--disable-popup-blocking',
|
|
136
137
|
...(!customEngine ? ['--use-mock-keychain', '--password-store=basic'] : [])],
|
|
137
138
|
args: [...chromiumPrivacyArgs(), ...(restoreSession ? ['--restore-last-session'] : []), '--load-extension=' + extensionDir, '--window-size=1240,860',
|
|
139
|
+
...(interfaceLanguage().preference !== 'system' || process.env.OPEN_BROWSER_LOCALE ? ['--lang=' + locale] : []),
|
|
138
140
|
...(process.platform === 'linux' ? ['--class=open-browser', '--name=open-browser'] : []),
|
|
139
141
|
...(netLogPath ? ['--log-net-log=' + netLogPath, '--net-log-capture-mode=Default'] : [])],
|
|
140
142
|
});
|
|
@@ -151,7 +153,7 @@ export async function launchChromiumShell({ profileDir = defaultProfile, headles
|
|
|
151
153
|
{url:marker,background:true,focus:false}).then(target => { targetId = target.targetId; })]);
|
|
152
154
|
await page.goto('chrome://settings/appearance');
|
|
153
155
|
const applied = await page.evaluate(() => chrome.settingsPrivate.setPref('bookmark_bar.show_tab_groups',false,''));
|
|
154
|
-
if (!applied) throw new Error(
|
|
156
|
+
if (!applied) throw new Error(t("Could not configure tab groups on the bookmarks bar."));
|
|
155
157
|
} catch (error) {
|
|
156
158
|
await context.close();
|
|
157
159
|
throw error;
|
package/cli.mjs
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { locale, t } from "./i18n.mjs";
|
|
2
3
|
import { writeFile } from 'node:fs/promises';
|
|
3
4
|
import { createInterface } from 'node:readline';
|
|
4
5
|
import { socketPath, adminTokenPath } from './paths.mjs';
|
|
5
6
|
import { localRequest, agentMethods, OpenBrowserClient, OpenBrowserError } from './sdk.mjs';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
function usage() {
|
|
9
|
+
const commands = agentMethods.join(locale === 'zh-CN' ? '、' : ', ');
|
|
10
|
+
const task = t("Page check");
|
|
11
|
+
return `open-browser <method> [< params.json]
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
${t("Read a JSON object from stdin and write the result to stdout.")}
|
|
14
|
+
${t("Available methods: {0}", commands)}
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
${t("Quick start")}
|
|
17
|
+
echo '{"url":"https://example.org","name":"${task}"}' | open-browser open
|
|
18
|
+
echo '{"workspaceId":"WORKSPACE_ID","pageId":"PAGE_ID"}' | open-browser observe
|
|
19
|
+
echo '{"workspaceId":"WORKSPACE_ID","operationId":"finish-UNIQUE-ID","keepPageIds":[]}' | open-browser finishWorkspace
|
|
16
20
|
|
|
17
|
-
open-browser --json <method> #
|
|
18
|
-
open-browser session
|
|
21
|
+
open-browser --json <method> # ${t("Print {result} or {error} to stdout and exit nonzero on failure.")}
|
|
22
|
+
open-browser session # ${t("Read one JSON request per line until stdin closes.")}
|
|
23
|
+
open-browser --schema # ${t("Show method names and parameter schemas.")}
|
|
24
|
+
open-browser skill # ${t("Show the skill guide for this package.")}
|
|
19
25
|
|
|
20
|
-
echo '{"name":"
|
|
21
|
-
echo '{"url":"https://example.org","name":"网页检查"}' | node cli.mjs open
|
|
26
|
+
echo '{"name":"${task}","agentName":"${t("Research assistant")}"}' | node cli.mjs createWorkspace
|
|
22
27
|
node cli.mjs listWorkspaces
|
|
23
28
|
echo '{"workspaceId":"WORKSPACE_ID","url":"https://example.org"}' | node cli.mjs openPage
|
|
24
|
-
echo '{"workspaceId":"WORKSPACE_ID","pageId":"PAGE_ID"}' | node cli.mjs observe
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
凭据在可信的本地控制台设置;使用 fillCredential 和 credentialRef 填写登录字段。
|
|
30
|
-
open-browser skill # 输出与当前包版本匹配的 Skill 指南
|
|
30
|
+
${t("Errors include code, message and an optional nextAction. After a timeout, query getOperation with the original operationId.")}
|
|
31
|
+
${t("Local admin commands: {0}", 'admin.pair, admin.list, admin.grant, admin.revoke, admin.revokeClient, admin.clearHistory, admin.scheduler, admin.setPixelPermission')}
|
|
32
|
+
${t("Bind credentials in the local console. Use fillCredential and credentialRef for sign-in fields.")}
|
|
31
33
|
`;
|
|
34
|
+
}
|
|
32
35
|
|
|
33
36
|
async function readParams() {
|
|
34
37
|
const chunks = [];
|
|
@@ -36,13 +39,13 @@ async function readParams() {
|
|
|
36
39
|
if (process.stdin.isTTY) return {};
|
|
37
40
|
for await (const chunk of process.stdin) {
|
|
38
41
|
bytes += chunk.length;
|
|
39
|
-
if (bytes > 1024 * 1024) throw new OpenBrowserError('REQUEST_TOO_LARGE',
|
|
42
|
+
if (bytes > 1024 * 1024) throw new OpenBrowserError('REQUEST_TOO_LARGE', t("Standard input exceeds 1 MiB."));
|
|
40
43
|
chunks.push(chunk);
|
|
41
44
|
}
|
|
42
45
|
const text = Buffer.concat(chunks).toString('utf8');
|
|
43
46
|
if (!text.trim()) return {};
|
|
44
47
|
try { return JSON.parse(text); }
|
|
45
|
-
catch { throw new OpenBrowserError('INVALID_JSON',
|
|
48
|
+
catch { throw new OpenBrowserError('INVALID_JSON', t("Standard input must contain a JSON object.")); }
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
async function sessionMain() {
|
|
@@ -53,11 +56,11 @@ async function sessionMain() {
|
|
|
53
56
|
input.on('line', line => {
|
|
54
57
|
tail = tail.then(async () => {
|
|
55
58
|
let frame;
|
|
56
|
-
try { frame = JSON.parse(line); } catch { send({ id: null, error: { code: 'INVALID_JSON', message:
|
|
59
|
+
try { frame = JSON.parse(line); } catch { send({ id: null, error: { code: 'INVALID_JSON', message: t("Each line must be a JSON request.") } }); return; }
|
|
57
60
|
const id = frame?.id;
|
|
58
61
|
if (!(typeof id === 'string' || Number.isSafeInteger(id)) || typeof frame?.method !== 'string' || !frame.method ||
|
|
59
62
|
(frame.params !== undefined && (!frame.params || typeof frame.params !== 'object' || Array.isArray(frame.params)))) {
|
|
60
|
-
send({ id: id ?? null, error: { code: 'INVALID_PARAMS', message:
|
|
63
|
+
send({ id: id ?? null, error: { code: 'INVALID_PARAMS', message: t("A session request needs an id, a method and a params object.") } });
|
|
61
64
|
return;
|
|
62
65
|
}
|
|
63
66
|
try {
|
|
@@ -82,9 +85,9 @@ function writeResult(result) {
|
|
|
82
85
|
async function main() {
|
|
83
86
|
const [method, ...extra] = process.argv.slice(jsonMode ? 3 : 2);
|
|
84
87
|
if (jsonMode && !agentMethods.includes(method) && !method?.startsWith('admin.'))
|
|
85
|
-
throw new OpenBrowserError('UNKNOWN_METHOD',
|
|
88
|
+
throw new OpenBrowserError('UNKNOWN_METHOD',t("--json requires an API method name."));
|
|
86
89
|
if (method === 'session') {
|
|
87
|
-
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS',
|
|
90
|
+
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS', t("session takes no additional arguments."));
|
|
88
91
|
await sessionMain();
|
|
89
92
|
return;
|
|
90
93
|
}
|
|
@@ -94,29 +97,29 @@ async function main() {
|
|
|
94
97
|
return;
|
|
95
98
|
}
|
|
96
99
|
if (method === 'skill') {
|
|
97
|
-
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS',
|
|
100
|
+
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS', t("skill takes no additional arguments."));
|
|
98
101
|
const { readSkillGuide } = await import('./skills/open-browser/scripts/guide.mjs');
|
|
99
102
|
process.stdout.write(await readSkillGuide());
|
|
100
103
|
return;
|
|
101
104
|
}
|
|
102
105
|
if (!method || method === '--help' || method === '-h') {
|
|
103
|
-
process.stdout.write(
|
|
106
|
+
process.stdout.write(usage());
|
|
104
107
|
return;
|
|
105
108
|
}
|
|
106
|
-
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS',
|
|
109
|
+
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS', t("Provide JSON parameters on standard input."));
|
|
107
110
|
if (method.startsWith('admin.')) {
|
|
108
|
-
if (process.env.OPEN_BROWSER_CLIENT_TOKEN_FILE) throw new OpenBrowserError('forbidden',
|
|
111
|
+
if (process.env.OPEN_BROWSER_CLIENT_TOKEN_FILE) throw new OpenBrowserError('forbidden', t("Run this command from a local administrator session."));
|
|
109
112
|
const params = await readParams();
|
|
110
113
|
const {tokenFile, ...args} = params;
|
|
111
114
|
const admin = (name, values) => localRequest(socketPath,adminTokenPath,'/v1/admin',name,values);
|
|
112
|
-
if (method === 'admin.pair' && (typeof tokenFile !== 'string' || !tokenFile)) throw new OpenBrowserError('INVALID_PARAMS',
|
|
115
|
+
if (method === 'admin.pair' && (typeof tokenFile !== 'string' || !tokenFile)) throw new OpenBrowserError('INVALID_PARAMS',t("Provide tokenFile as the path for the new token file."));
|
|
113
116
|
const result = await admin(method.slice(6),args);
|
|
114
117
|
if (method === 'admin.pair') {
|
|
115
118
|
try { await writeFile(tokenFile,result.token + '\n',{flag:'wx',mode:0o600}); }
|
|
116
119
|
catch (error) {
|
|
117
120
|
try { await admin('revokeClient', {principalId:result.principalId}); }
|
|
118
121
|
catch {
|
|
119
|
-
throw new OpenBrowserError('PAIR_CLEANUP_FAILED',
|
|
122
|
+
throw new OpenBrowserError('PAIR_CLEANUP_FAILED', t("Could not write the token file. Check and revoke {0} with admin.revokeClient.", result.principalId));
|
|
120
123
|
}
|
|
121
124
|
throw error;
|
|
122
125
|
}
|
|
@@ -125,7 +128,7 @@ async function main() {
|
|
|
125
128
|
writeResult(result);
|
|
126
129
|
return;
|
|
127
130
|
}
|
|
128
|
-
if (!agentMethods.includes(method)) throw new OpenBrowserError('UNKNOWN_METHOD',
|
|
131
|
+
if (!agentMethods.includes(method)) throw new OpenBrowserError('UNKNOWN_METHOD', t("Unknown method. Use --help to list commands."));
|
|
129
132
|
const api = new OpenBrowserClient({ fallbackName: 'CLI' });
|
|
130
133
|
const params = await readParams();
|
|
131
134
|
const result = method === 'capabilities' ? await api.capabilities() : await api.call(method, params);
|
package/control.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t } from './i18n.mjs';
|
|
1
2
|
import { pathToFileURL } from 'node:url';
|
|
2
3
|
import { chromium } from 'playwright-core';
|
|
3
4
|
import { engineExecutable } from './runtime.mjs';
|
|
@@ -14,23 +15,23 @@ export async function launchBrowser({ headless = true } = {}) {
|
|
|
14
15
|
|
|
15
16
|
function validate({ tasks, concurrency = 4 }) {
|
|
16
17
|
if (!Array.isArray(tasks) || !tasks.length)
|
|
17
|
-
throw new Error('tasks must be a nonempty array');
|
|
18
|
+
throw new Error(t('tasks must be a nonempty array'));
|
|
18
19
|
if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 16)
|
|
19
|
-
throw new Error('concurrency must be an integer between 1 and 16');
|
|
20
|
+
throw new Error(t('concurrency must be an integer between 1 and 16'));
|
|
20
21
|
const ids = new Set();
|
|
21
22
|
for (const task of tasks) {
|
|
22
23
|
if (!task || typeof task.id !== 'string' || !task.id || ids.has(task.id))
|
|
23
|
-
throw new Error('each task needs a unique string id');
|
|
24
|
+
throw new Error(t('each task needs a unique string id'));
|
|
24
25
|
ids.add(task.id);
|
|
25
26
|
if (!URL.canParse(task.url) || !['http:', 'https:'].includes(new URL(task.url).protocol))
|
|
26
|
-
throw new Error('each task needs an HTTP(S) URL');
|
|
27
|
-
if (!Array.isArray(task.steps)) throw new Error('steps must be an array');
|
|
27
|
+
throw new Error(t('each task needs an HTTP(S) URL'));
|
|
28
|
+
if (!Array.isArray(task.steps)) throw new Error(t('steps must be an array'));
|
|
28
29
|
for (const step of task.steps) {
|
|
29
30
|
if (!step || !['fill', 'click', 'read'].includes(step.op) ||
|
|
30
31
|
typeof step.selector !== 'string' || !step.selector.trim())
|
|
31
|
-
throw new Error('each step needs a fill, click or read operation and a selector');
|
|
32
|
+
throw new Error(t('each step needs a fill, click or read operation and a selector'));
|
|
32
33
|
if (step.op === 'fill' && typeof step.value !== 'string')
|
|
33
|
-
throw new Error('fill needs a string value');
|
|
34
|
+
throw new Error(t('fill needs a string value'));
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -87,7 +88,7 @@ async function main() {
|
|
|
87
88
|
for await (const chunk of process.stdin) input += chunk;
|
|
88
89
|
let batch;
|
|
89
90
|
try { batch = JSON.parse(input); }
|
|
90
|
-
catch { throw new Error('stdin must contain a JSON batch'); }
|
|
91
|
+
catch { throw new Error(t('stdin must contain a JSON batch')); }
|
|
91
92
|
validate(batch);
|
|
92
93
|
const browser = await launchBrowser();
|
|
93
94
|
try {
|
package/desktop/Info.plist
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
3
|
<plist version="1.0"><dict>
|
|
4
|
+
<key>CFBundleDevelopmentRegion</key><string>en</string>
|
|
5
|
+
<key>CFBundleLocalizations</key><array><string>en</string><string>zh-Hans</string></array>
|
|
4
6
|
<key>CFBundleIdentifier</key><string>local.open-browser.desktop</string>
|
|
5
7
|
<key>CFBundleName</key><string>open-browser</string>
|
|
6
8
|
<key>CFBundleDisplayName</key><string>open-browser</string>
|
|
@@ -8,6 +10,6 @@
|
|
|
8
10
|
<key>CFBundlePackageType</key><string>APPL</string>
|
|
9
11
|
<key>CFBundleIconFile</key><string>open-browser.icns</string>
|
|
10
12
|
<key>CFBundleVersion</key><string>2</string>
|
|
11
|
-
<key>CFBundleShortVersionString</key><string>0.3.
|
|
13
|
+
<key>CFBundleShortVersionString</key><string>0.3.1</string>
|
|
12
14
|
<key>NSHighResolutionCapable</key><true/>
|
|
13
15
|
</dict></plist>
|
package/desktop/Launcher.m
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#import "OBLocalization.h"
|
|
1
2
|
#import <AppKit/AppKit.h>
|
|
2
3
|
#import <signal.h>
|
|
3
4
|
#import "OBControlBar.h"
|
|
@@ -19,6 +20,9 @@
|
|
|
19
20
|
NSURL *app = [resources URLByAppendingPathComponent:@"app"];
|
|
20
21
|
self.service = [NSTask new];
|
|
21
22
|
self.service.currentDirectoryURL = app;
|
|
23
|
+
NSMutableDictionary *environment = [NSProcessInfo.processInfo.environment mutableCopy];
|
|
24
|
+
environment[@"OPEN_BROWSER_SYSTEM_LOCALE"] = NSBundle.mainBundle.preferredLocalizations.firstObject ?: @"en";
|
|
25
|
+
self.service.environment = environment;
|
|
22
26
|
self.service.executableURL = [resources URLByAppendingPathComponent:@"node/bin/node"];
|
|
23
27
|
self.service.arguments = @[[app URLByAppendingPathComponent:@"service.mjs"].path, @"--chromium", @"--desktop-bar"];
|
|
24
28
|
NSPipe *output = [NSPipe pipe];
|
|
@@ -34,7 +38,7 @@
|
|
|
34
38
|
[owner.bar stop];
|
|
35
39
|
owner.ready = NO;
|
|
36
40
|
if (owner.quitting) { [NSApp replyToApplicationShouldTerminate:YES]; return; }
|
|
37
|
-
if (task.terminationStatus != 0) [owner showError
|
|
41
|
+
if (task.terminationStatus != 0) [owner showError:OBLocalizedString(@"The local browser service exited. Check whether a service started from source is already running.")];
|
|
38
42
|
[NSApp terminate:nil];
|
|
39
43
|
});
|
|
40
44
|
};
|
|
@@ -77,7 +81,11 @@
|
|
|
77
81
|
if (!self.service.running || self.quitting) return;
|
|
78
82
|
NSDictionary *event = [message isKindOfClass:NSDictionary.class] ? message : nil;
|
|
79
83
|
if (ready || [event[@"ready"] isEqual:@YES]) self.ready = YES;
|
|
80
|
-
if ([event[@"event"] isEqual:@"desktop.bar"])
|
|
84
|
+
if ([event[@"event"] isEqual:@"desktop.bar"]) {
|
|
85
|
+
NSString *language = [event[@"locale"] isEqual:@"zh-CN"] ? @"zh-Hans" : @"en";
|
|
86
|
+
[NSUserDefaults.standardUserDefaults registerDefaults:@{@"OpenBrowserServiceLanguage":language}];
|
|
87
|
+
[self.bar update:event[@"bar"]];
|
|
88
|
+
}
|
|
81
89
|
});
|
|
82
90
|
}
|
|
83
91
|
[line setLength:0]; skip = NO;
|
package/desktop/OBControlBar.m
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#import "OBLocalization.h"
|
|
1
2
|
#import "OBControlBar.h"
|
|
2
3
|
#import <CoreGraphics/CoreGraphics.h>
|
|
3
4
|
#import <sys/sysctl.h>
|
|
@@ -72,7 +73,7 @@ static NSString *Text(id value) { return [value isKindOfClass:NSString.class] ?
|
|
|
72
73
|
_send = [send copy];
|
|
73
74
|
_panel = [[OBPanel alloc] initWithContentRect:NSMakeRect(0, 0, 248, 42)
|
|
74
75
|
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskNonactivatingPanel backing:NSBackingStoreBuffered defer:NO];
|
|
75
|
-
_panel.title = @"
|
|
76
|
+
_panel.title = OBLocalizedString(@"Open Browser control bar");
|
|
76
77
|
_panel.floatingPanel = YES;
|
|
77
78
|
_panel.level = NSFloatingWindowLevel;
|
|
78
79
|
_panel.hidesOnDeactivate = NO;
|
|
@@ -102,14 +103,14 @@ static NSString *Text(id value) { return [value isKindOfClass:NSString.class] ?
|
|
|
102
103
|
_status = [NSTextField labelWithString:@""];
|
|
103
104
|
_status.font = [NSFont systemFontOfSize:12];
|
|
104
105
|
_status.textColor = NSColor.secondaryLabelColor;
|
|
105
|
-
_button = [OBBarButton buttonWithTitle
|
|
106
|
+
_button = [OBBarButton buttonWithTitle:OBLocalizedString(@"Take over") target:self action:@selector(click:)];
|
|
106
107
|
_button.bezelStyle = NSBezelStyleRounded;
|
|
107
108
|
_button.controlSize = NSControlSizeSmall;
|
|
108
109
|
_button.focusRingType = NSFocusRingTypeNone;
|
|
109
|
-
_delivery = [OBBarButton buttonWithTitle
|
|
110
|
+
_delivery = [OBBarButton buttonWithTitle:OBLocalizedString(@"Finish") target:self action:@selector(click:)];
|
|
110
111
|
_delivery.bezelStyle = NSBezelStyleRounded;
|
|
111
112
|
_delivery.controlSize = NSControlSizeSmall;
|
|
112
|
-
_delivery.toolTip = @"
|
|
113
|
+
_delivery.toolTip = OBLocalizedString(@"Finish this agent task and keep its open pages");
|
|
113
114
|
NSStackView *row = [NSStackView stackViewWithViews:@[_dot, _agent, _status, _button, _delivery]];
|
|
114
115
|
row.spacing = 8;
|
|
115
116
|
row.alignment = NSLayoutAttributeCenterY;
|
|
@@ -164,6 +165,9 @@ static NSString *Text(id value) { return [value isKindOfClass:NSString.class] ?
|
|
|
164
165
|
if (![bar[key] isKindOfClass:NSNumber.class] || !isfinite([bar[key] doubleValue])) { bar = nil; break; }
|
|
165
166
|
}
|
|
166
167
|
self.bar = bar;
|
|
168
|
+
self.panel.title = OBLocalizedString(@"Open Browser control bar");
|
|
169
|
+
self.delivery.title = OBLocalizedString(@"Finish");
|
|
170
|
+
self.delivery.toolTip = OBLocalizedString(@"Finish this agent task and keep its open pages");
|
|
167
171
|
if (!bar) {
|
|
168
172
|
self.pending = nil;
|
|
169
173
|
self.button.binding = nil;
|
|
@@ -179,13 +183,13 @@ static NSString *Text(id value) { return [value isKindOfClass:NSString.class] ?
|
|
|
179
183
|
self.delivery.binding = delivery;
|
|
180
184
|
if (![self.pending isEqual:binding]) self.pending = nil;
|
|
181
185
|
BOOL human = [bar[@"mode"] isEqual:@"human"], transferring = [bar[@"mode"] isEqual:@"transferring"];
|
|
182
|
-
NSDictionary *states = @{@"actionability"
|
|
183
|
-
@"needs_credential"
|
|
186
|
+
NSDictionary *states = @{@"actionability":OBLocalizedString(@"Checking target"), @"dispatching":OBLocalizedString(@"Dispatching"), @"waiting":OBLocalizedString(@"Waiting for page"), @"verifying":OBLocalizedString(@"Checking result"), @"dispatched":OBLocalizedString(@"Dispatched"), @"running":OBLocalizedString(@"Running"), @"queued":OBLocalizedString(@"Queued"), @"idle":OBLocalizedString(@"Idle"), @"completed":OBLocalizedString(@"Completed"),
|
|
187
|
+
@"needs_visual_permission":OBLocalizedString(@"Screenshot permission required"), @"needs_credential":OBLocalizedString(@"Waiting for credentials"), @"needs_human_verification":OBLocalizedString(@"Human verification required"), @"failed":OBLocalizedString(@"Failed"), @"cancelled":OBLocalizedString(@"Cancelled"), @"outcome_unknown":OBLocalizedString(@"Unverified")};
|
|
184
188
|
self.agent.stringValue = Text(bar[@"agentName"]).length ? bar[@"agentName"] : @"Agent";
|
|
185
189
|
self.agent.toolTip = self.agent.stringValue;
|
|
186
|
-
self.status.stringValue = transferring ? @"
|
|
190
|
+
self.status.stringValue = transferring ? OBLocalizedString(@"Transferring") : human ? OBLocalizedString(@"Human in control") : states[Text(bar[@"phase"])] ?: OBLocalizedString(@"Idle");
|
|
187
191
|
self.button.bezelColor = !human && !transferring && [bar[@"inputBlocked"] boolValue] ? NSColor.systemOrangeColor : nil;
|
|
188
|
-
self.button.title = human ? @"
|
|
192
|
+
self.button.title = human ? OBLocalizedString(@"Return to agent") : OBLocalizedString(@"Take over");
|
|
189
193
|
self.delivery.enabled = !transferring;
|
|
190
194
|
self.button.enabled = !transferring && !self.pending;
|
|
191
195
|
NSColor *color = transferring ? NSColor.systemOrangeColor : human ? NSColor.systemGreenColor : NSColor.systemBlueColor;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
// Finder launches use the app's preferred localization. A source or scripted
|
|
4
|
+
// launch can select the same language as the CLI without changing OS defaults.
|
|
5
|
+
NS_INLINE NSString *OBInterfaceLanguage(void) {
|
|
6
|
+
NSString *selected = [NSUserDefaults.standardUserDefaults stringForKey:@"OpenBrowserServiceLanguage"];
|
|
7
|
+
if ([selected isEqualToString:@"en"] || [selected isEqualToString:@"zh-Hans"]) return selected;
|
|
8
|
+
NSString *override = [NSProcessInfo.processInfo.environment[@"OPEN_BROWSER_LOCALE"]
|
|
9
|
+
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
10
|
+
if (!override.length) return NSBundle.mainBundle.preferredLocalizations.firstObject ?: @"en";
|
|
11
|
+
NSString *language = [[override.lowercaseString componentsSeparatedByCharactersInSet:
|
|
12
|
+
[NSCharacterSet characterSetWithCharactersInString:@"-_.@"]] firstObject];
|
|
13
|
+
return [language isEqualToString:@"zh"] ? @"zh-Hans" : @"en";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
NS_INLINE NSString *OBLocalizedString(NSString *key) {
|
|
17
|
+
NSString *path = [NSBundle.mainBundle pathForResource:OBInterfaceLanguage() ofType:@"lproj"];
|
|
18
|
+
NSBundle *bundle = path ? [NSBundle bundleWithPath:path] : NSBundle.mainBundle;
|
|
19
|
+
return [bundle localizedStringForKey:key value:key table:nil];
|
|
20
|
+
}
|
package/desktop/OBPageView.m
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#import "OBLocalization.h"
|
|
1
2
|
#import "OBPageView.h"
|
|
2
3
|
|
|
3
4
|
@interface OBPageView ()
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
_events = [NSMutableArray array];
|
|
27
28
|
[self setAccessibilityElement:YES];
|
|
28
29
|
[self setAccessibilityRole:NSAccessibilityImageRole];
|
|
29
|
-
[self setAccessibilityLabel
|
|
30
|
+
[self setAccessibilityLabel:OBLocalizedString(@"Workspace web page")];
|
|
30
31
|
[self setAccessibilityIdentifier:@"open-browser-workspace-page"];
|
|
31
32
|
}
|
|
32
33
|
return self;
|