desktopUpdateMenu.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {
  2. ZCODE_PRODUCT_FLAVOR,
  3. type ZCodeProductFlavor,
  4. type UpdateStatePayload,
  5. } from "@zcode/shared";
  6. // 更新入口跟随产品身份而不是后端环境:Preview 身份(含生产后端的 Preview)禁用更新器。
  7. export function shouldShowDesktopUpdateEntry(
  8. flavor: ZCodeProductFlavor = ZCODE_PRODUCT_FLAVOR,
  9. ): boolean {
  10. return flavor === "production";
  11. }
  12. export function getUpdateMenuLabelId(state: UpdateStatePayload | null) {
  13. switch (state?.kind) {
  14. case "checking":
  15. return "desktopMenu.help.checkingForUpdates";
  16. case "update-available":
  17. return "desktopMenu.help.updateAvailableVersion";
  18. case "download-progress":
  19. return "desktopMenu.help.downloadingUpdateProgress";
  20. case "update-downloaded":
  21. return "desktopMenu.help.restartToUpdate";
  22. case "idle":
  23. default:
  24. return "titleBar.menu.help.checkForUpdates";
  25. }
  26. }
  27. export function getUpdateMenuLabelValues(
  28. state: UpdateStatePayload | null,
  29. ): Record<string, string> | undefined {
  30. switch (state?.kind) {
  31. case "update-available":
  32. case "update-downloaded":
  33. return { version: state.version };
  34. case "download-progress":
  35. return { progress: state.progress };
  36. default:
  37. return undefined;
  38. }
  39. }