Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
feat: support distinct app identifiers
Tw93c53601e9d62e
diff --git a/bin/helpers/cli-program.ts b/bin/helpers/cli-program.tsindex a3f35f5a..ebb51440 100644--- a/bin/helpers/cli-program.ts+++ b/bin/helpers/cli-program.ts@@ -22,6 +22,10 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with.showHelpAfterError().argument('[url]', 'The web URL you want to package', validateUrlInput).option('--name <string>', 'Application name')+ .addOption(+ new Option('--identifier <string>', 'Application identifier / bundle ID')+ .hideHelp(),+ ).option('--icon <string>', 'Application icon', DEFAULT.icon).option('--width <number>',diff --git a/bin/options/index.ts b/bin/options/index.tsindex e7dea120..6bd7240e 100644--- a/bin/options/index.ts+++ b/bin/options/index.ts@@ -4,7 +4,11 @@ import logger from '@/options/logger';import { handleIcon } from './icon';import { getDomain } from '@/utils/url';-import { getIdentifier, promptText, capitalizeFirstLetter } from '@/utils/info';+import {+ promptText,+ capitalizeFirstLetter,+ resolveIdentifier,+} from '@/utils/info';import { generateLinuxPackageName } from '@/utils/name';import { PakeAppOptions, PakeCliOptions, PlatformMap } from '@/types';@@ -60,6 +64,8 @@ export default async function handleOptions(name = generateLinuxPackageName(name);}+ const resolvedName = name || 'pake-app';+if (name && !isValidName(name, platform)) {const LINUX_NAME_ERROR = `✕ Name should only include lowercase letters, numbers, and dashes (not leading dashes). Examples: com-123-xxx, 123pan, pan123, weread, we-read, 123.`;const DEFAULT_NAME_ERROR = `✕ Name should only include letters, numbers, dashes, and spaces (not leading dashes and spaces). Examples: 123pan, 123Pan, Pan123, weread, WeRead, WERead, we-read, We Read, 123.`;@@ -76,8 +82,8 @@ export default async function handleOptions(const appOptions: PakeAppOptions = {...options,- name,- identifier: getIdentifier(url),+ name: resolvedName,+ identifier: resolveIdentifier(url, resolvedName, options.identifier),};const iconPath = await handleIcon(appOptions, url);diff --git a/bin/types.ts b/bin/types.tsindex 192708d7..caab4e40 100644--- a/bin/types.ts+++ b/bin/types.ts@@ -6,6 +6,9 @@ export interface PakeCliOptions {// Application namename?: string;+ // Explicit app identifier / bundle id+ identifier?: string;+// Window title (supports Chinese characters)title?: string;diff --git a/bin/utils/info.ts b/bin/utils/info.tsindex 0d077dd1..872b0f4a 100644--- a/bin/utils/info.ts+++ b/bin/utils/info.ts@@ -3,16 +3,29 @@ import prompts from 'prompts';import ora from 'ora';import chalk from 'chalk';-// Generates an identifier based on the given URL.-export function getIdentifier(url: string) {+// Generates a stable identifier based on the app URL and name.+export function getIdentifier(url: string, name: string) {const postFixHash = crypto.createHash('md5')- .update(url)+ .update(`${url}::${name}`).digest('hex').substring(0, 6);return `com.pake.${postFixHash}`;}+export function resolveIdentifier(+ url: string,+ name: string,+ customIdentifier?: string,+) {+ const trimmedIdentifier = customIdentifier?.trim();+ if (trimmedIdentifier) {+ return trimmedIdentifier;+ }++ return getIdentifier(url, name);+}+export async function promptText(message: string,initial?: string,diff --git a/dist/cli.js b/dist/cli.jsindex 9f7976ea..0c4034f6 100644--- a/dist/cli.js+++ b/dist/cli.js@@ -171,15 +171,22 @@ let tauriConfig = {pake: pakeConf,};-// Generates an identifier based on the given URL.-function getIdentifier(url) {+// Generates a stable identifier based on the app URL and name.+function getIdentifier(url, name) {const postFixHash = crypto.createHash('md5')- .update(url)+ .update(`${url}::${name}`).digest('hex').substring(0, 6);return `com.pake.${postFixHash}`;}+function resolveIdentifier(url, name, customIdentifier) {+ const trimmedIdentifier = customIdentifier?.trim();+ if (trimmedIdentifier) {+ return trimmedIdentifier;+ }+ return getIdentifier(url, name);+}async function promptText(message, initial) {const response = await prompts({type: 'text',@@ -2002,6 +2009,7 @@ async function handleOptions(options, url) {if (name && platform === 'linux') {name = generateLinuxPackageName(name);}+ const resolvedName = name || 'pake-app';if (name && !isValidName(name, platform)) {const LINUX_NAME_ERROR = `✕ Name should only include lowercase letters, numbers, and dashes (not leading dashes). Examples: com-123-xxx, 123pan, pan123, weread, we-read, 123.`;const DEFAULT_NAME_ERROR = `✕ Name should only include letters, numbers, dashes, and spaces (not leading dashes and spaces). Examples: 123pan, 123Pan, Pan123, weread, WeRead, WERead, we-read, We Read, 123.`;@@ -2017,8 +2025,8 @@ async function handleOptions(options, url) {}const appOptions = {...options,- name,- identifier: getIdentifier(url),+ name: resolvedName,+ identifier: resolveIdentifier(url, resolvedName, options.identifier),};const iconPath = await handleIcon(appOptions, url);appOptions.icon = iconPath || '';@@ -2114,6 +2122,8 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with.showHelpAfterError().argument('[url]', 'The web URL you want to package', validateUrlInput).option('--name <string>', 'Application name')+ .addOption(new Option('--identifier <string>', 'Application identifier / bundle ID')+ .hideHelp()).option('--icon <string>', 'Application icon', DEFAULT_PAKE_OPTIONS.icon).option('--width <number>', 'Window width', validateNumberInput, DEFAULT_PAKE_OPTIONS.width).option('--height <number>', 'Window height', validateNumberInput, DEFAULT_PAKE_OPTIONS.height)diff --git a/docs/advanced-usage.md b/docs/advanced-usage.mdindex 12dbe3e5..7d66d3ba 100644--- a/docs/advanced-usage.md+++ b/docs/advanced-usage.md@@ -124,6 +124,25 @@ pake ./my-app/index.html --name my-static-app --use-local-fileRequirements: Pake CLI >= 3.0.0+## Multiple Apps For The Same Site++If you need separate apps for the same site, for example two Gmail accounts with different login state, build them with different app names:++```bash+pake https://gmail.com --name "Gmail Work"+pake https://gmail.com --name "Gmail Personal"+```++Pake now generates a different app identifier for each `URL + name` pair, so these apps can be installed as separate desktop apps instead of resolving to the same app.++For advanced cases, Pake also supports a hidden `--identifier` option if you need to pin the bundle identifier explicitly:++```bash+pake https://gmail.com --name "Gmail Work" --identifier com.example.gmail.work+```++`--multi-instance` is different. It only allows multiple processes for the same packaged app, it does not create separate app identities.+## Project StructureUnderstanding Pake's codebase structure will help you navigate and contribute effectively:diff --git a/docs/advanced-usage_CN.md b/docs/advanced-usage_CN.mdindex a1df0b86..a0808b09 100644--- a/docs/advanced-usage_CN.md+++ b/docs/advanced-usage_CN.md@@ -124,6 +124,25 @@ pake ./my-app/index.html --name my-static-app --use-local-file要求:Pake CLI >= 3.0.0+## 同一站点生成多个独立应用++如果你需要为同一个站点生成多个彼此独立的应用,例如两个不同登录态的 Gmail,可以直接使用不同的应用名称进行构建:++```bash+pake https://gmail.com --name "Gmail Work"+pake https://gmail.com --name "Gmail Personal"+```++Pake 现在会基于 `URL + name` 生成不同的应用标识,因此这两个应用会被当作两个独立桌面应用安装,而不是落到同一个应用上。++对于需要固定 bundle identifier 的高级场景,Pake 也支持一个隐藏参数 `--identifier`:++```bash+pake https://gmail.com --name "Gmail Work" --identifier com.example.gmail.work+```++`--multi-instance` 和这个能力不同,它只是允许同一个已打包应用启动多个进程,并不会创建多个独立应用身份。+## 项目结构了解 Pake 的代码库结构将帮助您有效地进行导航和贡献:diff --git a/tests/unit/cli-options.test.ts b/tests/unit/cli-options.test.tsindex 756d2a4a..dcbee27b 100644--- a/tests/unit/cli-options.test.ts+++ b/tests/unit/cli-options.test.ts@@ -22,6 +22,13 @@ describe('CLI options', () => {expect(option?.defaultValue).toBe('');});+ it('registers hidden --identifier option', () => {+ const option = program.options.find((item) => item.long === '--identifier');++ expect(option).toBeDefined();+ expect(option?.hidden).toBe(true);+ });+it('registers visible --install option', () => {const option = program.options.find((item) => item.long === '--install');diff --git a/tests/unit/identifier.test.ts b/tests/unit/identifier.test.tsnew file mode 100644index 00000000..5cecf145--- /dev/null+++ b/tests/unit/identifier.test.ts@@ -0,0 +1,24 @@+import { describe, expect, it } from 'vitest';+import { getIdentifier, resolveIdentifier } from '@/utils/info';++describe('identifier generation', () => {+ const url = 'https://gmail.com';++ it('generates different identifiers for the same URL when app names differ', () => {+ expect(getIdentifier(url, 'Work Gmail')).not.toBe(+ getIdentifier(url, 'Personal Gmail'),+ );+ });++ it('generates stable identifiers for the same URL and app name', () => {+ expect(getIdentifier(url, 'Work Gmail')).toBe(+ getIdentifier(url, 'Work Gmail'),+ );+ });++ it('prefers a custom identifier when provided', () => {+ expect(+ resolveIdentifier(url, 'Work Gmail', 'com.example.work-gmail'),+ ).toBe('com.example.work-gmail');+ });+});