2.0 Upgrade Plan

This commit is contained in:
Tw93
2024-12-06 17:49:51 +08:00
parent 3f5454b839
commit f5869d62c8
22 changed files with 399 additions and 136 deletions

41
bin/README.md vendored
View File

@@ -146,6 +146,14 @@ Sets whether the window is always at the top level, defaults to `false`.
--always-on-top
```
#### [dark-mode]
Force Mac to package applications using dark mode, default is `false`.
```shell
--dark-mode
```
#### [disabled-web-shortcuts]
Sets whether to disable web shortcuts in the original Pake container, defaults to `false`.
@@ -211,6 +219,14 @@ Specify the system tray icon. This is only effective when the system tray is ena
--system-tray-icon <path>
```
#### [installer-language]
Set the Windows Installer language. Options include `zh-CN`, `ja-JP`, More at [Tauri Document](https://tauri.app/zh-cn/v1/guides/building/windows/#internationalization). Default is `en-US`.
```shell
--installer-language <language>
```
#### [use-local-file]
Enable recursive copying. When the URL is a local file path, enabling this option will copy the folder containing the file specified in the URL, as well as all sub-files, to the Pake static folder. This is disabled by default.
@@ -227,14 +243,12 @@ Using `inject`, you can inject local absolute and relative path `css` and `js` f
--inject ./tools/style.css,./tools/hotkey.js
```
#### [safe-domain]
#### [proxy-url]
This secure domain is a domain other than your currently configured `url` to which you may be redirected or jumped to, and only in domains that have been configured as secure can you use `tauri` to expose `api` to browsers to ensure that pake's built-in enhancements work correctly. Only in a domain that has been configured as secure can you use the `tauri` to expose the `api` to the browser, ensuring that `pake's` built-in enhancements work correctly.
PS: Secure domains do not need to carry protocols.
If you need to proxy requests for some reason, you can set the proxy address using the `proxy-url` option.
```shell
--safe-domain weread.qq.com,google.com
--proxy-url <url>
```
#### [debug]
@@ -248,3 +262,20 @@ The typed package has dev-tools for debugging, in addition to outputting more lo
## Conclusion
After completing the above steps, your application should be successfully packaged. Please note that the packaging process may take some time depending on your system configuration and network conditions. Be patient, and once the packaging is complete, you can find the application installer in the specified directory.
## Docker
```shell
# On Linux, you can run the Pake CLI via Docker
docker run -it --rm \ # Run interactively, remove container after exit
-v YOUR_DIR:/output \ # Files from container's /output will be in YOU_DIR
ghcr.io/tw93/pake \
<arguments>
# For example:
docker run -it --rm \
-v ./packages:/output \
ghcr.io/tw93/pake \
https://example.com --name myapp --icon ./icon.png
```

43
bin/README_CN.md vendored
View File

@@ -146,6 +146,14 @@ pake [url] [options]
--always-on-top
```
#### [dark-mode]
强制 Mac 打包应用使用黑暗模式,默认为 `false`。
```shell
--dark-mode
```
#### [disabled-web-shortcuts]
设置是否禁用原有 Pake 容器里面的网页操作快捷键,默认为 `false`。
@@ -212,6 +220,14 @@ Linux默认为 `all`。
--system-tray-icon <path>
```
#### [installer-language]
设置 Windows 安装包语言。支持 `zh-CN`、`ja-JP`,更多在 [Tauri 文档](https://tauri.app/zh-cn/v1/guides/building/windows/#internationalization)。默认为 `en-US`。
```shell
--installer-language <language>
```
#### [use-local-file]
当 `url` 为本地文件路径时,如果启用此选项,则会递归地将 `url` 路径文件所在的文件夹及其所有子文件复
@@ -234,16 +250,12 @@ Linux默认为 `all`。
--inject ./tools/style.css --inject ./tools/hotkey.js
```
#### [safe-domain]
#### [proxy-url]
这个安全域名是除你当前配置的 `url` 之外可能会出现重定向或跳转到的其他域名,只有在已配置为安全的域名中,
才能够使用 `tauri` 暴露到浏览器的 `api` ,保证 `pake` 内置增强功能的正确运行。
PS: 安全域名不需要携带协议。
假如你由于某些缘故需要代理请求,你可以通过 `proxy-url` 选项来设置代理地址。
```shell
--safe-domain weread.qq.com,google.com
--proxy-url <url>
```
#### [debug]
@@ -257,3 +269,20 @@ PS: 安全域名不需要携带协议。
## 结语
完成上述步骤后,您的应用程序应该已经成功打包。请注意,根据您的系统配置和网络状况,打包过程可能需要一些时间。请耐心等待,一旦打包完成,您就可以在指定的目录中找到应用程序安装包。
## Docker
```shell
# 在Linux上您可以通过 Docker 运行 Pake CLI。
docker run -it --rm \ # Run interactively, remove container after exit
-v YOUR_DIR:/output \ # Files from container's /output will be in YOU_DIR
ghcr.io/tw93/pake \
<arguments>
# For example:
docker run -it --rm \
-v ./packages:/output \
ghcr.io/tw93/pake \
https://example.com --name myapp --icon ./icon.png
```

9
bin/cli.ts vendored
View File

@@ -39,20 +39,19 @@ program
new Option('--targets <string>', 'Only for Linux, option "deb" or "appimage"').default(DEFAULT.targets).hideHelp(),
)
.addOption(new Option('--always-on-top', 'Always on the top level').default(DEFAULT.alwaysOnTop).hideHelp())
.addOption(new Option('--dark-mode', 'Force Mac app to use dark mode').default(DEFAULT.darkMode).hideHelp())
.addOption(
new Option('--disabled-web-shortcuts', 'Disabled webPage shortcuts')
.default(DEFAULT.disabledWebShortcuts)
.hideHelp(),
)
.addOption(
new Option('--safe-domain [domains...]', 'Domains that Require Security Configuration')
.default(DEFAULT.safeDomain)
.hideHelp(),
)
.addOption(new Option('--show-system-tray', 'Show system tray in app').default(DEFAULT.showSystemTray).hideHelp())
.addOption(
new Option('--system-tray-icon <string>', 'Custom system tray icon').default(DEFAULT.systemTrayIcon).hideHelp(),
)
.addOption(
new Option('--installer-language <string>', 'Installer language').default(DEFAULT.installerLanguage).hideHelp(),
)
.version(packageJson.version, '-v, --version', 'Output the current version')
.action(async (url: string, options: PakeCliOptions) => {
await checkUpdateTips();

9
bin/defaults.ts vendored
View File

@@ -8,10 +8,11 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
resizable: true,
hideTitleBar: false,
alwaysOnTop: false,
darkMode: false,
disabledWebShortcuts: false,
activationShortcut: '',
userAgent: '',
showSystemTray: true,
showSystemTray: false,
multiArch: false,
targets: 'deb',
useLocalFile: false,
@@ -19,13 +20,13 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
proxyUrl: "",
debug: false,
inject: [],
safeDomain: [],
installerLanguage: 'en-US',
};
// Just for cli development
export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & { url: string } = {
...DEFAULT_PAKE_OPTIONS,
url: 'https://www.xiaoyuzhoufm.com/',
name: 'XiaoYuZhou',
url: 'https://weread.qq.com',
name: 'WeRead',
hideTitleBar: true,
};

13
bin/helpers/merge.ts vendored
View File

@@ -14,6 +14,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
fullscreen,
hideTitleBar,
alwaysOnTop,
darkMode,
disabledWebShortcuts,
activationShortcut,
userAgent,
@@ -25,6 +26,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
resizable = true,
inject,
proxyUrl,
installerLanguage,
} = options;
const { platform } = process;
@@ -38,12 +40,16 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
hide_title_bar: hideTitleBar,
activation_shortcut: activationShortcut,
always_on_top: alwaysOnTop,
dark_mode: darkMode,
disabled_web_shortcuts: disabledWebShortcuts,
};
Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });
tauriConf.productName = name;
tauriConf.identifier = identifier;
tauriConf.package.productName = name;
tauriConf.tauri.bundle.identifier = identifier;
if (platform == "win32") {
tauriConf.tauri.bundle.windows.wix.language[0] = installerLanguage;
}
//Judge the type of URL, whether it is a file or a website.
const pathExists = await fsExtra.pathExists(url);
@@ -189,9 +195,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
tauriConf.pake.inject = [];
await fsExtra.writeFile(injectFilePath, '');
}
tauriConf.pake.proxy_url = proxyUrl || "";
// Save config file.
const platformConfigPaths: PlatformMap = {
win32: 'tauri.windows.conf.json',
@@ -212,7 +216,6 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
if (process.env.NODE_ENV === 'development') {
tauriConf2.bundle = bundleConf.bundle;
}
console.log('tauriConf', tauriConf2)
const configJsonPath = path.join(tauriConfigDirectory, 'tauri.conf.json');
await fsExtra.outputJSON(configJsonPath, tauriConf2, { spaces: 4 });
}

12
bin/types.ts vendored
View File

@@ -27,6 +27,10 @@ export interface PakeCliOptions {
// Enable windows always on top, default false
alwaysOnTop: boolean;
// Force Mac to use dark mode, default false
darkMode: boolean;
// Disable web shortcuts, default false
disabledWebShortcuts: boolean;
@@ -57,11 +61,11 @@ export interface PakeCliOptions {
/** 需要注入页面的外部脚本 */
inject: string[];
/* the domain that can use ipc or tauri javascript sdk */
safeDomain: string[];
// Proxy
proxyUrl: string;
// Proxy
proxyUrl: string;
// Installer language, valid for Windows users, default is en-US
installerLanguage: string;
}
export interface PakeAppOptions extends PakeCliOptions {