From f5869d62c8a9cdb639841699a95d7f532b84d395 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Fri, 6 Dec 2024 17:49:51 +0800 Subject: [PATCH] :sparkles: 2.0 Upgrade Plan --- .dockerignore | 11 ++++ .github/workflows/docker-publish.yml | 49 +++++++++++++++ Dockerfile | 57 +++++++++++++++++ README.md | 40 +++++++----- README_CN.md | 92 ++++++++++++++++++++++------ README_JP.md | 66 ++++++++++++-------- bin/README.md | 41 +++++++++++-- bin/README_CN.md | 43 ++++++++++--- bin/cli.ts | 9 ++- bin/defaults.ts | 9 +-- bin/helpers/merge.ts | 13 ++-- bin/types.ts | 12 ++-- script/build_with_pake_cli.js | 5 -- src-tauri/Cargo.lock | 12 ++++ src-tauri/Cargo.toml | 1 + src-tauri/pake.json | 1 + src-tauri/src/app/config.rs | 1 + src-tauri/src/app/invoke.rs | 2 +- src-tauri/src/app/menu.rs | 32 +--------- src-tauri/src/app/window.rs | 14 +++-- src-tauri/src/inject/style.js | 4 ++ src-tauri/src/lib.rs | 21 +++++-- 22 files changed, 399 insertions(+), 136 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker-publish.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..49bbb6b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.git +.gitignore + +**/target +**/node_modules + +**/*.log +**/*.md +**/tmp + +Dockerfile diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..114db3f --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,49 @@ +name: Build and Publish Docker Image + +on: + workflow_dispatch: # Manual + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=sha + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: linux/amd64 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..71eb285 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +# syntax=docker/dockerfile:1.4 +# Cargo build stage +FROM rust:1.80-slim AS cargo-builder +# Install Rust dependencies +RUN --mount=type=cache,target=/var/cache/apt \ + --mount=type=cache,target=/usr/local/cargo/registry \ + apt-get update && apt-get install -y --no-install-recommends \ + libdbus-1-dev libsoup2.4-dev libjavascriptcoregtk-4.0-dev \ + libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev \ + libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev \ + gnome-video-effects +COPY . /pake +WORKDIR /pake/src-tauri +# Build cargo packages and store cache +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + cargo fetch && \ + cargo build --release && \ + mkdir -p /cargo-cache && \ + cp -R /usr/local/cargo/registry /cargo-cache/ && \ + cp -R /usr/local/cargo/git /cargo-cache/ + +# Verify the content of /cargo-cache && clean unnecessary files +RUN ls -la /cargo-cache/registry && ls -la /cargo-cache/git && rm -rfd /cargo-cache/registry/src + +# Main build stage +FROM rust:1.80-slim AS builder +# Install Rust dependencies +RUN --mount=type=cache,target=/var/cache/apt \ + --mount=type=cache,target=/usr/local/cargo/registry \ + apt-get update && apt-get install -y --no-install-recommends \ + libdbus-1-dev libsoup2.4-dev libjavascriptcoregtk-4.0-dev \ + libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev \ + libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev \ + gnome-video-effects + +# Install Node.js 20.x +RUN --mount=type=cache,target=/var/cache/apt \ + curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ + apt-get update && apt-get install -y nodejs + +# Copy project files +COPY . /pake +WORKDIR /pake + +# Copy Rust build artifacts +COPY --from=cargo-builder /pake/src-tauri /pake/src-tauri +COPY --from=cargo-builder /cargo-cache/git /usr/local/cargo/git +COPY --from=cargo-builder /cargo-cache/registry /usr/local/cargo/registry + +# Install dependencies and build pake-cli +RUN --mount=type=cache,target=/root/.npm \ + npm install && \ + npm run cli:build + +# Set up the entrypoint +WORKDIR /output +ENTRYPOINT ["node", "/pake/cli.js"] diff --git a/README.md b/README.md index f1e5055..a800dd9 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ - - + + ChatGPT @@ -60,8 +60,8 @@ - - + + YouTube Music @@ -76,8 +76,8 @@ - - + + LiZhi @@ -92,8 +92,8 @@ - - + + Qwerty @@ -108,8 +108,8 @@ - - + + Flomo @@ -124,8 +124,8 @@ - - + + @@ -159,7 +159,7 @@ In addition, double-click the title bar to switch to full-screen mode. For Mac u ## Command-Line Packaging -![Pake](https://gw.alipayobjects.com/zos/k/zd/pake.gif) +![Pake](https://raw.githubusercontent.com/tw93/static/main/pake/pake.gif) **Pake provides a command line tool, making the flow of package customization quicker and easier. See [documentation](./bin/README.md) for more information.** @@ -172,6 +172,7 @@ pake url [OPTIONS]... # Feel free to play with Pake! It might take a while to prepare the environment the first time you launch Pake. pake https://weekly.tw93.fun --name Weekly --hide-title-bar + ``` If you are new to the command line, you can compile packages online with _GitHub Actions_. See the [Tutorial]() for more information. @@ -392,21 +393,28 @@ Pake's development can not be without these Hackers. They contributed a lot of c Po Chen + + + Tianj0o +
+ Qitianjia +
+ geekvest
Null
- + + houhoz
Hyzhao
- - + lakca diff --git a/README_CN.md b/README_CN.md index ae7a62e..7483d86 100644 --- a/README_CN.md +++ b/README_CN.md @@ -43,8 +43,8 @@ - - + + ChatGPT @@ -59,8 +59,8 @@ - - + + YouTube Music @@ -75,8 +75,8 @@ - - + + LiZhi @@ -91,8 +91,8 @@ - - + + Qwerty @@ -107,8 +107,8 @@ - - + + Flomo @@ -123,8 +123,8 @@ - - + + @@ -159,10 +159,7 @@ ## 命令行一键打包 - - - -

