desktop-pet-app 0.2.3 → 0.2.5

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/out/main/index.js +22 -6
  2. package/package.json +1 -1
package/out/main/index.js CHANGED
@@ -246,6 +246,9 @@ function sleep(ms) {
246
246
  function isPetOnQuest(petId) {
247
247
  return busy.has(petId);
248
248
  }
249
+ function canSendAwayPet(identity) {
250
+ return identity.kind === "remote-friend";
251
+ }
249
252
  function presentPetIdentity(identity, localUsername) {
250
253
  if (identity.kind === "remote-friend") {
251
254
  return {
@@ -274,6 +277,11 @@ class PetManager {
274
277
  count() {
275
278
  return this.pets.size;
276
279
  }
280
+ hasPrimaryPet() {
281
+ return [...this.pets.values()].some(
282
+ (pet) => !pet.win.isDestroyed() && pet.identity.kind === "primary"
283
+ );
284
+ }
277
285
  findRemoteFriend(username) {
278
286
  const normalized = username.trim().toLowerCase();
279
287
  return [...this.pets.values()].find(
@@ -1667,7 +1675,7 @@ async function checkForUpdates(currentVersion = electron.app.getVersion()) {
1667
1675
  endpoint.searchParams.set("platform", process.platform);
1668
1676
  endpoint.searchParams.set("arch", process.arch);
1669
1677
  endpoint.searchParams.set("currentVersion", currentVersion);
1670
- const response = await fetch(endpoint, {
1678
+ const response = await electron.net.fetch(endpoint.toString(), {
1671
1679
  headers: updateCheckHeaders(endpoint),
1672
1680
  signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
1673
1681
  cache: "no-store"
@@ -1711,7 +1719,7 @@ async function downloadAvailableUpdate() {
1711
1719
  const temporaryPath = `${artifactPath}.${node_crypto.randomUUID()}.download`;
1712
1720
  try {
1713
1721
  await promises.mkdir(updateDirectory, { recursive: true });
1714
- const response = await fetch(available.releaseUrl, {
1722
+ const response = await electron.net.fetch(available.releaseUrl, {
1715
1723
  headers: { accept: "application/octet-stream, application/wasm, */*" },
1716
1724
  signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS),
1717
1725
  cache: "no-store",
@@ -1926,6 +1934,9 @@ function compareVersions(a, b) {
1926
1934
  }
1927
1935
  function humanizeUpdateError(error) {
1928
1936
  if (error instanceof DOMException && error.name === "TimeoutError") return "检查更新超时,请稍后重试";
1937
+ if (error instanceof TypeError && error.message === "fetch failed") {
1938
+ return "无法连接更新服务器,请检查网络或系统代理";
1939
+ }
1929
1940
  if (error instanceof Error) return error.message;
1930
1941
  return "暂时无法检查更新";
1931
1942
  }
@@ -2084,7 +2095,7 @@ function createPetWindow(skin, options) {
2084
2095
  submenu: updateMenuItems(id)
2085
2096
  },
2086
2097
  { type: "separator" },
2087
- { label: "送走这只宠物", click: () => win.close() },
2098
+ ...canSendAwayPet(identity) ? [{ label: "送走这只宠物", click: () => win.close() }] : [],
2088
2099
  { label: "退出", click: () => electron.app.quit() }
2089
2100
  ]);
2090
2101
  menu.popup({ window: win });
@@ -2994,6 +3005,13 @@ if (!singleInstance) {
2994
3005
  electron.app.on("second-instance", (_event, argv) => {
2995
3006
  const callback = argv.find((value) => value.startsWith("desktop-pet://"));
2996
3007
  if (callback) handleAccountCallback(callback);
3008
+ ensurePrimaryPet();
3009
+ });
3010
+ }
3011
+ function ensurePrimaryPet() {
3012
+ if (petManager.hasPrimaryPet()) return null;
3013
+ return createPetWindow(process.env.DESKTOP_PET_SKIN || "codex", {
3014
+ identity: { kind: "primary" }
2997
3015
  });
2998
3016
  }
2999
3017
  electron.app.whenReady().then(async () => {
@@ -3006,9 +3024,7 @@ electron.app.whenReady().then(async () => {
3006
3024
  if (!activated) startRelay();
3007
3025
  if (process.env.DESKTOP_PET_P2P !== "0") startP2PWindow(getDeviceIceServers());
3008
3026
  void startRunnerManager();
3009
- const id = createPetWindow(process.env.DESKTOP_PET_SKIN || "codex", {
3010
- identity: { kind: "primary" }
3011
- });
3027
+ const id = ensurePrimaryPet();
3012
3028
  setTimeout(() => {
3013
3029
  void checkForUpdates().then((result) => {
3014
3030
  if (id && result.kind === "available") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "desktop-pet-app",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "AI desktop pet with MCP support and a self-hosted relay server",
5
5
  "license": "MIT",
6
6
  "keywords": [