示例工程 55-installers-and-channels

55-installers-and-channels/app/shared/channels.ts

typescript · 6.2 KB

export type Channel = {
  id: string;
  name: string;
  artifact: string;
  updateOwner: "自己" | "平台" | "包管理器";
  review: string;
  inAppUpdate: boolean;
  signing: string;
  note: string;
};

export type Installer = {
  id: string;
  platform: "macOS" | "Windows" | "Linux";
  location: string;
  shortcuts: string;
  uninstall: string;
  silent: string;
  residue: string;
};

export const CHANNELS: Channel[] = [
  {
    id: "direct",
    name: "官网直下",
    artifact: "dmg + zip / nsis / AppImage",
    updateOwner: "自己",
    review: "无",
    inAppUpdate: true,
    signing: "必须(macOS 公证 / Windows 证书)",
    note: "完全控制,但下载、签名、更新与客服都要自己承担。",
  },
  {
    id: "github",
    name: "GitHub Releases",
    artifact: "zip / nupkg / dmg",
    updateOwner: "自己",
    review: "无",
    inAppUpdate: true,
    signing: "必须",
    note: "公开仓库可用官方 update.electronjs.org;私有仓库需自建更新源。",
  },
  {
    id: "mas",
    name: "Mac App Store",
    artifact: "pkg(MAS)",
    updateOwner: "平台",
    review: "Apple 审核",
    inAppUpdate: false,
    signing: "Apple 分发证书 + Sandbox",
    note: "审核与沙箱限制;应用内不能自更新。",
  },
  {
    id: "msstore",
    name: "Microsoft Store",
    artifact: "MSIX / appx",
    updateOwner: "平台",
    review: "Microsoft 审核",
    inAppUpdate: false,
    signing: "商店签名 / 应用身份",
    note: "应用身份改变路径与更新;不要双重更新。",
  },
  {
    id: "flathub",
    name: "Flathub",
    artifact: "flatpak",
    updateOwner: "平台",
    review: "Flathub 审核",
    inAppUpdate: false,
    signing: "仓库签名",
    note: "沙箱权限由 manifest 声明;用户通过商店更新。",
  },
  {
    id: "snap",
    name: "Snap Store",
    artifact: "snap",
    updateOwner: "平台",
    review: "Canonical 审核",
    inAppUpdate: false,
    signing: "商店签名",
    note: "confinement 限制文件与设备访问;更新由 snapd 负责。",
  },
  {
    id: "aur",
    name: "AUR / 发行版仓库",
    artifact: "源码包 / deb / rpm",
    updateOwner: "包管理器",
    review: "仓库/维护者",
    inAppUpdate: false,
    signing: "仓库签名",
    note: "更新由包管理器负责;应用内自更新会破坏包状态。",
  },
  {
    id: "homebrew",
    name: "Homebrew Cask",
    artifact: "dmg / zip",
    updateOwner: "包管理器",
    review: "Cask 维护者",
    inAppUpdate: false,
    signing: "仍需公证",
    note: "适合开发者用户;brew upgrade 负责更新。",
  },
];

export const INSTALLERS: Installer[] = [
  {
    id: "dmg",
    platform: "macOS",
    location: "用户拖到 /Applications",
    shortcuts: "无",
    uninstall: "拖到废纸篓",
    silent: "不支持",
    residue: "~/Library 下的应用数据与偏好",
  },
  {
    id: "pkg",
    platform: "macOS",
    location: "/Applications 或自定义",
    shortcuts: "无",
    uninstall: "无标准卸载,需脚本或工具",
    silent: "installer -pkg ... -target /",
    residue: "receipts、LaunchDaemons、应用数据",
  },
  {
    id: "squirrel",
    platform: "Windows",
    location: "%LocalAppData%\\AppName",
    shortcuts: "开始菜单 + 桌面",
    uninstall: "应用内或设置",
    silent: "--silent",
    residue: "用户数据、更新缓存",
  },
  {
    id: "nsis",
    platform: "Windows",
    location: "Program Files 或 per-user",
    shortcuts: "可选",
    uninstall: "卸载器",
    silent: "/S",
    residue: "注册表、用户数据、快捷方式",
  },
  {
    id: "msi",
    platform: "Windows",
    location: "Program Files",
    shortcuts: "可选",
    uninstall: "应用和功能 / msiexec",
    silent: "msiexec /i ... /qn",
    residue: "注册表、用户数据",
  },
  {
    id: "msix",
    platform: "Windows",
    location: "WindowsApps(受管)",
    shortcuts: "开始菜单",
    uninstall: "设置 / 商店",
    silent: "Add-AppxPackage",
    residue: "应用数据容器",
  },
  {
    id: "deb",
    platform: "Linux",
    location: "/opt 或 /usr",
    shortcuts: ".desktop",
    uninstall: "apt remove",
    silent: "DEBIAN_FRONTEND=noninteractive",
    residue: "/etc 配置、~/.config",
  },
  {
    id: "rpm",
    platform: "Linux",
    location: "/opt 或 /usr",
    shortcuts: ".desktop",
    uninstall: "dnf remove",
    silent: "-y",
    residue: "/etc 配置、~/.config",
  },
  {
    id: "appimage",
    platform: "Linux",
    location: "用户任意位置",
    shortcuts: "手动",
    uninstall: "删除文件",
    silent: "不适用",
    residue: "~/.config、~/.cache",
  },
];

export type Requirement = {
  store: boolean;
  enterprise: boolean;
  autoUpdate: boolean;
  linux: boolean;
};

export type Recommendation = {
  channel: string;
  artifact: string;
  reason: string;
};

export function recommend(requirement: Requirement): Recommendation {
  if (requirement.store) {
    if (requirement.linux) {
      return {
        channel: "flathub",
        artifact: "flatpak",
        reason: "商店分发由 Flathub 负责更新与沙箱权限",
      };
    }
    if (requirement.enterprise) {
      return {
        channel: "msstore",
        artifact: "MSIX",
        reason: "企业商店分发,更新由平台负责",
      };
    }
    return {
      channel: "mas",
      artifact: "pkg(MAS)",
      reason: "macOS 商店分发,审核与沙箱由 Apple 管理",
    };
  }
  if (requirement.enterprise) {
    return {
      channel: "direct",
      artifact: requirement.linux ? "deb" : "msi / pkg",
      reason: "企业内部分发,安装器可控",
    };
  }
  if (requirement.autoUpdate) {
    return {
      channel: requirement.linux ? "appimage" : "direct",
      artifact: requirement.linux ? "AppImage + 签名" : "dmg + zip / nsis",
      reason: "自建更新源或应用内更新",
    };
  }
  return {
    channel: "direct",
    artifact: requirement.linux ? "AppImage" : "dmg / nsis",
    reason: "最小依赖,手动更新",
  };
}

export function releasePath(
  platform: string,
  arch: string,
  file: string,
): string {
  return `releases/${platform}/${arch}/${file}`;
}

export function checksumName(file: string): string {
  return `${file}.sha256`;
}