+![Pake](https://raw.githubusercontent.com/tw93/static/main/pake/pake.gif) **Pake 提供了命令行工具,可以更快捷方便地一键自定义打你需要的包,详细可见 [文档](./bin/README_CN.md)。** @@ -259,6 +256,13 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢
+ + + YangguangZhou +
+ Jerry Zhou +
+ AielloChan @@ -280,6 +284,13 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢 Pake Actions + + + eltociear +
+ Ikko Eltociear Ashimine +
+ QingZ11 @@ -293,7 +304,8 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢
孟世博
- + + 2nthony @@ -307,8 +319,7 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢
Null
- - + imabutahersiddik @@ -343,6 +354,28 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢
Fechin
+ + + + + ImgBotApp +
+ Imgbot +
+ + + + droid-Q +
+ Jiaqi Gu +
+ + + + mattbajorek +
+ Matt Bajorek +
@@ -357,6 +390,20 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢
Po Chen
+ + + + Tianj0o +
+ Qitianjia +
+ + + + geekvest +
+ Null +
@@ -373,6 +420,13 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢 Null + + + liudonghua123 +
+ Liudonghua +
+ liusishan diff --git a/README_JP.md b/README_JP.md index dd4a1de..1fe2c9c 100644 --- a/README_JP.md +++ b/README_JP.md @@ -44,8 +44,8 @@ - - + + ChatGPT @@ -60,8 +60,8 @@ - - + + YouTube Music @@ -76,8 +76,8 @@ - - + + LiZhi @@ -92,8 +92,8 @@ - - + + Qwerty @@ -108,8 +108,8 @@ - - + + Flomo @@ -124,8 +124,8 @@ - - + + @@ -159,7 +159,7 @@ ## コマンドラインパッケージング -![Pake](https://gw.alipayobjects.com/zos/k/zd/pake.gif) +![Pake](https://raw.githubusercontent.com/tw93/static/main/pake/pake.gif) **Pake はコマンドラインツールを提供しており、必要なパッケージをより迅速かつ簡単にカスタマイズすることができます。詳細は[ドキュメント](./bin/README.md)をご覧ください。** @@ -285,6 +285,13 @@ Pake の開発はこれらのハッカーたちなしにはあり得ませんで Pake Actions + + + eltociear +
+ Ikko Eltociear Ashimine +
+ QingZ11 @@ -298,15 +305,15 @@ Pake の開発はこれらのハッカーたちなしにはあり得ませんで
孟世博
- + + 2nthony
2nthony
- - + ACGNnsj @@ -348,13 +355,6 @@ Pake の開発はこれらのハッカーたちなしにはあり得ませんで
Fechin
- - - - eltociear -
- Ikko Eltociear Ashimine -
@@ -371,6 +371,13 @@ Pake の開発はこれらのハッカーたちなしにはあり得ませんで Jiaqi Gu + + + mattbajorek +
+ Matt Bajorek +
+ Milo123459 @@ -385,13 +392,21 @@ Pake の開発はこれらのハッカーたちなしにはあり得ませんで Po Chen + + + Tianj0o +
+ Qitianjia +
+ geekvest
Null
- + + houhoz @@ -405,8 +420,7 @@ Pake の開発はこれらのハッカーたちなしにはあり得ませんで
Null
- - + liudonghua123 diff --git a/bin/README.md b/bin/README.md index 02c2d63..92c5f14 100644 --- a/bin/README.md +++ b/bin/README.md @@ -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 ``` +#### [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 +``` + #### [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 ``` #### [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 \ + + +# For example: +docker run -it --rm \ + -v ./packages:/output \ + ghcr.io/tw93/pake \ + https://example.com --name myapp --icon ./icon.png + +``` diff --git a/bin/README_CN.md b/bin/README_CN.md index e7eccda..9898402 100644 --- a/bin/README_CN.md +++ b/bin/README_CN.md @@ -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 ``` +#### [installer-language] + +设置 Windows 安装包语言。支持 `zh-CN`、`ja-JP`,更多在 [Tauri 文档](https://tauri.app/zh-cn/v1/guides/building/windows/#internationalization)。默认为 `en-US`。 + +```shell +--installer-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 ``` #### [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 \ + + +# For example: +docker run -it --rm \ + -v ./packages:/output \ + ghcr.io/tw93/pake \ + https://example.com --name myapp --icon ./icon.png + +``` diff --git a/bin/cli.ts b/bin/cli.ts index 2054d5f..f08d87a 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -39,20 +39,19 @@ program new Option('--targets ', '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 ', 'Custom system tray icon').default(DEFAULT.systemTrayIcon).hideHelp(), ) + .addOption( + new Option('--installer-language ', 'Installer language').default(DEFAULT.installerLanguage).hideHelp(), + ) .version(packageJson.version, '-v, --version', 'Output the current version') .action(async (url: string, options: PakeCliOptions) => { await checkUpdateTips(); diff --git a/bin/defaults.ts b/bin/defaults.ts index 5093b3e..e5278be 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -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, }; diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.ts index dcdf6c9..ea47aee 100644 --- a/bin/helpers/merge.ts +++ b/bin/helpers/merge.ts @@ -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 }); } diff --git a/bin/types.ts b/bin/types.ts index 105f71a..0bbd935 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -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 { diff --git a/script/build_with_pake_cli.js b/script/build_with_pake_cli.js index 41cfb1c..895a3d2 100644 --- a/script/build_with_pake_cli.js +++ b/script/build_with_pake_cli.js @@ -17,7 +17,6 @@ console.log('hide-title-bar: ', process.env.HIDE_TITLE_BAR); console.log('resize: ', process.env.RESIZE); console.log('is multi arch? only for Mac: ', process.env.MULTI_ARCH); console.log('targets type? only for Linux: ', process.env.TARGETS); -console.log('safe-domain: ', process.env.SAFE_DOMAIN); console.log('===========================\n'); cd('node_modules/pake-cli'); @@ -40,10 +39,6 @@ if (process.env.TARGETS) { params = `${params} --targets ${process.env.TARGETS}`; } -if (process.env.SAFE_DOMAIN) { - params = `${params} --safe-domain ${process.env.SAFE_DOMAIN}`; -} - if (process.platform === 'win32' || process.platform === 'linux') { params = `${params} --show-system-tray`; } diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 23674ba..1232318 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2451,6 +2451,7 @@ dependencies = [ "tauri-plugin-oauth", "tauri-plugin-shell", "tauri-plugin-window-state", + "tokio", ] [[package]] @@ -3409,6 +3410,15 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "simd-adler32" version = "0.3.7" @@ -4178,7 +4188,9 @@ dependencies = [ "bytes", "libc", "mio", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2", "tokio-macros", "windows-sys 0.52.0", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 6dae424..2e1b366 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -28,6 +28,7 @@ tauri-plugin-http = "2.0.3" [target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies] tauri-plugin-global-shortcut = { version = "2.0.1" } tauri-plugin-shell = "2.0.0" +tokio = { version = "1", features = ["full"] } [dev-dependencies] cargo-bloat = "0.12.1" diff --git a/src-tauri/pake.json b/src-tauri/pake.json index ad15638..304b8e9 100644 --- a/src-tauri/pake.json +++ b/src-tauri/pake.json @@ -9,6 +9,7 @@ "height": 780, "resizable": true, "always_on_top": false, + "dark_mode": false, "activation_shortcut": "", "disabled_web_shortcuts": false } diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rs index 5c216c1..f201eb0 100644 --- a/src-tauri/src/app/config.rs +++ b/src-tauri/src/app/config.rs @@ -10,6 +10,7 @@ pub struct WindowConfig { pub resizable: bool, pub url_type: String, pub always_on_top: bool, + pub dark_mode: bool, pub disabled_web_shortcuts: bool, pub activation_shortcut: String, } diff --git a/src-tauri/src/app/invoke.rs b/src-tauri/src/app/invoke.rs index 374d643..078ee2c 100644 --- a/src-tauri/src/app/invoke.rs +++ b/src-tauri/src/app/invoke.rs @@ -3,8 +3,8 @@ use std::fs::{self, File}; use std::io::Write; use std::str::FromStr; use tauri::http::Method; -use tauri_plugin_http::reqwest::{ClientBuilder, Request}; use tauri::{command, AppHandle, Manager, Url, WebviewWindow}; +use tauri_plugin_http::reqwest::{ClientBuilder, Request}; #[derive(serde::Deserialize)] pub struct DownloadFileParams { diff --git a/src-tauri/src/app/menu.rs b/src-tauri/src/app/menu.rs index d74eba3..bce364a 100644 --- a/src-tauri/src/app/menu.rs +++ b/src-tauri/src/app/menu.rs @@ -1,14 +1,11 @@ use tauri::{ - image::Image, menu::{MenuBuilder, MenuItemBuilder}, - tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent}, + tray::TrayIconBuilder, AppHandle, Manager, }; use tauri_plugin_window_state::{AppHandleExt, StateFlags}; -use super::config::PakeConfig; - -pub fn set_system_tray(app: &AppHandle, pake_config: &PakeConfig) -> tauri::Result<()> { +pub fn set_system_tray(app: &AppHandle) -> tauri::Result<()> { let hide_app = MenuItemBuilder::with_id("hide_app", "Hide").build(app)?; let show_app = MenuItemBuilder::with_id("show_app", "Show").build(app)?; let quit = MenuItemBuilder::with_id("quit", "Quit").build(app)?; @@ -17,32 +14,7 @@ pub fn set_system_tray(app: &AppHandle, pake_config: &PakeConfig) -> tauri::Resu .build()?; app.app_handle().remove_tray_by_id("pake-tray"); let tray = TrayIconBuilder::new() - .icon(Image::from_path(pake_config.system_tray_path.as_str())?) .menu(&menu) - .on_tray_icon_event(move |tray, event| { - if let TrayIconEvent::Click { - button: MouseButton::Left, - button_state: MouseButtonState::Up, - .. - } = event - { - println!("click"); - - let app = tray.app_handle(); - - #[cfg(not(target_os = "macos"))] - { - if let Some(webview_window) = app.get_webview_window("pake") { - let _ = webview_window.show(); - let _ = webview_window.set_focus(); - } - } - #[cfg(target_os = "macos")] - { - tauri::AppHandle::show(&app.app_handle()).unwrap(); - } - } - }) .on_menu_event(move |app, event| match event.id().as_ref() { "hide_app" => { app.get_webview_window("pake").unwrap().minimize().unwrap(); diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index b50e533..ad1cf9c 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -3,7 +3,7 @@ use std::{path::PathBuf, str::FromStr}; use tauri::{App, Url, WebviewUrl, WebviewWindow, WebviewWindowBuilder}; #[cfg(target_os = "macos")] -use tauri::TitleBarStyle; +use tauri::{Theme, TitleBarStyle}; pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> WebviewWindow { let window_config = config @@ -31,7 +31,6 @@ pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> Web .resizable(window_config.resizable) .fullscreen(window_config.fullscreen) .inner_size(window_config.width, window_config.height) - .disable_drag_drop_handler() .always_on_top(window_config.always_on_top) .initialization_script(&config_script) .initialization_script(include_str!("../inject/component.js")) @@ -41,7 +40,6 @@ pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> Web .initialization_script(include_str!("../inject/custom.js")); if config.proxy_url != "" { - println!("{}", &config.proxy_url); window_builder = window_builder.proxy_url(Url::from_str(&config.proxy_url.as_str()).unwrap()); } @@ -53,12 +51,18 @@ pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> Web } else { TitleBarStyle::Visible }; - window_builder = window_builder.title_bar_style(title_bar_style) + window_builder = window_builder.title_bar_style(title_bar_style); + + if window_config.dark_mode { + window_builder = window_builder.theme(Some(Theme::Dark)); + } } #[cfg(not(target_os = "macos"))] { - window_builder = window_builder.data_directory(_data_dir); + window_builder = window_builder + .data_directory(_data_dir) + .title(app.package_info().name.clone()); } window_builder.build().expect("Failed to build window") diff --git a/src-tauri/src/inject/style.js b/src-tauri/src/inject/style.js index 816963e..c361d65 100644 --- a/src-tauri/src/inject/style.js +++ b/src-tauri/src/inject/style.js @@ -342,6 +342,10 @@ window.addEventListener('DOMContentLoaded', _event => { padding-top: 20px; } + #__next > div.relative.z-0.flex.h-full.w-full.overflow-hidden > div.flex-shrink-0.overflow-x-hidden.bg-token-sidebar-surface-primary > div > div > div > div > nav, #__next > div.relative.z-0.flex.h-full.w-full.overflow-hidden > div.relative.flex.h-full.max-w-full.flex-1.flex-col.overflow-hidden > main { + padding-top: 6px; + } + #__next > div.AnnouncementWrapper_container__Z51yh > div > aside.SidebarLayout_sidebar__SXeDJ.SidebarLayout_left__k163a > div > div > header{ padding-left: 84px; padding-top: 10px; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 864ca4f..2a7f4ad 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -12,6 +12,9 @@ use tauri_plugin_window_state::Builder as windowStatePlugin; use util::{get_data_dir, get_pake_config}; use window::get_window; +#[cfg(target_os = "macos")] +use std::time::Duration; + pub fn run_app() { let (pake_config, tauri_config) = get_pake_config(); @@ -39,7 +42,7 @@ pub fn run_app() { _window.show().unwrap(); if show_system_tray { - let _ = set_system_tray(&app.app_handle(), &pake_config); + let _ = set_system_tray(&app.app_handle()); } else { app.app_handle().remove_tray_by_id("pake-tray"); } @@ -74,14 +77,24 @@ pub fn run_app() { }) .on_window_event(|window, event| { if let tauri::WindowEvent::CloseRequested { api, .. } = event { + let window = window.clone(); + #[cfg(target_os = "macos")] { - window.minimize().unwrap(); - window.hide().unwrap(); + let window_handle = window.clone(); + tauri::async_runtime::spawn(async move { + if window_handle.is_fullscreen().unwrap_or(false) { + window_handle.set_fullscreen(false).unwrap(); + // Give a small delay to ensure the full-screen exit operation is completed. + tokio::time::sleep(Duration::from_millis(900)).await; + } + window_handle.minimize().unwrap(); + window_handle.hide().unwrap(); + }); } #[cfg(not(target_os = "macos"))] - event.window().close().unwrap(); + window.close().unwrap(); api.prevent_close(); }