diff --git a/.gitignore b/.gitignore index 6227cbb..66c28c6 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,8 @@ dist-ssr *.njsproj *.sln *.sw? +.npmrc +output package-lock.json yarn.lock diff --git a/README.md b/README.md index c272470..f120d3e 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,19 @@ 更多常用 App 下载可以去 [Releases](https://github.com/tw93/Pake/releases) 中看看。 -## 快捷键 +## 快捷键(Windows/Linux) +1. Ctrl + :返回上一个页面 +2. Ctrl + :去下一个页面 +3. Ctrl + :自动滚动到页面顶部 +4. Ctrl + :自动滚动到页面底部 +5. Ctrl + r:刷新页面 +6. Ctrl + -:缩小页面 +7. Ctrl + +:放大页面 +8. Ctrl + =:放大页面 +9. Ctrl + 0:重置页面缩放 + +## 快捷键(Mac) 1. + [:返回上一个页面 2. + ]:去下一个页面 3. + :自动滚动到页面顶部 @@ -77,6 +88,10 @@ 此外还支持双击头部进行全屏切换,拖拽头部进行移动窗口,还有其他需求,欢迎提过来。 +## 已知Bug +- Windows下不能安装到C:\Program File,会直接闪退。建议安装到其他目录,比如D:\Program Files。 +- Linux下暂时不能存cookie,即应用关闭后数据清空,账号自动推出。 + ## 开发 开始前参考 [Tauri](https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-macos) 快速配置好环境,如果你想打包 Windows、Linux 系统的包,可以参考 [Building](https://tauri.app/v1/guides/building/) 文档 @@ -88,8 +103,20 @@ npm i // 调试 npm run dev -// 打包 +// 打包(Mac) npm run build + +// 打包(Windows) +npm run build:windows + +// 打包(Linux) +npm run build:linux + +// 一键打包所有项目(Linux/Mac) +chmod +x build.sh && ./build.sh + +// 一键打包所有项目(Windows) +.\build.bat ``` ## 打新包 diff --git a/README_EN.md b/README_EN.md index 0990d3c..5ab88fa 100644 --- a/README_EN.md +++ b/README_EN.md @@ -63,7 +63,20 @@ More common apps can be downloaded from [Releases](https://github.com/tw93/Pake/releases). -## Shortcuts + +## Shortcuts(Windows/Linux) + +1. Ctrl + :Return to the previous page +2. Ctrl + :Go to the next page +3. Ctrl + :Auto scroll to top of page +4. Ctrl + :Auto scroll to bottom of page +5. Ctrl + r:Refresh Page +6. Ctrl + -:Zoom out the page +7. Ctrl + +:Zoom in the Page +8. Ctrl + =:Zoom in the Page +9. Ctrl + 0:Reset the page zoom + +## Shortcuts(Mac) 1. + [:Return to the previous page 2. + ]:Go to the next page @@ -77,6 +90,10 @@ More common apps can be downloaded from [Releases](https://github.com/tw93/Pake/ In addition, it supports double clicking the head to switch to full screen, and dragging the head to move the window +## Bugs +- It cannot be installed to C:\Program File under Windows, and it will crash directly. It is recommended to install to another directory, such as D:\Program Files. +- Under Linux, cookies cannot be stored temporarily, that is, the data will be cleared after the application is closed, and the account will be automatically released. + ## Development Refer to the [Tauri documentation](https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-macos) to quickly configure your environment before you start, if you want to package Windows or Linux systems, you can refer to [Building](https://tauri.app/v1/guides/building/) Documentation. @@ -88,10 +105,25 @@ npm i // Local development npm run dev -// Pack +// Pack (Mac) npm run build + +// Pack (Windows) +npm run build:windows + +// Pack(Linux) +npm run build:linux + +// One-click packaging of all projects (Linux/Mac) +chmod +x build.sh && ./build.sh + +// One-click packaging of all projects (Windows) +.\build.bat ``` +// Package all your projects in one click +chmod +x build.sh && ./build.sh + ## New pack 1. Modify the `tauri.conf.json` in the `src-tauri` directory to include 4 fields `url, productName, icon, identifier`, icon can be selected from the `icons` directory or downloaded from [macOSicons](https://macosicons.com/#/) to match the product. diff --git a/app.csv b/app.csv new file mode 100644 index 0000000..b408108 --- /dev/null +++ b/app.csv @@ -0,0 +1,4 @@ +weread,微信阅读,weread.qq.com +aliyuque,语雀,www.yuque.com +flomo,浮墨,flomoapp.com +weread,微信阅读,weread.qq.com diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..6e5ff9b --- /dev/null +++ b/build.bat @@ -0,0 +1,69 @@ +@echo off +chcp 65001 + +if not exist node_modules ( + call npm i +) + +if not exist output ( + mkdir output +) + + +if not exist output\windows ( + mkdir output\windows +) + + echo. + echo ======================= + echo "build for windows" + echo ======================= + echo. + +:: total package number +set /A index=1 +for /f %%a in (' find /c /v "" ^<"app.csv" ') do set /A total=%%a + +set old_name=weread +set old_zh_name=微信阅读 +set old_url=weread.qq.com + +for /f "tokens=1-3 delims=," %%i in (app.csv) do ( + setlocal enabledelayedexpansion + set name=%%i + set name_zh=%%j + set url=%%k + @echo on + + ::echo name is !name! !name_zh! !url! + :: replace url + .\sd.exe !old_url! !url! src-tauri\tauri.conf.json + ::replace pacakge name + .\sd.exe !old_name! !name! src-tauri\tauri.conf.json + echo update ico with 32x32 pictue + echo .\sd.exe !old_name! !name! src-tauri\src\main.rs + .\sd.exe !old_name! !name! src-tauri\src\main.rs + ::copy src-tauri\png\!name!_32.ico src-tauri\icons\icon.ico + echo. + ::update package info + set old_zh_name=!name_zh! + set old_name=!name! + set old_url=!url! + ::build package + echo building package !index!/!total! + echo package name is !name! !name_zh! + echo npm run build:windows + @echo off + call npm run tauri build -- --target x86_64-pc-windows-msvc + move src-tauri\target\x86_64-pc-windows-msvc\release\bundle\msi\*.msi output\windows + + @echo on + echo package build success! + echo. + echo. + + set /A index=index+1 + @echo off + +) +echo "output dir is output\windows" diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..327806c --- /dev/null +++ b/build.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +if [ ! -d "node_modules" ]; then + npm i +fi + + +if [ ! -d "output" ]; then + mkdir output +fi + +if [[ "$OSTYPE" =~ ^linux ]]; then + if [ ! -d "output/linux" ]; then + mkdir output/linux + fi +fi + + +if [[ "$OSTYPE" =~ ^darwin ]]; then + if [ ! -d "output/macos" ]; then + mkdir output/macos + fi +fi + + + + +# total package number +export total=`sed -n '$=' app.csv` +export index=1 + +old_name="weread" +old_zh_name="微信阅读" +old_url="weread.qq.com" +package_prefix="com-tw93" + +if [[ "$OSTYPE" =~ ^linux ]]; then + echo "===============" + echo "Build for Linux" + echo "===============" + # for linux, package name may be com.xxx.xxx + echo "rename package name" + export desktop_file="src-tauri/assets/${package_prefix}.weread.desktop" + sed -i "s/\"productName\": \"weread\"/\"productName\": \"${package_prefix}-weread\"/g" src-tauri/tauri.conf.json +fi + +if [[ "$OSTYPE" =~ ^darwin ]]; then + echo "===============" + echo "Build for MacOS" + echo "===============" +fi + +while read line +do + package_name=$(echo ${line} | cut -d , -f 1) + package_zh_name=$(echo ${line} | cut -d , -f 2) + url=$(echo ${line} | cut -d , -f 3) + echo "update package name and url" + # replace package info + + if [[ "$OSTYPE" =~ ^linux ]]; then + sed -i "s/${old_url}/${url}/g" src-tauri/tauri.conf.json + sed -i "s/${old_name}/${package_name}/g" src-tauri/tauri.conf.json + echo "update ico with 32x32 pictue" + sed -i "s/${old_name}/${package_name}/g" src-tauri/src/main.rs + + fi + + if [[ "$OSTYPE" =~ ^darwin ]]; then + sed -i '' "s|${old_url}|${url}|g" src-tauri/tauri.conf.json + sed -i '' "s|${old_name}|${package_name}|g" src-tauri/tauri.conf.json + echo "update ico with 32x32 pictue" + sed -i '' "s|${old_name}|${package_name}|g" src-tauri/src/main.rs + fi + + # echo "update ico with 32x32 pictue" + # cp "src-tauri/png/${package_name}_32.ico" "src-tauri/icons/icon.ico" + + if [[ "$OSTYPE" =~ ^linux ]]; then + echo "update desktop" + old_desktop="src-tauri/assets/${package_prefix}-${old_name}.desktop" + new_desktop="src-tauri/assets/${package_prefix}-${package_name}.desktop" + mv ${old_desktop} ${new_desktop} + sed -i "s/${old_zh_name}/${package_zh_name}/g" ${new_desktop} + sed -i "s/${old_name}/${package_name}/g" ${new_desktop} + fi + + # update package info + old_zh_name=${package_zh_name} + old_name=${package_name} + old_url=${url} + + echo "building package ${index}/${total}" + echo "package name is ${package_name} (${package_zh_name})" + npm run tauri build + echo "package build success!" + index=$(($index+1)) + + if [[ "$OSTYPE" =~ ^linux ]]; then + mv src-tauri/target/release/bundle/deb/*.deb output/linux + fi + + if [[ "$OSTYPE" =~ ^darwin ]]; then + mv src-tauri/target/release/bundle/dmg/*.dmg output/macos + echo "" + fi +done < app.csv + +echo "build all package success!" +if [[ "$OSTYPE" =~ ^linux ]]; then + echo "result file in output/linux" +fi + +if [[ "$OSTYPE" =~ ^darwin ]]; then + echo "result file in output/macos" +fi \ No newline at end of file diff --git a/icns2png.py b/icns2png.py new file mode 100644 index 0000000..cf9a998 --- /dev/null +++ b/icns2png.py @@ -0,0 +1,38 @@ +""" +批量将icns文件转成png文件 +Batch convert ICNS files to PNG files +""" +import os + +try: + from PIL import Image +except ImportError: + os.system("pip install Pillow") + from PIL import Image + + +if __name__ == "__main__": + now_dir = os.path.dirname(os.path.abspath(__file__)) + icons_dir = os.path.join(now_dir, "src-tauri", "icons") + png_dir = os.path.join(now_dir, "src-tauri", "png") + if not os.path.exists(png_dir): + os.mkdir(png_dir) + file_list = os.listdir(icons_dir) + file_list = [file for file in file_list if file.endswith(".icns")] + for file in file_list: + icns_path = os.path.join(icons_dir, file) + image = Image.open(icns_path) + image_512 = image.copy().resize((512, 512)) + image_256 = image.copy().resize((256, 256)) + image_32 = image.copy().resize((32, 32)) + image_name = os.path.splitext(file)[0] + image_512_path = os.path.join(png_dir, image_name + "_512.png") + image_256_path = os.path.join(png_dir, image_name + "_256.ico") + image_32_path = os.path.join(png_dir, image_name + "_32.ico") + image_512.save(image_512_path, "PNG") + image_256.save(image_256_path, "ICO") + image_32.save(image_32_path, "ICO") + print("png file write success.") + print(f"There are {len(os.listdir(png_dir))} png picture in ", png_dir) + + diff --git a/package.json b/package.json index d8c176e..e846685 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "dev:debug": "npm run tauri dev -- --features devtools", "build": "npm run tauri build -- --target universal-apple-darwin", "build:windows": "npm run tauri build -- --target x86_64-pc-windows-msvc", + "build:linux": "npm run tauri build --release", "tauri": "tauri" }, "license": "MIT", diff --git a/sd.exe b/sd.exe new file mode 100644 index 0000000..285ed10 Binary files /dev/null and b/sd.exe differ diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index c29bb4a..7e124cc 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -57,6 +57,7 @@ checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" name = "app" version = "0.1.0" dependencies = [ + "image", "serde", "serde_json", "tauri", @@ -118,6 +119,12 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "bit_field" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" + [[package]] name = "bitflags" version = "1.3.2" @@ -395,6 +402,30 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + [[package]] name = "crossbeam-utils" version = "0.8.10" @@ -405,6 +436,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "crypto-common" version = "0.1.3" @@ -514,15 +551,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "deflate" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f" -dependencies = [ - "adler32", -] - [[package]] name = "derive_more" version = "0.99.17" @@ -594,6 +622,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c" +[[package]] +name = "either" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" + [[package]] name = "embed_plist" version = "1.2.2" @@ -609,6 +643,21 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "exr" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb5f255b5980bb0c8cf676b675d1a99be40f316881444f44e0462eaf5df5ded" +dependencies = [ + "bit_field", + "flume", + "half", + "lebe", + "miniz_oxide 0.6.2", + "smallvec", + "threadpool", +] + [[package]] name = "fastrand" version = "1.7.0" @@ -647,7 +696,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" dependencies = [ "crc32fast", - "miniz_oxide", + "miniz_oxide 0.5.3", +] + +[[package]] +name = "flume" +version = "0.10.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" +dependencies = [ + "futures-core", + "futures-sink", + "nanorand", + "pin-project", + "spin", ] [[package]] @@ -734,6 +796,12 @@ dependencies = [ "syn", ] +[[package]] +name = "futures-sink" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" + [[package]] name = "futures-task" version = "0.3.21" @@ -876,8 +944,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "gif" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06" +dependencies = [ + "color_quant", + "weezl", ] [[package]] @@ -1040,6 +1120,15 @@ dependencies = [ "syn", ] +[[package]] +name = "half" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad6a9459c9c30b177b925162351f97e7d967c7ea8bab3b8352805327daf45554" +dependencies = [ + "crunchy", +] + [[package]] name = "hashbrown" version = "0.12.1" @@ -1148,16 +1237,21 @@ dependencies = [ [[package]] name = "image" -version = "0.24.2" +version = "0.24.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28edd9d7bc256be2502e325ac0628bde30b7001b9b52e0abe31a1a9dc2701212" +checksum = "69b7ea949b537b0fd0af141fff8c77690f2ce96f4f41f042ccb6c69c6c965945" dependencies = [ "bytemuck", "byteorder", "color_quant", - "num-iter", + "exr", + "gif", + "jpeg-decoder", "num-rational", "num-traits", + "png 0.17.7", + "scoped_threadpool", + "tiff", ] [[package]] @@ -1266,6 +1360,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" +[[package]] +name = "jpeg-decoder" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" +dependencies = [ + "rayon", +] + [[package]] name = "js-sys" version = "0.3.58" @@ -1304,6 +1407,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lebe" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" + [[package]] name = "libc" version = "0.2.126" @@ -1443,6 +1552,24 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + +[[package]] +name = "nanorand" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" +dependencies = [ + "getrandom 0.2.7", +] + [[package]] name = "native-tls" version = "0.2.10" @@ -1887,6 +2014,26 @@ dependencies = [ "siphasher", ] +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -1926,21 +2073,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0b0cabbbd20c2d7f06dbf015e06aad59b6ca3d9ed14848783e98af9aaf19925" dependencies = [ "bitflags", - "deflate 0.7.20", + "deflate", "inflate", "num-iter", ] [[package]] name = "png" -version = "0.17.5" +version = "0.17.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc38c0ad57efb786dd57b9864e5b18bae478c00c824dc55a38bbc9da95dde3ba" +checksum = "5d708eaf860a19b19ce538740d2b4bdeeb8337fa53f7738455e706623ad5c638" dependencies = [ "bitflags", "crc32fast", - "deflate 1.0.0", - "miniz_oxide", + "flate2", + "miniz_oxide 0.6.2", ] [[package]] @@ -2103,6 +2250,30 @@ dependencies = [ "cty", ] +[[package]] +name = "rayon" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "redox_syscall" version = "0.2.13" @@ -2243,6 +2414,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" + [[package]] name = "scopeguard" version = "1.1.0" @@ -2503,6 +2680,15 @@ dependencies = [ "system-deps 5.0.0", ] +[[package]] +name = "spin" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +dependencies = [ + "lock_api", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -2643,7 +2829,7 @@ dependencies = [ "once_cell", "parking_lot", "paste", - "png 0.17.5", + "png 0.17.7", "raw-window-handle", "scopeguard", "serde", @@ -2689,7 +2875,7 @@ dependencies = [ "once_cell", "parking_lot", "paste", - "png 0.17.5", + "png 0.17.7", "raw-window-handle", "scopeguard", "serde", @@ -2791,7 +2977,7 @@ dependencies = [ "ico", "json-patch", "plist", - "png 0.17.5", + "png 0.17.7", "proc-macro2", "quote", "regex", @@ -2948,6 +3134,26 @@ dependencies = [ "once_cell", ] +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "tiff" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17def29300a156c19ae30814710d9c63cd50288a49c6fd3a10ccfbe4cf886fd" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + [[package]] name = "time" version = "0.3.11" @@ -3369,6 +3575,12 @@ dependencies = [ "windows-metadata", ] +[[package]] +name = "weezl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" + [[package]] name = "widestring" version = "1.0.2" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 01ae264..74c3d4e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -12,14 +12,16 @@ rust-version = "1.61.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [build-dependencies] -tauri-build = { version = "1.1.1", features = [] } +tauri-build = { version = "1.2.0", features = [] } + [dependencies] serde_json = "1.0.86" serde = { version = "1.0.145", features = ["derive"] } -tauri = { version = "1.1.1", features = ["api-all"] } +tauri = { version = "1.2.0", features = ["api-all"] } +image = "0.24.5" wry = "0.21.1" -tauri-utils = "1.1.1" +tauri-utils = "1.2.0" webbrowser = "0.8.2" [features] diff --git a/src-tauri/assets/com-tw93-weread.desktop b/src-tauri/assets/com-tw93-weread.desktop new file mode 100644 index 0000000..0978834 --- /dev/null +++ b/src-tauri/assets/com-tw93-weread.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Encoding=UTF-8 +Categories=Office +Exec=com-tw93-weread +Icon=com-tw93-weread +Name=com-tw93-weread +Name[zh_CN]=微信阅读 +StartupNotify=true +Terminal=false +Type=Application diff --git a/src-tauri/icons/icon.ico b/src-tauri/icons/icon.ico index 8956e14..351c871 100644 Binary files a/src-tauri/icons/icon.ico and b/src-tauri/icons/icon.ico differ diff --git a/src-tauri/icons/weRead.icns b/src-tauri/icons/weread.icns similarity index 100% rename from src-tauri/icons/weRead.icns rename to src-tauri/icons/weread.icns diff --git a/src-tauri/png/aliyuque_256.ico b/src-tauri/png/aliyuque_256.ico new file mode 100644 index 0000000..42c62b3 Binary files /dev/null and b/src-tauri/png/aliyuque_256.ico differ diff --git a/src-tauri/png/aliyuque_32.ico b/src-tauri/png/aliyuque_32.ico new file mode 100644 index 0000000..a993cf7 Binary files /dev/null and b/src-tauri/png/aliyuque_32.ico differ diff --git a/src-tauri/png/aliyuque_512.png b/src-tauri/png/aliyuque_512.png new file mode 100644 index 0000000..796f75d Binary files /dev/null and b/src-tauri/png/aliyuque_512.png differ diff --git a/src-tauri/png/anymind_256.ico b/src-tauri/png/anymind_256.ico new file mode 100644 index 0000000..dda2147 Binary files /dev/null and b/src-tauri/png/anymind_256.ico differ diff --git a/src-tauri/png/anymind_32.ico b/src-tauri/png/anymind_32.ico new file mode 100644 index 0000000..a66c510 Binary files /dev/null and b/src-tauri/png/anymind_32.ico differ diff --git a/src-tauri/png/anymind_512.png b/src-tauri/png/anymind_512.png new file mode 100644 index 0000000..056edb2 Binary files /dev/null and b/src-tauri/png/anymind_512.png differ diff --git a/src-tauri/png/code_256.ico b/src-tauri/png/code_256.ico new file mode 100644 index 0000000..6da8d09 Binary files /dev/null and b/src-tauri/png/code_256.ico differ diff --git a/src-tauri/png/code_32.ico b/src-tauri/png/code_32.ico new file mode 100644 index 0000000..d3bc12f Binary files /dev/null and b/src-tauri/png/code_32.ico differ diff --git a/src-tauri/png/code_512.png b/src-tauri/png/code_512.png new file mode 100644 index 0000000..cded608 Binary files /dev/null and b/src-tauri/png/code_512.png differ diff --git a/src-tauri/png/fanfou_256.ico b/src-tauri/png/fanfou_256.ico new file mode 100644 index 0000000..91c7d46 Binary files /dev/null and b/src-tauri/png/fanfou_256.ico differ diff --git a/src-tauri/png/fanfou_32.ico b/src-tauri/png/fanfou_32.ico new file mode 100644 index 0000000..14b8e1d Binary files /dev/null and b/src-tauri/png/fanfou_32.ico differ diff --git a/src-tauri/png/fanfou_512.png b/src-tauri/png/fanfou_512.png new file mode 100644 index 0000000..9252593 Binary files /dev/null and b/src-tauri/png/fanfou_512.png differ diff --git a/src-tauri/png/flomo_256.ico b/src-tauri/png/flomo_256.ico new file mode 100644 index 0000000..a796102 Binary files /dev/null and b/src-tauri/png/flomo_256.ico differ diff --git a/src-tauri/png/flomo_32.ico b/src-tauri/png/flomo_32.ico new file mode 100644 index 0000000..e1ecbeb Binary files /dev/null and b/src-tauri/png/flomo_32.ico differ diff --git a/src-tauri/png/flomo_512.png b/src-tauri/png/flomo_512.png new file mode 100644 index 0000000..e868bc4 Binary files /dev/null and b/src-tauri/png/flomo_512.png differ diff --git a/src-tauri/png/fone_256.ico b/src-tauri/png/fone_256.ico new file mode 100644 index 0000000..95826c0 Binary files /dev/null and b/src-tauri/png/fone_256.ico differ diff --git a/src-tauri/png/fone_32.ico b/src-tauri/png/fone_32.ico new file mode 100644 index 0000000..b500385 Binary files /dev/null and b/src-tauri/png/fone_32.ico differ diff --git a/src-tauri/png/fone_512.png b/src-tauri/png/fone_512.png new file mode 100644 index 0000000..f7e096c Binary files /dev/null and b/src-tauri/png/fone_512.png differ diff --git a/src-tauri/png/jdread_256.ico b/src-tauri/png/jdread_256.ico new file mode 100644 index 0000000..55512fb Binary files /dev/null and b/src-tauri/png/jdread_256.ico differ diff --git a/src-tauri/png/jdread_32.ico b/src-tauri/png/jdread_32.ico new file mode 100644 index 0000000..b1c54f3 Binary files /dev/null and b/src-tauri/png/jdread_32.ico differ diff --git a/src-tauri/png/jdread_512.png b/src-tauri/png/jdread_512.png new file mode 100644 index 0000000..5d41b36 Binary files /dev/null and b/src-tauri/png/jdread_512.png differ diff --git a/src-tauri/png/jike_256.ico b/src-tauri/png/jike_256.ico new file mode 100644 index 0000000..c49d202 Binary files /dev/null and b/src-tauri/png/jike_256.ico differ diff --git a/src-tauri/png/jike_32.ico b/src-tauri/png/jike_32.ico new file mode 100644 index 0000000..b5a68aa Binary files /dev/null and b/src-tauri/png/jike_32.ico differ diff --git a/src-tauri/png/jike_512.png b/src-tauri/png/jike_512.png new file mode 100644 index 0000000..dad7283 Binary files /dev/null and b/src-tauri/png/jike_512.png differ diff --git a/src-tauri/png/notion_256.ico b/src-tauri/png/notion_256.ico new file mode 100644 index 0000000..ce51f05 Binary files /dev/null and b/src-tauri/png/notion_256.ico differ diff --git a/src-tauri/png/notion_32.ico b/src-tauri/png/notion_32.ico new file mode 100644 index 0000000..632bcf4 Binary files /dev/null and b/src-tauri/png/notion_32.ico differ diff --git a/src-tauri/png/notion_512.png b/src-tauri/png/notion_512.png new file mode 100644 index 0000000..c5dcf0e Binary files /dev/null and b/src-tauri/png/notion_512.png differ diff --git a/src-tauri/png/reference_256.ico b/src-tauri/png/reference_256.ico new file mode 100644 index 0000000..2b8281f Binary files /dev/null and b/src-tauri/png/reference_256.ico differ diff --git a/src-tauri/png/reference_32.ico b/src-tauri/png/reference_32.ico new file mode 100644 index 0000000..95bc857 Binary files /dev/null and b/src-tauri/png/reference_32.ico differ diff --git a/src-tauri/png/reference_512.png b/src-tauri/png/reference_512.png new file mode 100644 index 0000000..a61916c Binary files /dev/null and b/src-tauri/png/reference_512.png differ diff --git a/src-tauri/png/roam_256.ico b/src-tauri/png/roam_256.ico new file mode 100644 index 0000000..ee829b8 Binary files /dev/null and b/src-tauri/png/roam_256.ico differ diff --git a/src-tauri/png/roam_32.ico b/src-tauri/png/roam_32.ico new file mode 100644 index 0000000..8dda778 Binary files /dev/null and b/src-tauri/png/roam_32.ico differ diff --git a/src-tauri/png/roam_512.png b/src-tauri/png/roam_512.png new file mode 100644 index 0000000..ab5a737 Binary files /dev/null and b/src-tauri/png/roam_512.png differ diff --git a/src-tauri/png/tool_256.ico b/src-tauri/png/tool_256.ico new file mode 100644 index 0000000..ed34bcc Binary files /dev/null and b/src-tauri/png/tool_256.ico differ diff --git a/src-tauri/png/tool_32.ico b/src-tauri/png/tool_32.ico new file mode 100644 index 0000000..a7bae8e Binary files /dev/null and b/src-tauri/png/tool_32.ico differ diff --git a/src-tauri/png/tool_512.png b/src-tauri/png/tool_512.png new file mode 100644 index 0000000..55b8a3d Binary files /dev/null and b/src-tauri/png/tool_512.png differ diff --git a/src-tauri/png/translate_256.ico b/src-tauri/png/translate_256.ico new file mode 100644 index 0000000..ebbd667 Binary files /dev/null and b/src-tauri/png/translate_256.ico differ diff --git a/src-tauri/png/translate_32.ico b/src-tauri/png/translate_32.ico new file mode 100644 index 0000000..c9fe263 Binary files /dev/null and b/src-tauri/png/translate_32.ico differ diff --git a/src-tauri/png/translate_512.png b/src-tauri/png/translate_512.png new file mode 100644 index 0000000..984b507 Binary files /dev/null and b/src-tauri/png/translate_512.png differ diff --git a/src-tauri/png/twitter_256.ico b/src-tauri/png/twitter_256.ico new file mode 100644 index 0000000..4ecac31 Binary files /dev/null and b/src-tauri/png/twitter_256.ico differ diff --git a/src-tauri/png/twitter_32.ico b/src-tauri/png/twitter_32.ico new file mode 100644 index 0000000..396798b Binary files /dev/null and b/src-tauri/png/twitter_32.ico differ diff --git a/src-tauri/png/twitter_512.png b/src-tauri/png/twitter_512.png new file mode 100644 index 0000000..679b61f Binary files /dev/null and b/src-tauri/png/twitter_512.png differ diff --git a/src-tauri/png/v2ex_256.ico b/src-tauri/png/v2ex_256.ico new file mode 100644 index 0000000..6c5b7ef Binary files /dev/null and b/src-tauri/png/v2ex_256.ico differ diff --git a/src-tauri/png/v2ex_32.ico b/src-tauri/png/v2ex_32.ico new file mode 100644 index 0000000..d852d2e Binary files /dev/null and b/src-tauri/png/v2ex_32.ico differ diff --git a/src-tauri/png/v2ex_512.png b/src-tauri/png/v2ex_512.png new file mode 100644 index 0000000..addfc7b Binary files /dev/null and b/src-tauri/png/v2ex_512.png differ diff --git a/src-tauri/png/vercel_256.ico b/src-tauri/png/vercel_256.ico new file mode 100644 index 0000000..be1824a Binary files /dev/null and b/src-tauri/png/vercel_256.ico differ diff --git a/src-tauri/png/vercel_32.ico b/src-tauri/png/vercel_32.ico new file mode 100644 index 0000000..59b4d77 Binary files /dev/null and b/src-tauri/png/vercel_32.ico differ diff --git a/src-tauri/png/vercel_512.png b/src-tauri/png/vercel_512.png new file mode 100644 index 0000000..e32e178 Binary files /dev/null and b/src-tauri/png/vercel_512.png differ diff --git a/src-tauri/png/weread_256.ico b/src-tauri/png/weread_256.ico new file mode 100644 index 0000000..8654aba Binary files /dev/null and b/src-tauri/png/weread_256.ico differ diff --git a/src-tauri/png/weread_32.ico b/src-tauri/png/weread_32.ico new file mode 100644 index 0000000..351c871 Binary files /dev/null and b/src-tauri/png/weread_32.ico differ diff --git a/src-tauri/png/weread_512.png b/src-tauri/png/weread_512.png new file mode 100644 index 0000000..aa8a737 Binary files /dev/null and b/src-tauri/png/weread_512.png differ diff --git a/src-tauri/png/whatsapp_256.ico b/src-tauri/png/whatsapp_256.ico new file mode 100644 index 0000000..8b4f0c9 Binary files /dev/null and b/src-tauri/png/whatsapp_256.ico differ diff --git a/src-tauri/png/whatsapp_32.ico b/src-tauri/png/whatsapp_32.ico new file mode 100644 index 0000000..7327bd7 Binary files /dev/null and b/src-tauri/png/whatsapp_32.ico differ diff --git a/src-tauri/png/whatsapp_512.png b/src-tauri/png/whatsapp_512.png new file mode 100644 index 0000000..698656a Binary files /dev/null and b/src-tauri/png/whatsapp_512.png differ diff --git a/src-tauri/png/witeboard_256.ico b/src-tauri/png/witeboard_256.ico new file mode 100644 index 0000000..5151980 Binary files /dev/null and b/src-tauri/png/witeboard_256.ico differ diff --git a/src-tauri/png/witeboard_32.ico b/src-tauri/png/witeboard_32.ico new file mode 100644 index 0000000..ab99a55 Binary files /dev/null and b/src-tauri/png/witeboard_32.ico differ diff --git a/src-tauri/png/witeboard_512.png b/src-tauri/png/witeboard_512.png new file mode 100644 index 0000000..a8d8609 Binary files /dev/null and b/src-tauri/png/witeboard_512.png differ diff --git a/src-tauri/png/youtube_256.ico b/src-tauri/png/youtube_256.ico new file mode 100644 index 0000000..d7b6ede Binary files /dev/null and b/src-tauri/png/youtube_256.ico differ diff --git a/src-tauri/png/youtube_32.ico b/src-tauri/png/youtube_32.ico new file mode 100644 index 0000000..33a6870 Binary files /dev/null and b/src-tauri/png/youtube_32.ico differ diff --git a/src-tauri/png/youtube_512.png b/src-tauri/png/youtube_512.png new file mode 100644 index 0000000..6e50a53 Binary files /dev/null and b/src-tauri/png/youtube_512.png differ diff --git a/src-tauri/png/yuque_256.ico b/src-tauri/png/yuque_256.ico new file mode 100644 index 0000000..e061639 Binary files /dev/null and b/src-tauri/png/yuque_256.ico differ diff --git a/src-tauri/png/yuque_32.ico b/src-tauri/png/yuque_32.ico new file mode 100644 index 0000000..803c542 Binary files /dev/null and b/src-tauri/png/yuque_32.ico differ diff --git a/src-tauri/png/yuque_512.png b/src-tauri/png/yuque_512.png new file mode 100644 index 0000000..4e80dcd Binary files /dev/null and b/src-tauri/png/yuque_512.png differ diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 4f54c31..8d25526 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,44 +1,107 @@ +// at the top of main.rs - that will prevent the console from showing +#![windows_subsystem = "windows"] +extern crate image; use tauri_utils::config::{Config, WindowConfig}; #[cfg(target_os = "macos")] use wry::application::platform::macos::WindowBuilderExtMacOS; -#[cfg(target_os = "windows")] -use wry::application::platform::windows::WindowBuilderExtWindows; + +#[cfg(target_os="macos")] +use wry::{ + application::{ + accelerator::{Accelerator, SysMods}, + event::{Event, StartCause, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + keyboard::KeyCode, + menu::{MenuBar as Menu, MenuItem, MenuItemAttributes, MenuType}, + window::{Fullscreen, Window, WindowBuilder}, + }, + webview::WebViewBuilder, +}; + + +#[cfg(target_os="windows")] +use wry::{ + application::{ + event::{Event, StartCause, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + menu::{MenuType}, + window::{Fullscreen, Window, WindowBuilder, Icon}, + }, + webview::WebViewBuilder, +}; + + +#[cfg(target_os="linux")] +use wry::{ + application::{ + event::{Event, StartCause, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + menu::{MenuType}, + window::{Fullscreen, Window, WindowBuilder}, + }, + webview::WebViewBuilder, +}; + fn main() -> wry::Result<()> { - use wry::{ - application::{ - accelerator::{Accelerator, SysMods}, - event::{Event, StartCause, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, - keyboard::KeyCode, - menu::{MenuBar as Menu, MenuItem, MenuItemAttributes, MenuType}, - window::{Fullscreen, Window, WindowBuilder}, - }, - webview::WebViewBuilder, - }; - + + #[cfg(target_os = "macos")] let mut menu_bar_menu = Menu::new(); + #[cfg(target_os = "macos")] let mut first_menu = Menu::new(); - + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::Hide); + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::EnterFullScreen); + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::Minimize); + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::Separator); + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::Copy); + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::Cut); + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::Paste); + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::Undo); + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::Redo); + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::SelectAll); + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::Separator); + + #[cfg(target_os = "macos")] let close_item = first_menu.add_item( MenuItemAttributes::new("CloseWindow") .with_accelerators(&Accelerator::new(SysMods::Cmd, KeyCode::KeyW)), ); + + #[cfg(target_os = "macos")] first_menu.add_native_item(MenuItem::Quit); + #[cfg(target_os = "macos")] menu_bar_menu.add_submenu("App", true, first_menu); - + #[cfg(target_os = "linux")] + let WindowConfig { + url, + width, + height, + resizable, + fullscreen, + .. + } = get_windows_config().unwrap_or(WindowConfig::default()); + #[cfg(target_os = "windows")] + let WindowConfig { + url, + width, + height, + resizable, + fullscreen, + .. + } = get_windows_config().unwrap_or(WindowConfig::default()); + #[cfg(target_os = "macos")] let WindowConfig { url, width, @@ -58,13 +121,26 @@ fn main() -> wry::Result<()> { None }) .with_inner_size(wry::application::dpi::LogicalSize::new(width, height)); + #[cfg(target_os = "windows")] + let icon_path = concat!(env!("CARGO_MANIFEST_DIR"), "/png/weread_32.ico"); + #[cfg(target_os = "windows")] + let icon = load_icon(std::path::Path::new(icon_path)); + #[cfg(target_os = "windows")] let window = common_window - .with_decorations(false) + .with_decorations(true) .with_title("") + .with_window_icon(Some(icon)) .build(&event_loop) .unwrap(); + + #[cfg(target_os = "linux")] + let window = common_window + .with_title("") + .build(&event_loop) + .unwrap(); + #[cfg(target_os = "macos")] let window = common_window .with_fullsize_content_view(true) @@ -89,7 +165,16 @@ fn main() -> wry::Result<()> { webbrowser::open(&href).expect("no browser"); } }; - + #[cfg(target_os = "windows")] + let webview = WebViewBuilder::new(window)? + .with_url(&url.to_string())? + .with_devtools(cfg!(feature = "devtools")) + .with_initialization_script(include_str!("pake.js")) + .with_ipc_handler(handler) + .build()?; + + + #[cfg(target_os = "linux")] let webview = WebViewBuilder::new(window)? .with_url(&url.to_string())? .with_devtools(cfg!(feature = "devtools")) @@ -97,6 +182,14 @@ fn main() -> wry::Result<()> { .with_ipc_handler(handler) .build()?; + #[cfg(target_os = "macos")] + let webview = WebViewBuilder::new(window)? + .with_url(&url.to_string())? + .with_devtools(cfg!(feature = "devtools")) + .with_initialization_script(include_str!("pake-mac.js")) + .with_ipc_handler(handler) + .build()?; + #[cfg(feature = "devtools")] { webview.open_devtools(); } @@ -115,10 +208,12 @@ fn main() -> wry::Result<()> { origin: MenuType::MenuBar, .. } => { + #[cfg(target_os = "macos")] if menu_id == close_item.clone().id() { webview.window().set_minimized(true); } println!("Clicked on {:?}", menu_id); + println!("Clicked on {:?}", webview.window().is_visible()); } _ => (), } @@ -131,3 +226,17 @@ fn get_windows_config() -> Option { config.tauri.windows.iter().next().cloned() } + +#[cfg(target_os = "windows")] +fn load_icon(path: &std::path::Path) -> Icon { + let (icon_rgba, icon_width, icon_height) = { + // alternatively, you can embed the icon in the binary through `include_bytes!` macro and use `image::load_from_memory` + let image = image::open(path) + .expect("Failed to open icon path") + .into_rgba8(); + let (width, height) = image.dimensions(); + let rgba = image.into_raw(); + (rgba, width, height) + }; + Icon::from_rgba(icon_rgba, icon_width, icon_height).expect("Failed to open icon") + } diff --git a/src-tauri/src/pake-mac.js b/src-tauri/src/pake-mac.js new file mode 100644 index 0000000..51cb51e --- /dev/null +++ b/src-tauri/src/pake-mac.js @@ -0,0 +1,175 @@ +/** + * @typedef {string} KeyboardKey `event.key` 的代号, + * 见 + * @typedef {() => void} OnKeyDown 使用者按下 ⌘ [KeyboardKey] 时应该执行的行为 + * 以 Meta 键 (⌘) 为首的快捷键清单。 + * 每个写在这里的 shortcuts 都会运行 {@link Event.preventDefault}. + * @type {Record} + */ + const metaKeyShortcuts = { + 'ArrowUp': () => scrollTo(0, 0), + 'ArrowDown': () => scrollTo(0, document.body.scrollHeight), + '[': () => window.history.back(), + ']': () => window.history.forward(), + 'r': () => window.location.reload(), + '-': () => zoomOut(), + '=': () => zoomIn(), + '0': () => zoomCommon(() => '100%'), +} + +window.addEventListener('DOMContentLoaded', (_event) => { + const style = document.createElement('style'); + style.innerHTML = ` + #page #footer-wrapper, + .drawing-board .toolbar .toolbar-action, + .c-swiper-container, + .download_entry, + .lang, .copyright, + .wwads-cn, .adsbygoogle, + #Bottom > div.content > div.inner, + #Rightbar .sep20:nth-of-type(5), + #Rightbar > div.box:nth-child(4), + #Main > div.box:nth-child(8) > div + #Wrapper > div.sep20, + #Main > div.box:nth-child(8), + #masthead-ad, + #Rightbar > div:nth-child(6) > div.sidebar_compliance { + display: none !important; + } + + #page .main_header { + padding-top: 20px; + } + + .panel.give_me .nav_view { + top: 154px !important; + } + + .columns .column #header{ + padding-top: 30px; + } + + ytd-masthead>#container.style-scope.ytd-masthead { + padding-top: 12px !important; + } + + .wrap.h1body-exist.max-container > div.menu-tocs > div.menu-btn{ + top: 28px; + } + + #Wrapper{ + background-color: #F8F8F8 !important; + background-image:none !important; + } + + #Top { + border-bottom: none; + } + + .container-with-note #home, .container-with-note #switcher{ + top: 30px; + } + + .geist-page nav.dashboard_nav__PRmJv { + padding-top:10px; + } + + .geist-page .submenu button{ + margin-top:24px; + } + + #pack-top-dom:active { + cursor: grabbing; + cursor: -webkit-grabbing; + } + + #pack-top-dom{ + position:fixed; + background:transparent; + top:0; + width: 100%; + height: 20px; + cursor: grab; + cursor: -webkit-grab; + z-index: 90000; + } + `; + document.head.append(style); + const topDom = document.createElement('div'); + topDom.id = 'pack-top-dom'; + document.body.appendChild(topDom); + + const domEl = document.getElementById('pack-top-dom'); + + domEl.addEventListener('mousedown', (e) => { + if (e.buttons === 1 && e.detail !== 2) { + window.ipc.postMessage('drag_window'); + } + }); + + domEl.addEventListener('touchstart', () => { + window.ipc.postMessage('drag_window'); + }); + + domEl.addEventListener('dblclick', () => { + window.ipc.postMessage('fullscreen'); + }); + + document.addEventListener('keyup', function (event) { + const preventDefault = (f) => { + event.preventDefault(); + f(); + }; + + if (event.metaKey && event.key in metaKeyShortcuts) { + preventDefault(metaKeyShortcuts[event.key]); + } + }); + + document.addEventListener('click', (e) => { + const origin = e.target.closest('a'); + if (origin && origin.href) { + origin.target = '_self'; + + //额外处理下 twitter 的外跳,对于其他需要外跳的可以改这里成对应域名 + const href = origin.href; + if(location.host === "twitter.com" && href.indexOf("twitter.com")===-1){ + e.preventDefault(); + window.ipc.postMessage(`open_browser:${href}`); + } + } + }); +}); + +setDefaultZoom(); + +function setDefaultZoom() { + const htmlZoom = window.localStorage.getItem('htmlZoom'); + if (htmlZoom) { + document.getElementsByTagName('html')[0].style.zoom = htmlZoom; + } +} + +/** + * @param {(htmlZoom: string) => string} [zoomRule] + */ +function zoomCommon(zoomRule) { + const htmlZoom = window.localStorage.getItem('htmlZoom') || '100%'; + const html = document.getElementsByTagName('html')[0]; + const zoom = zoomRule(htmlZoom); + html.style.zoom = zoom; + window.localStorage.setItem('htmlZoom', zoom); +} + +function zoomIn() { + zoomCommon((htmlZoom) => + `${Math.min(parseInt(htmlZoom) + 10, 200)}%` + ); +} + +function zoomOut() { + zoomCommon((htmlZoom) => + `${Math.max(parseInt(htmlZoom) - 10, 30)}%` + ); +} + diff --git a/src-tauri/src/pake.js b/src-tauri/src/pake.js index 5c0adcc..8f03af6 100644 --- a/src-tauri/src/pake.js +++ b/src-tauri/src/pake.js @@ -1,19 +1,20 @@ /** * @typedef {string} KeyboardKey `event.key` 的代号, * 见 - * @typedef {() => void} OnKeyDown 使用者按下 ⌘ [KeyboardKey] 时应该执行的行为 - * 以 Meta 键 (⌘) 为首的快捷键清单。 + * @typedef {() => void} OnKeyDown 使用者按下 [CtrlKey] 时应该执行的行为 + * 以 Ctrl 键 为首的快捷键清单。 * 每个写在这里的 shortcuts 都会运行 {@link Event.preventDefault}. * @type {Record} */ -const metaKeyShortcuts = { +const ctrlKeyShortcuts = { 'ArrowUp': () => scrollTo(0, 0), 'ArrowDown': () => scrollTo(0, document.body.scrollHeight), - '[': () => window.history.back(), - ']': () => window.history.forward(), + 'ArrowLeft': () => window.history.back(), + 'ArrowRight': () => window.history.forward(), 'r': () => window.location.reload(), '-': () => zoomOut(), '=': () => zoomIn(), + '+': () => zoomIn(), '0': () => zoomCommon(() => '100%'), } @@ -121,8 +122,8 @@ window.addEventListener('DOMContentLoaded', (_event) => { f(); }; - if (event.metaKey && event.key in metaKeyShortcuts) { - preventDefault(metaKeyShortcuts[event.key]); + if (event.ctrlKey && event.key in ctrlKeyShortcuts) { + preventDefault(ctrlKeyShortcuts[event.key]); } }); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 0cb34c9..733d5cf 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,6 +1,6 @@ { "package": { - "productName": "WeRead", + "productName": "weread", "version": "0.2.0" }, "tauri": { @@ -19,15 +19,29 @@ }, "bundle": { "icon": [ - "icons/weRead.icns", - "icons/icon.ico" + "icons/weread.icns", + "png/weread_256.ico", + "png/weread_32.ico", + "png/weread_512.png" ], - "identifier": "com.tw93.weRead", + "identifier": "com.tw93.weread", "active": true, "category": "DeveloperTool", "copyright": "", "deb": { - "depends": [] + "depends": [ + "libwebkit2gtk-4.0-dev", + "build-essential", + "curl", + "wget", + "libssl-dev", + "libgtk-3-dev", + "libayatana-appindicator3-dev", + "librsvg2-dev" + ], + "files": { + "/usr/share/applications/com-tw93-weread.desktop": "assets/com-tw93-weread.desktop" + } }, "externalBin": [], "longDescription": "", @@ -40,11 +54,14 @@ }, "resources": [], "shortDescription": "", - "targets": "all", + "targets": ["deb", "msi", "dmg"], "windows": { "certificateThumbprint": null, "digestAlgorithm": "sha256", - "timestampUrl": "" + "timestampUrl": "", + "wix": { + "language": ["en-US", "zh-CN"] + } } }, "security": {