cicy-desktop 2.1.257 → 2.1.258

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/main.js +71 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cicy-desktop",
3
- "version": "2.1.257",
3
+ "version": "2.1.258",
4
4
  "description": "CiCy - AI-powered operating system browser",
5
5
  "main": "src/main.js",
6
6
  "bin": {
package/src/main.js CHANGED
@@ -1317,17 +1317,17 @@ electronApp.whenReady().then(async () => {
1317
1317
  }
1318
1318
 
1319
1319
  const profileStore = require("./profiles/profile-store");
1320
- const electronProfiles = (() => {
1320
+ const electronProfiles = () => {
1321
1321
  let rows = [];
1322
1322
  try { rows = profileStore.listProfiles("electron"); } catch {}
1323
1323
  // Profile 0 is the resident CiCy system window and must not be exposed in
1324
1324
  // the macOS title/top-bar launcher. Profile 9 is Chrome's source template.
1325
1325
  rows = rows.filter((p) => ![0, 9].includes(Number(p.accountIdx)));
1326
1326
  return rows;
1327
- })();
1328
- const chromeProfiles = (() => {
1327
+ };
1328
+ const chromeProfiles = () => {
1329
1329
  try { return profileStore.listProfiles("chrome"); } catch { return []; }
1330
- })();
1330
+ };
1331
1331
  const showProfileError = (kind, e) => {
1332
1332
  dialog.showMessageBox({
1333
1333
  type: "error",
@@ -1336,16 +1336,17 @@ electronApp.whenReady().then(async () => {
1336
1336
  buttons: ["OK"],
1337
1337
  });
1338
1338
  };
1339
- const openElectronProfile = async (accountIdx) => {
1339
+ const openElectronProfile = async (accountIdx, url) => {
1340
1340
  try {
1341
1341
  const tabs = require("./tools/tab-browser-tools");
1342
- await tabs.openTab(accountIdx, undefined, { activate: true });
1342
+ await tabs.openTab(accountIdx, url, { activate: true });
1343
1343
  const m = tabs.ensureManager(accountIdx);
1344
1344
  if (m.win.isMinimized()) m.win.restore();
1345
1345
  m.win.show();
1346
1346
  m.win.focus();
1347
1347
  } catch (e) { showProfileError("Electron", e); }
1348
1348
  };
1349
+ const openCicyAi = () => openElectronProfile(1, "https://cicy-ai.com");
1349
1350
  const openChromeProfile = async (accountIdx) => {
1350
1351
  try {
1351
1352
  await require("./tools/chrome-tools").launchOrActivateProfile({
@@ -1359,8 +1360,49 @@ electronApp.whenReady().then(async () => {
1359
1360
  catch (e) { showProfileError("Chrome", e); }
1360
1361
  };
1361
1362
 
1362
- const menuTemplate = [
1363
- ...(process.platform === "darwin" ? [{ role: "appMenu" }] : []),
1363
+ let installApplicationMenu = () => {};
1364
+ const addProfileFromMenu = async (kind) => {
1365
+ try {
1366
+ const result = await executeTool(kind === "Electron" ? "electron_add_profile" : "chrome_add_profile", {});
1367
+ const text = result && result.content && result.content[0] && result.content[0].text;
1368
+ let data = {};
1369
+ try { data = JSON.parse(text || "{}"); } catch {}
1370
+ if (result && result.isError) throw new Error(data.error || text || "unknown error");
1371
+ const accountIdx = Number(data.accountIdx ?? (data.created && data.created.accountIdx));
1372
+ installApplicationMenu(); // the new profile appears immediately in the native menu
1373
+ if (Number.isFinite(accountIdx)) {
1374
+ if (kind === "Electron") await openElectronProfile(accountIdx);
1375
+ else await openChromeProfile(accountIdx);
1376
+ }
1377
+ } catch (e) {
1378
+ dialog.showMessageBox({
1379
+ type: "error",
1380
+ message: `新增 ${kind} Profile 失败`,
1381
+ detail: String((e && e.message) || e),
1382
+ buttons: ["OK"],
1383
+ });
1384
+ }
1385
+ };
1386
+
1387
+ installApplicationMenu = () => {
1388
+ const electronRows = electronProfiles();
1389
+ const chromeRows = chromeProfiles();
1390
+ const menuTemplate = [
1391
+ ...(process.platform === "darwin" ? [{
1392
+ label: electronApp.name,
1393
+ submenu: [
1394
+ { role: "about" },
1395
+ { label: "打开 cicy-ai.com", click: openCicyAi },
1396
+ { type: "separator" },
1397
+ { role: "services" },
1398
+ { type: "separator" },
1399
+ { role: "hide" },
1400
+ { role: "hideOthers" },
1401
+ { role: "unhide" },
1402
+ { type: "separator" },
1403
+ { role: "quit" },
1404
+ ],
1405
+ }] : []),
1364
1406
  {
1365
1407
  label: i18n.t("menu.file"),
1366
1408
  submenu: [
@@ -1398,17 +1440,22 @@ electronApp.whenReady().then(async () => {
1398
1440
  },
1399
1441
  {
1400
1442
  label: "Electron",
1401
- submenu: electronProfiles.map((p) => ({
1402
- label: `Profile ${p.accountIdx}${p.name ? ` · ${p.name}` : ""}`,
1403
- click: () => openElectronProfile(Number(p.accountIdx)),
1404
- })),
1443
+ submenu: [
1444
+ { label: "新增 Profile", click: () => addProfileFromMenu("Electron") },
1445
+ ...(electronRows.length ? [{ type: "separator" }] : []),
1446
+ ...electronRows.map((p) => ({
1447
+ label: `Profile ${p.accountIdx}${p.name ? ` · ${p.name}` : ""}`,
1448
+ click: () => openElectronProfile(Number(p.accountIdx)),
1449
+ })),
1450
+ ],
1405
1451
  },
1406
1452
  {
1407
1453
  label: "Chrome",
1408
1454
  submenu: [
1455
+ { label: "新增 Profile", click: () => addProfileFromMenu("Chrome") },
1409
1456
  { label: "原生 Chrome", click: openNativeChrome },
1410
- { type: "separator" },
1411
- ...chromeProfiles.map((p) => ({
1457
+ ...(chromeRows.length ? [{ type: "separator" }] : []),
1458
+ ...chromeRows.map((p) => ({
1412
1459
  label: `Profile ${p.accountIdx}${p.gmail ? ` · ${p.gmail}` : p.note ? ` · ${p.note}` : ""}`,
1413
1460
  click: () => openChromeProfile(Number(p.accountIdx)),
1414
1461
  })),
@@ -1423,8 +1470,16 @@ electronApp.whenReady().then(async () => {
1423
1470
  : [{ label: i18n.t("menu.close"), role: "close" }]),
1424
1471
  ],
1425
1472
  },
1426
- ];
1427
- Menu.setApplicationMenu(Menu.buildFromTemplate(menuTemplate));
1473
+ ...(process.platform !== "darwin" ? [{
1474
+ label: i18n.t("menu.help"),
1475
+ submenu: [
1476
+ { label: "打开 cicy-ai.com", click: openCicyAi },
1477
+ ],
1478
+ }] : []),
1479
+ ];
1480
+ Menu.setApplicationMenu(Menu.buildFromTemplate(menuTemplate));
1481
+ };
1482
+ installApplicationMenu();
1428
1483
 
1429
1484
  // Always open the homepage unless launched at login with --hidden.
1430
1485
  const hidden = process.argv.includes("--hidden");