From 51adb2aeeaaa30492bc7279be988978a2ecec5a3 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Wed, 28 Dec 2022 16:07:40 +0800 Subject: [PATCH 01/22] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=B0=86=E6=89=98?= =?UTF-8?q?=E7=9B=98=E5=9B=BE=E6=A0=87=E9=85=8D=E7=BD=AE=E6=94=BE=E5=88=B0?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E8=AE=BE=E7=BD=AE=E9=87=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/tauri.conf.json | 4 ++++ src-tauri/tauri.linux.conf.json | 4 ---- src-tauri/tauri.windows.conf.json | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 6395ef3..35ed045 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -9,6 +9,10 @@ }, "updater": { "active": false + }, + "systemTray": { + "iconPath": "png/weread_512.png", + "iconAsTemplate": true } }, "build": { diff --git a/src-tauri/tauri.linux.conf.json b/src-tauri/tauri.linux.conf.json index a78696c..c4c78b0 100644 --- a/src-tauri/tauri.linux.conf.json +++ b/src-tauri/tauri.linux.conf.json @@ -1,9 +1,5 @@ { "tauri": { - "systemTray": { - "iconPath": "png/weread_512.png", - "iconAsTemplate": true - }, "bundle": { "icon": [ "png/weread_256.ico", diff --git a/src-tauri/tauri.windows.conf.json b/src-tauri/tauri.windows.conf.json index 9b5a348..0c2eb5b 100644 --- a/src-tauri/tauri.windows.conf.json +++ b/src-tauri/tauri.windows.conf.json @@ -1,9 +1,5 @@ { "tauri": { - "systemTray": { - "iconPath": "png/weread_256.ico", - "iconAsTemplate": true - }, "bundle": { "icon": [ "png/weread_256.ico", From 2bc74e8e225c1469177d68c25c78a33368beba85 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Wed, 28 Dec 2022 16:12:46 +0800 Subject: [PATCH 02/22] =?UTF-8?q?=E6=9B=B4=E6=96=B0Windows=E7=AB=AF?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=89=93=E5=8C=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/build.bat | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/script/build.bat b/script/build.bat index 0624c12..7dccb34 100644 --- a/script/build.bat +++ b/script/build.bat @@ -53,6 +53,7 @@ for /f "skip=1 tokens=1-4 delims=," %%i in (app.csv) do ( .\script\sd.exe -s !old_url! !url! src-tauri\pake.json ::replace pacakge name .\script\sd.exe !old_title! !title! src-tauri\tauri.conf.json + .\script\sd.exe !old_name! !name! src-tauri\tauri.conf.json .\script\sd.exe !old_name! !name! src-tauri\tauri.windows.conf.json echo. @@ -92,6 +93,7 @@ for /f "skip=1 tokens=1-4 delims=," %%i in (app.csv) do ( echo "output dir is output\windows" ::recovery code -.\script\sd.exe %url% %init_url% src-tauri\tauri.conf.json +.\script\sd.exe %url% %init_url% src-tauri\pake.json .\script\sd.exe %title% %init_title% src-tauri\tauri.conf.json +.\script\sd.exe %name% %init_name% src-tauri\tauri.conf.json .\script\sd.exe %name% %init_name% src-tauri\tauri.windows.conf.json \ No newline at end of file From 506d3875f23dbbb84087c36fb3a8649b8c0a22e0 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Wed, 28 Dec 2022 17:07:55 +0800 Subject: [PATCH 03/22] =?UTF-8?q?=E5=B1=8F=E8=94=BD=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=8C=89=E9=92=AE,=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E6=89=98=E7=9B=98=E6=8C=89=E9=92=AE=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/Cargo.lock | 101 +++++----------------------- src-tauri/Cargo.toml | 10 +-- src-tauri/pake.json | 2 +- src-tauri/src/lib.rs | 152 +++++++++++++++++++++---------------------- 4 files changed, 98 insertions(+), 167 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index f8eafc2..e3ab7f6 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -42,17 +42,14 @@ checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" name = "app" version = "0.1.0" dependencies = [ - "cocoa 0.24.1 (git+https://github.com/servo/core-foundation-rs/)", "home", "image", - "objc", "serde", "serde_json", "tauri", "tauri-build", "tauri-plugin-window-state", "tauri-utils", - "webkit2gtk", ] [[package]] @@ -269,24 +266,9 @@ checksum = "f425db7937052c684daec3bd6375c8abe2d146dca4b8b143d6db777c39138f3a" dependencies = [ "bitflags", "block", - "cocoa-foundation 0.1.0", - "core-foundation 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types", - "libc", - "objc", -] - -[[package]] -name = "cocoa" -version = "0.24.1" -source = "git+https://github.com/servo/core-foundation-rs/#8c2444066aac42c20443b696270f5b1afff18993" -dependencies = [ - "bitflags", - "block", - "cocoa-foundation 0.1.1", - "core-foundation 0.9.3 (git+https://github.com/servo/core-foundation-rs/)", - "core-graphics 0.22.3 (git+https://github.com/servo/core-foundation-rs/)", + "cocoa-foundation", + "core-foundation", + "core-graphics", "foreign-types", "libc", "objc", @@ -300,22 +282,8 @@ checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" dependencies = [ "bitflags", "block", - "core-foundation 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics-types 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types", - "libc", - "objc", -] - -[[package]] -name = "cocoa-foundation" -version = "0.1.1" -source = "git+https://github.com/servo/core-foundation-rs/#8c2444066aac42c20443b696270f5b1afff18993" -dependencies = [ - "bitflags", - "block", - "core-foundation 0.9.3 (git+https://github.com/servo/core-foundation-rs/)", - "core-graphics-types 0.1.1 (git+https://github.com/servo/core-foundation-rs/)", + "core-foundation", + "core-graphics-types", "foreign-types", "libc", "objc", @@ -349,16 +317,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ - "core-foundation-sys 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc", -] - -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "git+https://github.com/servo/core-foundation-rs/#8c2444066aac42c20443b696270f5b1afff18993" -dependencies = [ - "core-foundation-sys 0.8.3 (git+https://github.com/servo/core-foundation-rs/)", + "core-foundation-sys", "libc", ] @@ -368,11 +327,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" -[[package]] -name = "core-foundation-sys" -version = "0.8.3" -source = "git+https://github.com/servo/core-foundation-rs/#8c2444066aac42c20443b696270f5b1afff18993" - [[package]] name = "core-graphics" version = "0.22.3" @@ -380,20 +334,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" dependencies = [ "bitflags", - "core-foundation 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics-types 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types", - "libc", -] - -[[package]] -name = "core-graphics" -version = "0.22.3" -source = "git+https://github.com/servo/core-foundation-rs/#8c2444066aac42c20443b696270f5b1afff18993" -dependencies = [ - "bitflags", - "core-foundation 0.9.3 (git+https://github.com/servo/core-foundation-rs/)", - "core-graphics-types 0.1.1 (git+https://github.com/servo/core-foundation-rs/)", + "core-foundation", + "core-graphics-types", "foreign-types", "libc", ] @@ -405,18 +347,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" dependencies = [ "bitflags", - "core-foundation 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types", - "libc", -] - -[[package]] -name = "core-graphics-types" -version = "0.1.1" -source = "git+https://github.com/servo/core-foundation-rs/#8c2444066aac42c20443b696270f5b1afff18993" -dependencies = [ - "bitflags", - "core-foundation 0.9.3 (git+https://github.com/servo/core-foundation-rs/)", + "core-foundation", "foreign-types", "libc", ] @@ -2589,9 +2520,9 @@ dependencies = [ "bitflags", "cairo-rs", "cc", - "cocoa 0.24.1 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cocoa", + "core-foundation", + "core-graphics", "crossbeam-channel", "dirs-next", "dispatch", @@ -2646,7 +2577,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b48820ee3bb6a5031a83b2b6e11f8630bdc5a2f68cb841ab8ebc7a15a916679" dependencies = [ "anyhow", - "cocoa 0.24.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cocoa", "dirs-next", "embed_plist", "encoding_rs", @@ -2776,7 +2707,7 @@ version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "36b1c5764a41a13176a4599b5b7bd0881bea7d94dfe45e1e755f789b98317e30" dependencies = [ - "cocoa 0.24.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cocoa", "gtk", "percent-encoding", "rand 0.8.5", @@ -3479,8 +3410,8 @@ checksum = "4c1ad8e2424f554cc5bdebe8aa374ef5b433feff817aebabca0389961fc7ef98" dependencies = [ "base64", "block", - "cocoa 0.24.1 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cocoa", + "core-graphics", "crossbeam-channel", "dunce", "gdk", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index e68a4d8..d1e59f5 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -25,12 +25,12 @@ tauri-plugin-window-state = { git = "https://github.com/tauri-apps/tauri-plugin- # webbrowser = "0.8.2" # wry = "0.23.4" -[target.'cfg(target_os = "linux")'.dependencies] -webkit2gtk = "0.18.0" +# [target.'cfg(target_os = "linux")'.dependencies] +# webkit2gtk = "0.18.0" -[target.'cfg(target_os = "macos")'.dependencies] -objc = "0.2.7" -cocoa = {git = "https://github.com/servo/core-foundation-rs/"} +# [target.'cfg(target_os = "macos")'.dependencies] +# objc = "0.2.7" +# cocoa = {git = "https://github.com/servo/core-foundation-rs/"} [features] # by default Tauri runs in production mode diff --git a/src-tauri/pake.json b/src-tauri/pake.json index 0a60807..b103128 100644 --- a/src-tauri/pake.json +++ b/src-tauri/pake.json @@ -17,7 +17,7 @@ }, "menu": { "macos": true, - "linux": false, + "linux": true, "windows": false }, "system_tray": { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 63ee18a..f629458 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,13 +1,13 @@ #[cfg(target_os = "macos")] use tauri::MenuItem; -#[cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +// #[cfg(target_os = "macos")] +// #[macro_use] +// extern crate objc; use tauri::{ - window::PlatformWebview, App, Config, CustomMenuItem, Manager, Menu, Submenu, SystemTray, - SystemTrayEvent, SystemTrayMenu, Window, WindowBuilder, WindowMenuEvent, WindowUrl, + App, Config, CustomMenuItem, Manager, Menu, Submenu, SystemTray, SystemTrayEvent, + SystemTrayMenu, Window, WindowBuilder, WindowMenuEvent, WindowUrl, }; mod pake; use pake::PakeConfig; @@ -47,19 +47,19 @@ pub fn get_menu() -> Menu { // let previous = CustomMenuItem::new("previous", "Previous (←)"); // let next = CustomMenuItem::new("next", "next (→)"); // let refresh = CustomMenuItem::new("refresh", "Refresh"); - let zoom_out = CustomMenuItem::new("zoom_out", "Zoom Out (125%)"); - let zoom_in = CustomMenuItem::new("zoom_in", "Zoom In (75%)"); - let zoom_reset = CustomMenuItem::new("reset", "Zoom Reset"); - let hot_key = Menu::new() - // .add_item(top) - // .add_item(buttom) - // .add_item(previous) - // .add_item(next) - // .add_item(refresh) - .add_item(zoom_in) - .add_item(zoom_out) - .add_item(zoom_reset); - let hot_key_menu = Submenu::new("Hot Key", hot_key); + // let zoom_out = CustomMenuItem::new("zoom_out", "Zoom Out (125%)"); + // let zoom_in = CustomMenuItem::new("zoom_in", "Zoom In (75%)"); + // let zoom_reset = CustomMenuItem::new("reset", "Zoom Reset"); + // let hot_key = Menu::new() + // .add_item(top) + // .add_item(buttom) + // .add_item(previous) + // .add_item(next) + // .add_item(refresh) + // .add_item(zoom_in) + // .add_item(zoom_out) + // .add_item(zoom_reset); + // let hot_key_menu = Submenu::new("Hot Key", hot_key); // Help // let instructions = CustomMenuItem::new("instruction", "Instruction"); @@ -68,47 +68,46 @@ pub fn get_menu() -> Menu { // .add_item(instructions) // .add_item(about); // let help_menu = Submenu::new("Help", help); - Menu::new() - .add_submenu(first_menu) - .add_submenu(hot_key_menu) + Menu::new().add_submenu(first_menu) + // .add_submenu(hot_key_menu) } -pub fn set_zoom(webview: PlatformWebview, zoom_value: f64) { - #[cfg(target_os = "linux")] - { - // see https://docs.rs/webkit2gtk/0.18.2/webkit2gtk/struct.WebView.html - // and https://docs.rs/webkit2gtk/0.18.2/webkit2gtk/trait.WebViewExt.html - use webkit2gtk::traits::WebViewExt; - webview.inner().set_zoom_level(zoom_value); - } +// pub fn set_zoom(webview: PlatformWebview, zoom_value: f64) { +// #[cfg(target_os = "linux")] +// { +// // see https://docs.rs/webkit2gtk/0.18.2/webkit2gtk/struct.WebView.html +// // and https://docs.rs/webkit2gtk/0.18.2/webkit2gtk/trait.WebViewExt.html +// use webkit2gtk::traits::WebViewExt; +// webview.inner().set_zoom_level(zoom_value); +// } - #[cfg(windows)] - unsafe { - // see https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html - webview.controller().SetZoomFactor(zoom_value).unwrap(); - } +// #[cfg(windows)] +// unsafe { +// // see https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html +// webview.controller().SetZoomFactor(zoom_value).unwrap(); +// } - #[cfg(target_os = "macos")] - unsafe { - let () = msg_send![webview.inner(), setPageZoom: zoom_value]; - let () = msg_send![webview.controller(), removeAllUserScripts]; - let bg_color: cocoa::base::id = - msg_send![class!(NSColor), colorWithDeviceRed:0.5 green:0.2 blue:0.4 alpha:1.]; - let () = msg_send![webview.ns_window(), setBackgroundColor: bg_color]; - } -} +// #[cfg(target_os = "macos")] +// unsafe { +// let () = msg_send![webview.inner(), setPageZoom: zoom_value]; +// let () = msg_send![webview.controller(), removeAllUserScripts]; +// let bg_color: cocoa::base::id = +// msg_send![class!(NSColor), colorWithDeviceRed:0.5 green:0.2 blue:0.4 alpha:1.]; +// let () = msg_send![webview.ns_window(), setBackgroundColor: bg_color]; +// } +// } -pub fn set_zoom_out(webview: PlatformWebview) { - set_zoom(webview, 1.25); -} +// pub fn set_zoom_out(webview: PlatformWebview) { +// set_zoom(webview, 1.25); +// } -pub fn set_zoom_in(webview: PlatformWebview) { - set_zoom(webview, 0.75); -} +// pub fn set_zoom_in(webview: PlatformWebview) { +// set_zoom(webview, 0.75); +// } -pub fn zoom_reset(webview: PlatformWebview) { - set_zoom(webview, 1.0); -} +// pub fn zoom_reset(webview: PlatformWebview) { +// set_zoom(webview, 1.0); +// } pub fn menu_event_handle(event: WindowMenuEvent) { match event.menu_item_id() { @@ -116,24 +115,24 @@ pub fn menu_event_handle(event: WindowMenuEvent) { "show" => event.window().show().expect("can't show window"), "close" => event.window().close().expect("can't close window"), "quit" => std::process::exit(0), - "zoom_out" => { - event - .window() - .with_webview(set_zoom_out) - .expect("can't set zoom out"); - } - "zoom_in" => { - event - .window() - .with_webview(set_zoom_in) - .expect("can't set zoom in"); - } - "reset" => { - event - .window() - .with_webview(zoom_reset) - .expect("can't reset zoom"); - } + // "zoom_out" => { + // event + // .window() + // .with_webview(set_zoom_out) + // .expect("can't set zoom out"); + // } + // "zoom_in" => { + // event + // .window() + // .with_webview(set_zoom_in) + // .expect("can't set zoom in"); + // } + // "reset" => { + // event + // .window() + // .with_webview(zoom_reset) + // .expect("can't reset zoom"); + // } _ => {} } } @@ -154,17 +153,18 @@ pub fn get_system_tray(show_menu: bool) -> SystemTray { let show_app = CustomMenuItem::new("show_app".to_string(), "Show App"); let quit = CustomMenuItem::new("quit".to_string(), "Quit"); let about = CustomMenuItem::new("about".to_string(), "About"); - let tray_menu = SystemTrayMenu::new() - .add_item(hide_app) - .add_item(show_app) - .add_item(quit) - .add_item(about); + let tray_menu = SystemTrayMenu::new().add_item(hide_app).add_item(show_app); if show_menu { let hide_menu = CustomMenuItem::new("hide_menu".to_string(), "Hide Menu"); let show_menu = CustomMenuItem::new("show_menu".to_string(), "Show Menu"); - let tray_menu = tray_menu.add_item(hide_menu).add_item(show_menu); + let tray_menu = tray_menu + .add_item(hide_menu) + .add_item(show_menu) + .add_item(quit) + .add_item(about); SystemTray::new().with_menu(tray_menu) } else { + let tray_menu = tray_menu.add_item(quit).add_item(about); SystemTray::new().with_menu(tray_menu) } } From f7eb9d8699b6cc72f4ad9bb9699b68195643ef09 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Wed, 28 Dec 2022 17:08:14 +0800 Subject: [PATCH 04/22] =?UTF-8?q?=E5=B1=8F=E8=94=BD=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=8C=89=E9=92=AE,=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E6=89=98=E7=9B=98=E6=8C=89=E9=92=AE=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/pake.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/pake.json b/src-tauri/pake.json index b103128..0a60807 100644 --- a/src-tauri/pake.json +++ b/src-tauri/pake.json @@ -17,7 +17,7 @@ }, "menu": { "macos": true, - "linux": true, + "linux": false, "windows": false }, "system_tray": { From cd2985a1913699749d24b11c0a58dfa9a7d20c79 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Wed, 28 Dec 2022 17:12:10 +0800 Subject: [PATCH 05/22] =?UTF-8?q?=E6=9B=B4=E6=96=B0about=20=E9=93=BE?= =?UTF-8?q?=E6=8E=A5,=E4=BD=BF=E5=BE=97=E5=8F=AF=E4=BB=A5=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E6=89=93=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/about_pake.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/about_pake.html b/dist/about_pake.html index e1655dd..d7bb838 100644 --- a/dist/about_pake.html +++ b/dist/about_pake.html @@ -8,9 +8,9 @@
Welcome from Pake!

version: 1.0.1

- Project link
- Discussions
- Issues
+ Project link
+ Discussions
+ Issues

LICENSE: MIT

\ No newline at end of file From 1504149635cbde0366bf6ba5b6cc3365bb2e71bc Mon Sep 17 00:00:00 2001 From: Tlntin Date: Wed, 28 Dec 2022 23:26:53 +0800 Subject: [PATCH 06/22] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=85=8D=E5=A5=97pake-?= =?UTF-8?q?cli=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/builders/common.ts | 128 +++++++++++++++++++++++- bin/builders/tauriConf.js | 4 +- bin/cli.ts | 9 +- bin/defaults.ts | 5 + bin/types.ts | 15 +++ dist/cli.js | 198 ++++++++++++++++++++++++++++++++------ 6 files changed, 323 insertions(+), 36 deletions(-) diff --git a/bin/builders/common.ts b/bin/builders/common.ts index 06b2d19..07e14ba 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -15,6 +15,7 @@ export async function promptText(message: string, initial?: string) { return response.content; } + export async function mergeTauriConfig( url: string, options: PakeAppOptions, @@ -26,6 +27,11 @@ export async function mergeTauriConfig( fullscreen, transparent, resizable, + userAgent, + showMenu, + showSystemTray, + systemTrayIcon, + // iter_copy_file, identifier, name, } = options; @@ -56,10 +62,84 @@ export async function mergeTauriConfig( } } + // logger.warn(JSON.stringify(tauriConf.pake.windows, null, 4)); + Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); + // 判断一下url类型,是文件还是网站 + // 如果是文件,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下(待做) + + // const src_exists = await fs.stat("src") + // .then(() => true) + // .catch(() => false); + // if (!src_exists) { + // fs.mkdir("src") + // } else { + // fs.rm + // } + const url_exists = await fs.stat(url) + .then(() => true) + .catch(() => false); + if (url_exists) { + tauriConf.pake.windows[0].url_type = "local"; + const file_name = path.basename(url); + // const dir_name = path.dirname(url); + const url_path = path.join("dist/", file_name); + await fs.copyFile(url, url_path); + tauriConf.pake.windows[0].url = file_name; + tauriConf.pake.windows[0].url_type = "local"; + } else { + tauriConf.pake.windows[0].url_type = "web"; + } + + // 处理user-agent + logger.warn(userAgent); + if (userAgent.length > 0) { + if (process.platform === "win32") { + tauriConf.pake.user_agent.windows = userAgent; + } + + if (process.platform === "linux") { + tauriConf.pake.user_agent.linux = userAgent; + } + + if (process.platform === "darwin") { + tauriConf.pake.user_agent.macos = userAgent; + } + } + + // 处理菜单栏 + if (showMenu) { + if (process.platform === "win32") { + tauriConf.pake.menu.windows = true; + } + + if (process.platform === "linux") { + tauriConf.pake.menu.linux = true; + } + + if (process.platform === "darwin") { + tauriConf.pake.user_agent.macos = true; + } + } + + // 处理托盘 + if (showSystemTray) { + if (process.platform === "win32") { + tauriConf.pake.system_tray.windows = true; + } + + if (process.platform === "linux") { + tauriConf.pake.system_tray.linux = true; + } + + if (process.platform === "darwin") { + tauriConf.pake.system_tray.macos = true; + } + } - Object.assign(tauriConf.tauri.windows[0], { url, ...tauriConfWindowOptions }); tauriConf.package.productName = name; tauriConf.tauri.bundle.identifier = identifier; + + // 处理应用图标 const exists = await fs.stat(options.icon) .then(() => true) .catch(() => false); @@ -97,7 +177,40 @@ export async function mergeTauriConfig( logger.warn("the custom icon path may not exists. we will use default icon to replace it"); } + // 处理托盘自定义图标 + let useDefaultIcon = true; // 是否使用默认托盘图标 + if (systemTrayIcon.length > 0) { + const icon_exists = await fs.stat(systemTrayIcon) + .then(() => true) + .catch(() => false); + if (icon_exists) { + // 需要判断图标格式,默认只支持ico和png两种 + let iconExt = path.extname(systemTrayIcon).toLowerCase(); + if (iconExt == ".png" || iconExt == ".icon") { + useDefaultIcon = false; + const trayIcoPath = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}${iconExt}`); + tauriConf.tauri.systemTray.iconPath = `png/${name.toLowerCase()}${iconExt}`; + await fs.copyFile(systemTrayIcon, trayIcoPath); + } else { + logger.warn(`file type for system tray icon mut be .ico or .png , but you give ${iconExt}`); + logger.warn(`system tray icon file will not change with default.`); + } + } else { + logger.warn(`${systemTrayIcon} not exists!`) + logger.warn(`system tray icon file will not change with default.`); + } + } + // 处理托盘默认图标 + if (useDefaultIcon) { + if (process.platform === "linux" || process.platform === "win32") { + tauriConf.tauri.systemTray.iconPath = tauriConf.tauri.bundle.icon[0]; + } else { + tauriConf.tauri.systemTray.iconPath = "png/icon_512.png"; + } + } + + // 保存配置文件 let configPath = ""; switch (process.platform) { case "win32": { @@ -117,13 +230,22 @@ export async function mergeTauriConfig( let bundleConf = {tauri: {bundle: tauriConf.tauri.bundle}}; await fs.writeFile( configPath, - Buffer.from(JSON.stringify(bundleConf), 'utf-8') + Buffer.from(JSON.stringify(bundleConf, null, 4), 'utf-8') ); + const pakeConfigPath = path.join(npmDirectory, 'src-tauri/pake.json') + await fs.writeFile( + pakeConfigPath, + Buffer.from(JSON.stringify(tauriConf.pake, null, 4), 'utf-8') + ); + + let tauriConf2 = JSON.parse(JSON.stringify(tauriConf)); + delete tauriConf2.pake; + delete tauriConf2.tauri.bundle; const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json') await fs.writeFile( configJsonPath, - Buffer.from(JSON.stringify(tauriConf), 'utf-8') + Buffer.from(JSON.stringify(tauriConf2, null, 4), 'utf-8') ); } diff --git a/bin/builders/tauriConf.js b/bin/builders/tauriConf.js index 2b5fd20..53122b8 100644 --- a/bin/builders/tauriConf.js +++ b/bin/builders/tauriConf.js @@ -1,11 +1,13 @@ import CommonConf from '../../src-tauri/tauri.conf.json'; +import pakeConf from '../../src-tauri/pake.json'; import WinConf from '../../src-tauri/tauri.windows.conf.json'; import MacConf from '../../src-tauri/tauri.macos.conf.json'; import LinuxConf from '../../src-tauri/tauri.linux.conf.json'; let tauriConf = { package: CommonConf.package, - tauri: CommonConf.tauri + tauri: CommonConf.tauri, + pake: pakeConf } switch (process.platform) { case "win32": { diff --git a/bin/cli.ts b/bin/cli.ts index 14a6d0e..174564a 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -23,6 +23,13 @@ program .option('--no-resizable', 'whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable) .option('--fullscreen', 'makes the packaged app start in full screen', DEFAULT_PAKE_OPTIONS.fullscreen) .option('--transparent', 'transparent title bar', DEFAULT_PAKE_OPTIONS.transparent) + .option('--user-agent ', 'custom user agent', DEFAULT_PAKE_OPTIONS.userAgent) + .option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu) + .option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray) + .option('--system-tray-icon ', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon) + // .option('--iter-copy-file', + // 'copy all static file to pake app when url is a static file', + // DEFAULT_PAKE_OPTIONS.iter_copy_file) .option('--debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent) .action(async (url: string, options: PakeCliOptions) => { checkUpdateTips(); @@ -41,7 +48,7 @@ program await builder.prepare(); const appOptions = await handleInputOptions(options, url); - + // logger.warn(JSON.stringify(appOptions, null, 4)); builder.build(url, appOptions); }); diff --git a/bin/defaults.ts b/bin/defaults.ts index fb5cbff..c28cdb5 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -7,6 +7,11 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { fullscreen: false, resizable: true, transparent: false, + userAgent: '', + showMenu: false, + showSystemTray: false, + // iter_copy_file: false, + systemTrayIcon: '', debug: false, }; diff --git a/bin/types.ts b/bin/types.ts index 9610edb..d0ec34e 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -20,6 +20,21 @@ export interface PakeCliOptions { /** 是否开启沉浸式头部,默认为 false 不开启 ƒ*/ transparent: boolean; + /** 自定义UA,默认为不开启 ƒ*/ + userAgent: string; + + /** 开启菜单栏,MacOS默认开启,Windows,Linux默认不开启 ƒ*/ + showMenu: boolean; + + /** 开启系统托盘,MacOS默认不开启,Windows,Linux默认开启 ƒ*/ + showSystemTray: boolean; + + /** 托盘图标, Windows、Linux默认和应用图标共用一样的,MacOS需要提别提供, 格式为png或者ico */ + systemTrayIcon: string; + + // /** 递归拷贝,当url为本地文件路径时候,将文件所在文件夹下面的所有子文件都拷贝到pake静态文件夹,默认不开启 */ + // iter_copy_file: false; + /** 调试模式,会输出更多日志 */ debug: boolean; } diff --git a/dist/cli.js b/dist/cli.js index 468a13b..1a5f29f 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -47,6 +47,11 @@ const DEFAULT_PAKE_OPTIONS = { fullscreen: false, resizable: true, transparent: false, + userAgent: '', + showMenu: false, + showSystemTray: false, + // iter_copy_file: false, + systemTrayIcon: '', debug: false, }; @@ -1624,7 +1629,9 @@ function promptText(message, initial) { } function mergeTauriConfig(url, options, tauriConf) { return __awaiter(this, void 0, void 0, function* () { - const { width, height, fullscreen, transparent, resizable, identifier, name, } = options; + const { width, height, fullscreen, transparent, resizable, userAgent, showMenu, showSystemTray, systemTrayIcon, + // iter_copy_file, + identifier, name, } = options; const tauriConfWindowOptions = { width, height, @@ -1650,9 +1657,73 @@ function mergeTauriConfig(url, options, tauriConf) { process.exit(); } } - Object.assign(tauriConf.tauri.windows[0], Object.assign({ url }, tauriConfWindowOptions)); + // logger.warn(JSON.stringify(tauriConf.pake.windows, null, 4)); + Object.assign(tauriConf.pake.windows[0], Object.assign({ url }, tauriConfWindowOptions)); + // 判断一下url类型,是文件还是网站 + // 如果是文件,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下(待做) + // const src_exists = await fs.stat("src") + // .then(() => true) + // .catch(() => false); + // if (!src_exists) { + // fs.mkdir("src") + // } else { + // fs.rm + // } + const url_exists = yield fs.stat(url) + .then(() => true) + .catch(() => false); + if (url_exists) { + tauriConf.pake.windows[0].url_type = "local"; + const file_name = path.basename(url); + // const dir_name = path.dirname(url); + const url_path = path.join("dist/", file_name); + yield fs.copyFile(url, url_path); + tauriConf.pake.windows[0].url = file_name; + tauriConf.pake.windows[0].url_type = "local"; + } + else { + tauriConf.pake.windows[0].url_type = "web"; + } + // 处理user-agent + logger.warn(userAgent); + if (userAgent.length > 0) { + if (process.platform === "win32") { + tauriConf.pake.user_agent.windows = userAgent; + } + if (process.platform === "linux") { + tauriConf.pake.user_agent.linux = userAgent; + } + if (process.platform === "darwin") { + tauriConf.pake.user_agent.macos = userAgent; + } + } + // 处理菜单栏 + if (showMenu) { + if (process.platform === "win32") { + tauriConf.pake.menu.windows = true; + } + if (process.platform === "linux") { + tauriConf.pake.menu.linux = true; + } + if (process.platform === "darwin") { + tauriConf.pake.user_agent.macos = true; + } + } + // 处理托盘 + if (showSystemTray) { + if (process.platform === "win32") { + tauriConf.pake.system_tray.windows = true; + } + if (process.platform === "linux") { + tauriConf.pake.system_tray.linux = true; + } + if (process.platform === "darwin") { + tauriConf.pake.system_tray.macos = true; + } + } tauriConf.package.productName = name; tauriConf.tauri.bundle.identifier = identifier; + // 处理应用图标 const exists = yield fs.stat(options.icon) .then(() => true) .catch(() => false); @@ -1691,6 +1762,41 @@ function mergeTauriConfig(url, options, tauriConf) { else { logger.warn("the custom icon path may not exists. we will use default icon to replace it"); } + // 处理托盘自定义图标 + let useDefaultIcon = true; // 是否使用默认托盘图标 + if (systemTrayIcon.length > 0) { + const icon_exists = yield fs.stat(systemTrayIcon) + .then(() => true) + .catch(() => false); + if (icon_exists) { + // 需要判断图标格式,默认只支持ico和png两种 + let iconExt = path.extname(systemTrayIcon).toLowerCase(); + if (iconExt == ".png" || iconExt == ".icon") { + useDefaultIcon = false; + const trayIcoPath = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}${iconExt}`); + tauriConf.tauri.systemTray.iconPath = `png/${name.toLowerCase()}${iconExt}`; + yield fs.copyFile(systemTrayIcon, trayIcoPath); + } + else { + logger.warn(`file type for system tray icon mut be .ico or .png , but you give ${iconExt}`); + logger.warn(`system tray icon file will not change with default.`); + } + } + else { + logger.warn(`${systemTrayIcon} not exists!`); + logger.warn(`system tray icon file will not change with default.`); + } + } + // 处理托盘默认图标 + if (useDefaultIcon) { + if (process.platform === "linux" || process.platform === "win32") { + tauriConf.tauri.systemTray.iconPath = tauriConf.tauri.bundle.icon[0]; + } + else { + tauriConf.tauri.systemTray.iconPath = "png/icon_512.png"; + } + } + // 保存配置文件 let configPath = ""; switch (process.platform) { case "win32": { @@ -1707,9 +1813,14 @@ function mergeTauriConfig(url, options, tauriConf) { } } let bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } }; - yield fs.writeFile(configPath, Buffer.from(JSON.stringify(bundleConf), 'utf-8')); + yield fs.writeFile(configPath, Buffer.from(JSON.stringify(bundleConf, null, 4), 'utf-8')); + const pakeConfigPath = path.join(npmDirectory, 'src-tauri/pake.json'); + yield fs.writeFile(pakeConfigPath, Buffer.from(JSON.stringify(tauriConf.pake, null, 4), 'utf-8')); + let tauriConf2 = JSON.parse(JSON.stringify(tauriConf)); + delete tauriConf2.pake; + delete tauriConf2.tauri.bundle; const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json'); - yield fs.writeFile(configJsonPath, Buffer.from(JSON.stringify(tauriConf), 'utf-8')); + yield fs.writeFile(configJsonPath, Buffer.from(JSON.stringify(tauriConf2, null, 4), 'utf-8')); }); } @@ -1859,36 +1970,56 @@ function checkRustInstalled() { } var tauri$3 = { - windows: [ - { - url: "https://weread.qq.com/", - transparent: true, - fullscreen: false, - width: 1200, - height: 780, - resizable: true - } - ], security: { csp: null }, updater: { active: false + }, + systemTray: { + iconPath: "/home/tlntin/data/code/rust_study/Pake/src-tauri/png/code_512.png", + iconAsTemplate: true } }; -var build = { - devPath: "../dist", - distDir: "../dist", - beforeBuildCommand: "", - beforeDevCommand: "" -}; var CommonConf = { "package": { - productName: "WeRead", + productName: "baidu", version: "1.0.0" }, - tauri: tauri$3, - build: build + tauri: tauri$3 +}; + +var windows = [ + { + url: "https://www.baidu.com", + transparent: false, + fullscreen: false, + width: 1200, + height: 780, + resizable: true, + url_type: "web" + } +]; +var user_agent = { + macos: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15", + linux: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", + windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" +}; +var menu = { + macos: true, + linux: true, + windows: false +}; +var system_tray = { + macos: false, + linux: true, + windows: true +}; +var pakeConf = { + windows: windows, + user_agent: user_agent, + menu: menu, + system_tray: system_tray }; var tauri$2 = { @@ -1963,10 +2094,9 @@ var MacConf = { var tauri = { bundle: { icon: [ - "png/weread_256.ico", - "png/weread_512.png" + "/home/tlntin/data/code/rust_study/Pake/src-tauri/png/code_512.png" ], - identifier: "com.tw93.weread", + identifier: "pake-f9751d", active: true, category: "DeveloperTool", copyright: "", @@ -1982,10 +2112,7 @@ var tauri = { "librsvg2-dev", "gnome-video-effects", "gnome-video-effects-extra" - ], - files: { - "/usr/share/applications/com-tw93-weread.desktop": "assets/com-tw93-weread.desktop" - } + ] }, externalBin: [ ], @@ -2005,7 +2132,8 @@ var LinuxConf = { let tauriConf = { package: CommonConf.package, - tauri: CommonConf.tauri + tauri: CommonConf.tauri, + pake: pakeConf }; switch (process.platform) { case "win32": { @@ -2301,6 +2429,13 @@ program .option('--no-resizable', 'whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable) .option('--fullscreen', 'makes the packaged app start in full screen', DEFAULT_PAKE_OPTIONS.fullscreen) .option('--transparent', 'transparent title bar', DEFAULT_PAKE_OPTIONS.transparent) + .option('--user-agent ', 'custom user agent', DEFAULT_PAKE_OPTIONS.userAgent) + .option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu) + .option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray) + .option('--system-tray-icon ', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon) + // .option('--iter-copy-file', + // 'copy all static file to pake app when url is a static file', + // DEFAULT_PAKE_OPTIONS.iter_copy_file) .option('--debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent) .action((url, options) => __awaiter(void 0, void 0, void 0, function* () { checkUpdateTips(); @@ -2315,6 +2450,7 @@ program const builder = BuilderFactory.create(); yield builder.prepare(); const appOptions = yield handleOptions(options, url); + // logger.warn(JSON.stringify(appOptions, null, 4)); builder.build(url, appOptions); })); program.parse(); From 88f3a9ada6193531d385e212c82bfb4116837ef1 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Wed, 28 Dec 2022 23:53:18 +0800 Subject: [PATCH 07/22] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E5=A5=97pake-?= =?UTF-8?q?cli=E5=91=BD=E4=BB=A41=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/README.md | 32 ++++++++++++++++++++++++++ bin/README_EN.md | 32 ++++++++++++++++++++++++++ bin/builders/common.ts | 24 ++++++++++++++++++++ dist/cli.js | 51 ++++++++++++++++++++++++++++++++++-------- 4 files changed, 130 insertions(+), 9 deletions(-) diff --git a/bin/README.md b/bin/README.md index b6b8bc4..bf10e65 100644 --- a/bin/README.md +++ b/bin/README.md @@ -88,3 +88,35 @@ url 为你需要打包的网页链接 🔗,必须提供。 ```shell --fullscreen ``` + +#### [user-agent] + +自定义浏览器请求头, 默认为空。 + +```shell +--user-agent +``` + +#### [show-menu] + +显示菜单栏, 默认不显示 + +```shell +--show-menu +``` + +#### [show-system-tray] + +显示通知栏托盘, 默认不显示 + +```shell +--show-system-tray +``` + +#### [system-tray-icon] + +通知栏托盘图标,仅当显示通知栏托盘时有效, 图标必须为.ico或者.png格式的,512*512像素的图片。 + +```shell +--system-tray-icon +``` \ No newline at end of file diff --git a/bin/README_EN.md b/bin/README_EN.md index 683e9d7..e205b6c 100644 --- a/bin/README_EN.md +++ b/bin/README_EN.md @@ -87,3 +87,35 @@ Whether to open the full screen after opening the application. The default is `f ```shell --fullscreen ``` + +#### [user-agent] + +Custom browser user agent, default is empty. + +```shell +--user-agent +``` + +#### [show-menu] + +Display the menu bar, not display it by default. + +```shell +--show-menu +``` + +#### [show-system-tray] + +Display the notification tray, not display it by default. + +```shell +--show-system-tray +``` + +#### [system-tray-icon] + +The notification tray icon is only valid when the notification tray is displayed. The icon must be a 512*512 pixel image in .ico or .png format. + +```shell +--system-tray-icon +``` diff --git a/bin/builders/common.ts b/bin/builders/common.ts index 07e14ba..212e330 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -119,6 +119,18 @@ export async function mergeTauriConfig( if (process.platform === "darwin") { tauriConf.pake.user_agent.macos = true; } + } else { + if (process.platform === "win32") { + tauriConf.pake.menu.windows = false; + } + + if (process.platform === "linux") { + tauriConf.pake.menu.linux = false; + } + + if (process.platform === "darwin") { + tauriConf.pake.user_agent.macos = false; + } } // 处理托盘 @@ -134,6 +146,18 @@ export async function mergeTauriConfig( if (process.platform === "darwin") { tauriConf.pake.system_tray.macos = true; } + } else { + if (process.platform === "win32") { + tauriConf.pake.system_tray.windows = false; + } + + if (process.platform === "linux") { + tauriConf.pake.system_tray.linux = false; + } + + if (process.platform === "darwin") { + tauriConf.pake.system_tray.macos = false; + } } tauriConf.package.productName = name; diff --git a/dist/cli.js b/dist/cli.js index 1a5f29f..4f5aafa 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1709,6 +1709,17 @@ function mergeTauriConfig(url, options, tauriConf) { tauriConf.pake.user_agent.macos = true; } } + else { + if (process.platform === "win32") { + tauriConf.pake.menu.windows = false; + } + if (process.platform === "linux") { + tauriConf.pake.menu.linux = false; + } + if (process.platform === "darwin") { + tauriConf.pake.user_agent.macos = false; + } + } // 处理托盘 if (showSystemTray) { if (process.platform === "win32") { @@ -1721,6 +1732,17 @@ function mergeTauriConfig(url, options, tauriConf) { tauriConf.pake.system_tray.macos = true; } } + else { + if (process.platform === "win32") { + tauriConf.pake.system_tray.windows = false; + } + if (process.platform === "linux") { + tauriConf.pake.system_tray.linux = false; + } + if (process.platform === "darwin") { + tauriConf.pake.system_tray.macos = false; + } + } tauriConf.package.productName = name; tauriConf.tauri.bundle.identifier = identifier; // 处理应用图标 @@ -1977,22 +1999,29 @@ var tauri$3 = { active: false }, systemTray: { - iconPath: "/home/tlntin/data/code/rust_study/Pake/src-tauri/png/code_512.png", + iconPath: "png/weread_512.png", iconAsTemplate: true } }; +var build = { + devPath: "../dist", + distDir: "../dist", + beforeBuildCommand: "", + beforeDevCommand: "" +}; var CommonConf = { "package": { - productName: "baidu", + productName: "WeRead", version: "1.0.0" }, - tauri: tauri$3 + tauri: tauri$3, + build: build }; var windows = [ { - url: "https://www.baidu.com", - transparent: false, + url: "https://weread.qq.com/", + transparent: true, fullscreen: false, width: 1200, height: 780, @@ -2007,7 +2036,7 @@ var user_agent = { }; var menu = { macos: true, - linux: true, + linux: false, windows: false }; var system_tray = { @@ -2094,9 +2123,10 @@ var MacConf = { var tauri = { bundle: { icon: [ - "/home/tlntin/data/code/rust_study/Pake/src-tauri/png/code_512.png" + "png/weread_256.ico", + "png/weread_512.png" ], - identifier: "pake-f9751d", + identifier: "com.tw93.weread", active: true, category: "DeveloperTool", copyright: "", @@ -2112,7 +2142,10 @@ var tauri = { "librsvg2-dev", "gnome-video-effects", "gnome-video-effects-extra" - ] + ], + files: { + "/usr/share/applications/com-tw93-weread.desktop": "assets/com-tw93-weread.desktop" + } }, externalBin: [ ], From f6223869cf4b666c8ff02ec377b841de97a88359 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 00:06:59 +0800 Subject: [PATCH 08/22] =?UTF-8?q?=E6=9B=B4=E6=96=B0pake-cli=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/README.md | 14 +++++++------- bin/README_EN.md | 10 +++++----- bin/cli.ts | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bin/README.md b/bin/README.md index bf10e65..e147791 100644 --- a/bin/README.md +++ b/bin/README.md @@ -67,7 +67,7 @@ url 为你需要打包的网页链接 🔗,必须提供。 #### [transparent] -是否开启沉浸式头部,默认为 `false` 不开启。 +是否开启沉浸式头部,默认为 `false` 不开启,输入下面的命令则开启沉浸式,推荐MacOS用户开启。 ```shell --transparent @@ -75,7 +75,7 @@ url 为你需要打包的网页链接 🔗,必须提供。 #### [resize] -是否可以拖动大小,默认为 `true` 可拖动。 +是否可以拖动大小,默认为 `true` 可拖动,输入下面的命令则不能对窗口大小进行拉伸。 ```shell --no-resizable @@ -83,10 +83,10 @@ url 为你需要打包的网页链接 🔗,必须提供。 #### [fullscreen] -打开应用后是否开启全屏,默认为 `false`。 +打开应用后是否开启全屏,默认为 `false`,输入下面的命令则会自动全屏。 ```shell ---fullscreen +--fullscreen ``` #### [user-agent] @@ -99,7 +99,7 @@ url 为你需要打包的网页链接 🔗,必须提供。 #### [show-menu] -显示菜单栏, 默认不显示 +显示菜单栏, 默认不显示,输入下面的命令则会显示,推荐MacOS用户开启。 ```shell --show-menu @@ -107,10 +107,10 @@ url 为你需要打包的网页链接 🔗,必须提供。 #### [show-system-tray] -显示通知栏托盘, 默认不显示 +显示通知栏托盘, 默认不显示,输入下面的命令则会显示。 ```shell ---show-system-tray +--show-system-tray ``` #### [system-tray-icon] diff --git a/bin/README_EN.md b/bin/README_EN.md index e205b6c..754f135 100644 --- a/bin/README_EN.md +++ b/bin/README_EN.md @@ -66,7 +66,7 @@ The width of the packaged application window. The default is `1200px`. #### [transparent] -Whether to enable the immersive header. The default is `false`. +Whether to enable the immersive header. The default is `false`, enter the following command to enable immersive, recommended for MacOS users to enable ```shell --transparent @@ -74,7 +74,7 @@ Whether to enable the immersive header. The default is `false`. #### [resize] -Whether the size can be dragged. The default value is `true`. +Whether the size can be dragged. The default value is `true`, the window size cannot be stretched by entering the following command. ```shell --no-resizable @@ -82,7 +82,7 @@ Whether the size can be dragged. The default value is `true`. #### [fullscreen] -Whether to open the full screen after opening the application. The default is `false`. +Whether to open the full screen after opening the application. The default is `false`, enter the following command to automatically full screen ```shell --fullscreen @@ -98,7 +98,7 @@ Custom browser user agent, default is empty. #### [show-menu] -Display the menu bar, not display it by default. +Display the menu bar, not display it by default, enter the following command and it will be displayed. MacOS users are recommended to enable. ```shell --show-menu @@ -106,7 +106,7 @@ Display the menu bar, not display it by default. #### [show-system-tray] -Display the notification tray, not display it by default. +Display the notification tray, not display it by default, entering the following command will display. ```shell --show-system-tray diff --git a/bin/cli.ts b/bin/cli.ts index 174564a..9c7eacf 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -48,7 +48,7 @@ program await builder.prepare(); const appOptions = await handleInputOptions(options, url); - // logger.warn(JSON.stringify(appOptions, null, 4)); + logger.warn(JSON.stringify(appOptions, null, 4)); builder.build(url, appOptions); }); From 6d69b1144c8efb3662a308bdc603b3a7c48a64e9 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 00:10:19 +0800 Subject: [PATCH 09/22] =?UTF-8?q?=E6=9B=B4=E6=96=B0pake-cli=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/README.md | 2 +- bin/README_EN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/README.md b/bin/README.md index e147791..39c70be 100644 --- a/bin/README.md +++ b/bin/README.md @@ -23,7 +23,7 @@ Note: 打包需要用 `Rust` 环境,如果没有 `Rust`,会提示确认安 ### url -url 为你需要打包的网页链接 🔗,必须提供。 +url 为你需要打包的网页链接 🔗或者本地html文件,必须提供。 ### [options] diff --git a/bin/README_EN.md b/bin/README_EN.md index 754f135..331065a 100644 --- a/bin/README_EN.md +++ b/bin/README_EN.md @@ -22,7 +22,7 @@ Note: The Rust environment is required for packaging. If you do not have Rust, y ### url -The url🔗 is the webpage link you need to package, Must be provided. +The url🔗 is the webpage link or local html file you need to package, Must be provided. ### [options] From c7717ffda5aba2d31f7062f0e618233ff6c3ae9c Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 11:05:25 +0800 Subject: [PATCH 10/22] =?UTF-8?q?=E6=9B=B4=E6=96=B0pake-cli,=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0Linux=E7=AB=AFtargets=E9=80=89=E9=A1=B9,=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=89=93=E5=8C=85=E6=9C=AC=E5=9C=B0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/builders/LinuxBuilder.ts | 29 +- bin/builders/common.ts | 19 +- bin/cli.ts | 7 +- bin/defaults.ts | 1 + bin/types.ts | 2 + bin/utils/validate.ts | 10 +- dist/cli.js | 49 ++- dist/index.html | 559 +++++++++++++++++++++++++++++++++++ 8 files changed, 647 insertions(+), 29 deletions(-) create mode 100644 dist/index.html diff --git a/bin/builders/LinuxBuilder.ts b/bin/builders/LinuxBuilder.ts index cec50b1..de8920a 100644 --- a/bin/builders/LinuxBuilder.ts +++ b/bin/builders/LinuxBuilder.ts @@ -54,20 +54,33 @@ export default class LinuxBuilder implements IBuilder { arch = process.arch; } const debName = `${name}_${tauriConf.package.version}_${arch}.deb`; - const appPath = this.getBuildedAppPath(npmDirectory, "deb", debName); + const debPath = this.getBuildedAppPath(npmDirectory, "deb", debName); const distPath = path.resolve(`${name}.deb`); - await fs.copyFile(appPath, distPath); - await fs.unlink(appPath); + // 增加文件是否存在验证,再决定是否copy文件 + const debExists = await fs.stat(debPath) + .then(() => true) + .catch(() => false); + if (debExists) { + await fs.copyFile(debPath, distPath); + await fs.unlink(debPath); + logger.success('Build success!'); + logger.success('You can find the deb app installer in', distPath); + } const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`; const appImagePath = this.getBuildedAppPath(npmDirectory, "appimage", appImageName); const distAppPath = path.resolve(`${name}.AppImage`); - await fs.copyFile(appImagePath, distAppPath); - await fs.unlink(appImagePath); - logger.success('Build success!'); - logger.success('You can find the deb app installer in', distPath); - logger.success('You can find the Appimage app installer in', distAppPath); + + const appExists = await fs.stat(appImagePath) + .then(() => true) + .catch(() => false); + if (appExists) { + await fs.copyFile(appImagePath, distAppPath); + await fs.unlink(appImagePath); + logger.success('Build success!'); + logger.success('You can find the Appimage app installer in', distAppPath); + } } getBuildedAppPath(npmDirectory: string,packageType: string, packageName: string) { diff --git a/bin/builders/common.ts b/bin/builders/common.ts index 212e330..aba7cbf 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -75,15 +75,17 @@ export async function mergeTauriConfig( // } else { // fs.rm // } - const url_exists = await fs.stat(url) + let file_path = url.slice(8, url.length); + const url_exists = await fs.stat(file_path) .then(() => true) .catch(() => false); if (url_exists) { + logger.warn("you input may a local file"); tauriConf.pake.windows[0].url_type = "local"; - const file_name = path.basename(url); + const file_name = path.basename(file_path); // const dir_name = path.dirname(url); const url_path = path.join("dist/", file_name); - await fs.copyFile(url, url_path); + await fs.copyFile(file_path, url_path); tauriConf.pake.windows[0].url = file_name; tauriConf.pake.windows[0].url_type = "local"; } else { @@ -160,6 +162,17 @@ export async function mergeTauriConfig( } } + // 处理targets 暂时只对linux开放 + if (process.platform === "linux") { + if (options.targets.length > 0) { + if (options.targets === "deb" || options.targets === "appimage" || options.targets === "all") { + tauriConf.tauri.bundle.targets = [options.targets]; + } + } + } else { + tauriConf.tauri.bundle.targets = ["deb"]; + } + tauriConf.package.productName = name; tauriConf.tauri.bundle.identifier = identifier; diff --git a/bin/cli.ts b/bin/cli.ts index 9c7eacf..312dc44 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -9,7 +9,6 @@ import BuilderFactory from './builders/BuilderFactory.js'; import { checkUpdateTips } from './helpers/updater.js'; // @ts-expect-error import packageJson from '../package.json'; -import logger from './options/logger.js'; program.version(packageJson.version).description('A cli application can package a web page to desktop application.'); @@ -27,6 +26,10 @@ program .option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu) .option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray) .option('--system-tray-icon ', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon) + .option( + '--targets ', + 'only for linux, default is "deb", option "appaimge" or "all"(deb & appimage)', + DEFAULT_PAKE_OPTIONS.targets) // .option('--iter-copy-file', // 'copy all static file to pake app when url is a static file', // DEFAULT_PAKE_OPTIONS.iter_copy_file) @@ -48,7 +51,7 @@ program await builder.prepare(); const appOptions = await handleInputOptions(options, url); - logger.warn(JSON.stringify(appOptions, null, 4)); + // logger.warn(JSON.stringify(appOptions, null, 4)); builder.build(url, appOptions); }); diff --git a/bin/defaults.ts b/bin/defaults.ts index c28cdb5..3804864 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -10,6 +10,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { userAgent: '', showMenu: false, showSystemTray: false, + targets: '', // iter_copy_file: false, systemTrayIcon: '', debug: false, diff --git a/bin/types.ts b/bin/types.ts index d0ec34e..6725079 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -34,6 +34,8 @@ export interface PakeCliOptions { // /** 递归拷贝,当url为本地文件路径时候,将文件所在文件夹下面的所有子文件都拷贝到pake静态文件夹,默认不开启 */ // iter_copy_file: false; + // 包输出产物,对linux用户有效,默认为deb,可选appimage, 或者all(即同时输出deb和all); + targets: string; /** 调试模式,会输出更多日志 */ debug: boolean; diff --git a/bin/utils/validate.ts b/bin/utils/validate.ts index a97821c..39b09f8 100644 --- a/bin/utils/validate.ts +++ b/bin/utils/validate.ts @@ -10,9 +10,9 @@ export function validateNumberInput(value: string) { } export function validateUrlInput(url: string) { - try { - return normalizeUrl(url); - } catch (error) { - throw new Commander.InvalidArgumentError(error.message); - } + try { + return normalizeUrl(url) + } catch (error) { + throw new Commander.InvalidArgumentError(error.message); + } } diff --git a/dist/cli.js b/dist/cli.js index 4f5aafa..615dd30 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -50,6 +50,7 @@ const DEFAULT_PAKE_OPTIONS = { userAgent: '', showMenu: false, showSystemTray: false, + targets: '', // iter_copy_file: false, systemTrayIcon: '', debug: false, @@ -1669,15 +1670,17 @@ function mergeTauriConfig(url, options, tauriConf) { // } else { // fs.rm // } - const url_exists = yield fs.stat(url) + let file_path = url.slice(8, url.length); + const url_exists = yield fs.stat(file_path) .then(() => true) .catch(() => false); if (url_exists) { + logger.warn("you input may a local file"); tauriConf.pake.windows[0].url_type = "local"; - const file_name = path.basename(url); + const file_name = path.basename(file_path); // const dir_name = path.dirname(url); const url_path = path.join("dist/", file_name); - yield fs.copyFile(url, url_path); + yield fs.copyFile(file_path, url_path); tauriConf.pake.windows[0].url = file_name; tauriConf.pake.windows[0].url_type = "local"; } @@ -1743,6 +1746,17 @@ function mergeTauriConfig(url, options, tauriConf) { tauriConf.pake.system_tray.macos = false; } } + // 处理targets 暂时只对linux开放 + if (process.platform === "linux") { + if (options.targets.length > 0) { + if (options.targets === "deb" || options.targets === "appimage" || options.targets === "all") { + tauriConf.tauri.bundle.targets = [options.targets]; + } + } + } + else { + tauriConf.tauri.bundle.targets = ["deb"]; + } tauriConf.package.productName = name; tauriConf.tauri.bundle.identifier = identifier; // 处理应用图标 @@ -2313,18 +2327,30 @@ class LinuxBuilder { arch = process.arch; } const debName = `${name}_${tauriConf.package.version}_${arch}.deb`; - const appPath = this.getBuildedAppPath(npmDirectory, "deb", debName); + const debPath = this.getBuildedAppPath(npmDirectory, "deb", debName); const distPath = path.resolve(`${name}.deb`); - yield fs.copyFile(appPath, distPath); - yield fs.unlink(appPath); + // 增加文件是否存在验证,再决定是否copy文件 + const debExists = yield fs.stat(debPath) + .then(() => true) + .catch(() => false); + if (debExists) { + yield fs.copyFile(debPath, distPath); + yield fs.unlink(debPath); + logger.success('Build success!'); + logger.success('You can find the deb app installer in', distPath); + } const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`; const appImagePath = this.getBuildedAppPath(npmDirectory, "appimage", appImageName); const distAppPath = path.resolve(`${name}.AppImage`); - yield fs.copyFile(appImagePath, distAppPath); - yield fs.unlink(appImagePath); - logger.success('Build success!'); - logger.success('You can find the deb app installer in', distPath); - logger.success('You can find the Appimage app installer in', distAppPath); + const appExists = yield fs.stat(appImagePath) + .then(() => true) + .catch(() => false); + if (appExists) { + yield fs.copyFile(appImagePath, distAppPath); + yield fs.unlink(appImagePath); + logger.success('Build success!'); + logger.success('You can find the Appimage app installer in', distAppPath); + } }); } getBuildedAppPath(npmDirectory, packageType, packageName) { @@ -2466,6 +2492,7 @@ program .option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu) .option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray) .option('--system-tray-icon ', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon) + .option('--targets ', 'only for linux, default is "deb", option "appaimge" or "all"(deb & appimage)', DEFAULT_PAKE_OPTIONS.targets) // .option('--iter-copy-file', // 'copy all static file to pake app when url is a static file', // DEFAULT_PAKE_OPTIONS.iter_copy_file) diff --git a/dist/index.html b/dist/index.html new file mode 100644 index 0000000..8a32f1a --- /dev/null +++ b/dist/index.html @@ -0,0 +1,559 @@ +AriaNg \ No newline at end of file From 2f9e104b511279ac4dc47e2b312665aefd34339d Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 11:24:22 +0800 Subject: [PATCH 11/22] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=89=93=E5=8C=85=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/builders/common.ts | 7 ++- bin/cli.ts | 5 +- bin/defaults.ts | 2 +- bin/options/index.ts | 11 ++++- bin/utils/validate.ts | 5 ++ dist/cli.js | 104 +++++++++++++++++++++-------------------- 6 files changed, 74 insertions(+), 60 deletions(-) diff --git a/bin/builders/common.ts b/bin/builders/common.ts index aba7cbf..4ae414d 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -75,17 +75,16 @@ export async function mergeTauriConfig( // } else { // fs.rm // } - let file_path = url.slice(8, url.length); - const url_exists = await fs.stat(file_path) + const url_exists = await fs.stat(url) .then(() => true) .catch(() => false); if (url_exists) { logger.warn("you input may a local file"); tauriConf.pake.windows[0].url_type = "local"; - const file_name = path.basename(file_path); + const file_name = path.basename(url); // const dir_name = path.dirname(url); const url_path = path.join("dist/", file_name); - await fs.copyFile(file_path, url_path); + await fs.copyFile(url, url_path); tauriConf.pake.windows[0].url = file_name; tauriConf.pake.windows[0].url_type = "local"; } else { diff --git a/bin/cli.ts b/bin/cli.ts index 312dc44..c50f9fa 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -9,6 +9,7 @@ import BuilderFactory from './builders/BuilderFactory.js'; import { checkUpdateTips } from './helpers/updater.js'; // @ts-expect-error import packageJson from '../package.json'; +import logger from './options/logger.js'; program.version(packageJson.version).description('A cli application can package a web page to desktop application.'); @@ -49,9 +50,9 @@ program const builder = BuilderFactory.create(); await builder.prepare(); - + // logger.warn("you input url is ", url); const appOptions = await handleInputOptions(options, url); - // logger.warn(JSON.stringify(appOptions, null, 4)); + // logger.info(JSON.stringify(appOptions, null, 4)); builder.build(url, appOptions); }); diff --git a/bin/defaults.ts b/bin/defaults.ts index 3804864..50516eb 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -10,7 +10,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { userAgent: '', showMenu: false, showSystemTray: false, - targets: '', + targets: 'deb', // iter_copy_file: false, systemTrayIcon: '', debug: false, diff --git a/bin/options/index.ts b/bin/options/index.ts index efcf4f6..f259dd5 100644 --- a/bin/options/index.ts +++ b/bin/options/index.ts @@ -3,15 +3,22 @@ import { getDomain } from '@/utils/url.js'; import { getIdentifier } from '../helpers/tauriConfig.js'; import { PakeAppOptions, PakeCliOptions } from '../types.js'; import { handleIcon } from './icon.js'; +import fs from 'fs/promises'; export default async function handleOptions(options: PakeCliOptions, url: string): Promise { const appOptions: PakeAppOptions = { ...options, identifier: '', }; - + const url_exists = await fs.stat(url) + .then(() => true) + .catch(() => false); if (!appOptions.name) { - appOptions.name = await promptText('please input your application name', getDomain(url)); + if (!url_exists) { + appOptions.name = await promptText('please input your application name', getDomain(url)); + } else { + appOptions.name = await promptText('please input your application name', ""); + } } appOptions.identifier = getIdentifier(appOptions.name, url); diff --git a/bin/utils/validate.ts b/bin/utils/validate.ts index 39b09f8..418c699 100644 --- a/bin/utils/validate.ts +++ b/bin/utils/validate.ts @@ -1,5 +1,6 @@ import * as Commander from 'commander'; import { normalizeUrl } from './url.js'; +import fs from 'fs'; export function validateNumberInput(value: string) { const parsedValue = Number(value); @@ -10,9 +11,13 @@ export function validateNumberInput(value: string) { } export function validateUrlInput(url: string) { + if(!fs.existsSync(url)) { try { return normalizeUrl(url) } catch (error) { throw new Commander.InvalidArgumentError(error.message); } + } else { + return url; + } } diff --git a/dist/cli.js b/dist/cli.js index 615dd30..b52ce14 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -3,9 +3,10 @@ import { program } from 'commander'; import log from 'loglevel'; import url, { fileURLToPath } from 'url'; import isurl from 'is-url'; +import fs from 'fs'; import prompts from 'prompts'; import path from 'path'; -import fs from 'fs/promises'; +import fs$1 from 'fs/promises'; import chalk from 'chalk'; import crypto from 'crypto'; import axios from 'axios'; @@ -50,7 +51,7 @@ const DEFAULT_PAKE_OPTIONS = { userAgent: '', showMenu: false, showSystemTray: false, - targets: '', + targets: 'deb', // iter_copy_file: false, systemTrayIcon: '', debug: false, @@ -1589,11 +1590,16 @@ function validateNumberInput(value) { return parsedValue; } function validateUrlInput(url) { - try { - return normalizeUrl(url); + if (!fs.existsSync(url)) { + try { + return normalizeUrl(url); + } + catch (error) { + throw new Commander.InvalidArgumentError(error.message); + } } - catch (error) { - throw new Commander.InvalidArgumentError(error.message); + else { + return url; } } @@ -1670,17 +1676,16 @@ function mergeTauriConfig(url, options, tauriConf) { // } else { // fs.rm // } - let file_path = url.slice(8, url.length); - const url_exists = yield fs.stat(file_path) + const url_exists = yield fs$1.stat(url) .then(() => true) .catch(() => false); if (url_exists) { logger.warn("you input may a local file"); tauriConf.pake.windows[0].url_type = "local"; - const file_name = path.basename(file_path); + const file_name = path.basename(url); // const dir_name = path.dirname(url); const url_path = path.join("dist/", file_name); - yield fs.copyFile(file_path, url_path); + yield fs$1.copyFile(url, url_path); tauriConf.pake.windows[0].url = file_name; tauriConf.pake.windows[0].url_type = "local"; } @@ -1760,7 +1765,7 @@ function mergeTauriConfig(url, options, tauriConf) { tauriConf.package.productName = name; tauriConf.tauri.bundle.identifier = identifier; // 处理应用图标 - const exists = yield fs.stat(options.icon) + const exists = yield fs$1.stat(options.icon) .then(() => true) .catch(() => false); if (exists) { @@ -1770,7 +1775,7 @@ function mergeTauriConfig(url, options, tauriConf) { if (customIconExt === ".ico") { const ico_path = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}_32.ico`); tauriConf.tauri.bundle.resources = [`png/${name.toLowerCase()}_32.ico`]; - yield fs.copyFile(options.icon, ico_path); + yield fs$1.copyFile(options.icon, ico_path); } else { updateIconPath = false; @@ -1801,7 +1806,7 @@ function mergeTauriConfig(url, options, tauriConf) { // 处理托盘自定义图标 let useDefaultIcon = true; // 是否使用默认托盘图标 if (systemTrayIcon.length > 0) { - const icon_exists = yield fs.stat(systemTrayIcon) + const icon_exists = yield fs$1.stat(systemTrayIcon) .then(() => true) .catch(() => false); if (icon_exists) { @@ -1811,7 +1816,7 @@ function mergeTauriConfig(url, options, tauriConf) { useDefaultIcon = false; const trayIcoPath = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}${iconExt}`); tauriConf.tauri.systemTray.iconPath = `png/${name.toLowerCase()}${iconExt}`; - yield fs.copyFile(systemTrayIcon, trayIcoPath); + yield fs$1.copyFile(systemTrayIcon, trayIcoPath); } else { logger.warn(`file type for system tray icon mut be .ico or .png , but you give ${iconExt}`); @@ -1849,14 +1854,14 @@ function mergeTauriConfig(url, options, tauriConf) { } } let bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } }; - yield fs.writeFile(configPath, Buffer.from(JSON.stringify(bundleConf, null, 4), 'utf-8')); + yield fs$1.writeFile(configPath, Buffer.from(JSON.stringify(bundleConf, null, 4), 'utf-8')); const pakeConfigPath = path.join(npmDirectory, 'src-tauri/pake.json'); - yield fs.writeFile(pakeConfigPath, Buffer.from(JSON.stringify(tauriConf.pake, null, 4), 'utf-8')); + yield fs$1.writeFile(pakeConfigPath, Buffer.from(JSON.stringify(tauriConf.pake, null, 4), 'utf-8')); let tauriConf2 = JSON.parse(JSON.stringify(tauriConf)); delete tauriConf2.pake; delete tauriConf2.tauri.bundle; const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json'); - yield fs.writeFile(configJsonPath, Buffer.from(JSON.stringify(tauriConf2, null, 4), 'utf-8')); + yield fs$1.writeFile(configJsonPath, Buffer.from(JSON.stringify(tauriConf2, null, 4), 'utf-8')); }); } @@ -1955,7 +1960,7 @@ function downloadIcon(iconUrl) { } const { path } = yield dir(); const iconPath = `${path}/icon.${fileDetails.ext}`; - yield fs.writeFile(iconPath, iconData); + yield fs$1.writeFile(iconPath, iconData); return iconPath; }); } @@ -1963,8 +1968,16 @@ function downloadIcon(iconUrl) { function handleOptions(options, url) { return __awaiter(this, void 0, void 0, function* () { const appOptions = Object.assign(Object.assign({}, options), { identifier: '' }); + const url_exists = yield fs$1.stat(url) + .then(() => true) + .catch(() => false); if (!appOptions.name) { - appOptions.name = yield promptText('please input your application name', getDomain(url)); + if (!url_exists) { + appOptions.name = yield promptText('please input your application name', getDomain(url)); + } + else { + appOptions.name = yield promptText('please input your application name', ""); + } } appOptions.identifier = getIdentifier(appOptions.name, url); appOptions.icon = yield handleIcon(appOptions); @@ -2013,29 +2026,22 @@ var tauri$3 = { active: false }, systemTray: { - iconPath: "png/weread_512.png", + iconPath: "/home/tlntin/data/code/rust_study/Pake/src-tauri/png/icon_512.png", iconAsTemplate: true } }; -var build = { - devPath: "../dist", - distDir: "../dist", - beforeBuildCommand: "", - beforeDevCommand: "" -}; var CommonConf = { "package": { - productName: "WeRead", + productName: "ccc", version: "1.0.0" }, - tauri: tauri$3, - build: build + tauri: tauri$3 }; var windows = [ { - url: "https://weread.qq.com/", - transparent: true, + url: "/home/tlntin/下载/AriaNg-1.3.2-AllInOne/index.html", + transparent: false, fullscreen: false, width: 1200, height: 780, @@ -2137,10 +2143,9 @@ var MacConf = { var tauri = { bundle: { icon: [ - "png/weread_256.ico", - "png/weread_512.png" + "/home/tlntin/data/code/rust_study/Pake/src-tauri/png/icon_512.png" ], - identifier: "com.tw93.weread", + identifier: "pake-34d841", active: true, category: "DeveloperTool", copyright: "", @@ -2156,10 +2161,7 @@ var tauri = { "librsvg2-dev", "gnome-video-effects", "gnome-video-effects-extra" - ], - files: { - "/usr/share/applications/com-tw93-weread.desktop": "assets/com-tw93-weread.desktop" - } + ] }, externalBin: [ ], @@ -2168,8 +2170,7 @@ var tauri = { ], shortDescription: "", targets: [ - "deb", - "appimage" + "deb" ] } }; @@ -2234,8 +2235,8 @@ class MacBuilder { const dmgName = `${name}_${tauriConf.package.version}_${arch}.dmg`; const appPath = this.getBuildedAppPath(npmDirectory, dmgName); const distPath = path.resolve(`${name}.dmg`); - yield fs.copyFile(appPath, distPath); - yield fs.unlink(appPath); + yield fs$1.copyFile(appPath, distPath); + yield fs$1.unlink(appPath); logger.success('Build success!'); logger.success('You can find the app installer in', distPath); }); @@ -2279,8 +2280,8 @@ class WinBuilder { const msiName = `${name}_${tauriConf.package.version}_${arch}_${language}.msi`; const appPath = this.getBuildedAppPath(npmDirectory, msiName); const distPath = path.resolve(`${name}.msi`); - yield fs.copyFile(appPath, distPath); - yield fs.unlink(appPath); + yield fs$1.copyFile(appPath, distPath); + yield fs$1.unlink(appPath); logger.success('Build success!'); logger.success('You can find the app installer in', distPath); }); @@ -2330,24 +2331,24 @@ class LinuxBuilder { const debPath = this.getBuildedAppPath(npmDirectory, "deb", debName); const distPath = path.resolve(`${name}.deb`); // 增加文件是否存在验证,再决定是否copy文件 - const debExists = yield fs.stat(debPath) + const debExists = yield fs$1.stat(debPath) .then(() => true) .catch(() => false); if (debExists) { - yield fs.copyFile(debPath, distPath); - yield fs.unlink(debPath); + yield fs$1.copyFile(debPath, distPath); + yield fs$1.unlink(debPath); logger.success('Build success!'); logger.success('You can find the deb app installer in', distPath); } const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`; const appImagePath = this.getBuildedAppPath(npmDirectory, "appimage", appImageName); const distAppPath = path.resolve(`${name}.AppImage`); - const appExists = yield fs.stat(appImagePath) + const appExists = yield fs$1.stat(appImagePath) .then(() => true) .catch(() => false); if (appExists) { - yield fs.copyFile(appImagePath, distAppPath); - yield fs.unlink(appImagePath); + yield fs$1.copyFile(appImagePath, distAppPath); + yield fs$1.unlink(appImagePath); logger.success('Build success!'); logger.success('You can find the Appimage app installer in', distAppPath); } @@ -2509,8 +2510,9 @@ program } const builder = BuilderFactory.create(); yield builder.prepare(); + // logger.warn("you input url is ", url); const appOptions = yield handleOptions(options, url); - // logger.warn(JSON.stringify(appOptions, null, 4)); + // logger.info(JSON.stringify(appOptions, null, 4)); builder.build(url, appOptions); })); program.parse(); From 6f921ebee4c1a28de15a8794b2c7966f2ef7636c Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 11:28:35 +0800 Subject: [PATCH 12/22] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=89=93=E5=8C=85=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/builders/common.ts | 2 +- dist/cli.js | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/bin/builders/common.ts b/bin/builders/common.ts index 4ae414d..df75227 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -83,7 +83,7 @@ export async function mergeTauriConfig( tauriConf.pake.windows[0].url_type = "local"; const file_name = path.basename(url); // const dir_name = path.dirname(url); - const url_path = path.join("dist/", file_name); + const url_path = path.join(npmDirectory,"dist/", file_name); await fs.copyFile(url, url_path); tauriConf.pake.windows[0].url = file_name; tauriConf.pake.windows[0].url_type = "local"; diff --git a/dist/cli.js b/dist/cli.js index b52ce14..306dc1e 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1684,7 +1684,7 @@ function mergeTauriConfig(url, options, tauriConf) { tauriConf.pake.windows[0].url_type = "local"; const file_name = path.basename(url); // const dir_name = path.dirname(url); - const url_path = path.join("dist/", file_name); + const url_path = path.join(npmDirectory, "dist/", file_name); yield fs$1.copyFile(url, url_path); tauriConf.pake.windows[0].url = file_name; tauriConf.pake.windows[0].url_type = "local"; @@ -2026,22 +2026,29 @@ var tauri$3 = { active: false }, systemTray: { - iconPath: "/home/tlntin/data/code/rust_study/Pake/src-tauri/png/icon_512.png", + iconPath: "png/weread_512.png", iconAsTemplate: true } }; +var build = { + devPath: "../dist", + distDir: "../dist", + beforeBuildCommand: "", + beforeDevCommand: "" +}; var CommonConf = { "package": { - productName: "ccc", + productName: "WeRead", version: "1.0.0" }, - tauri: tauri$3 + tauri: tauri$3, + build: build }; var windows = [ { - url: "/home/tlntin/下载/AriaNg-1.3.2-AllInOne/index.html", - transparent: false, + url: "https://weread.qq.com/", + transparent: true, fullscreen: false, width: 1200, height: 780, @@ -2143,9 +2150,10 @@ var MacConf = { var tauri = { bundle: { icon: [ - "/home/tlntin/data/code/rust_study/Pake/src-tauri/png/icon_512.png" + "png/weread_256.ico", + "png/weread_512.png" ], - identifier: "pake-34d841", + identifier: "com.tw93.weread", active: true, category: "DeveloperTool", copyright: "", @@ -2161,7 +2169,10 @@ var tauri = { "librsvg2-dev", "gnome-video-effects", "gnome-video-effects-extra" - ] + ], + files: { + "/usr/share/applications/com-tw93-weread.desktop": "assets/com-tw93-weread.desktop" + } }, externalBin: [ ], @@ -2170,7 +2181,8 @@ var tauri = { ], shortDescription: "", targets: [ - "deb" + "deb", + "appimage" ] } }; From fb7b6ce6cb2ea41ae480c2f944990470b1de93d4 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 11:36:43 +0800 Subject: [PATCH 13/22] =?UTF-8?q?=E5=88=A0=E9=99=A4pake-cli=20=E9=BB=98?= =?UTF-8?q?=E8=AE=A4linux=E5=B9=B3=E5=8F=B0=E7=9A=84=E6=A1=8C=E9=9D=A2?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E6=96=87=E4=BB=B6=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/builders/common.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/builders/common.ts b/bin/builders/common.ts index df75227..27514e7 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -175,6 +175,11 @@ export async function mergeTauriConfig( tauriConf.package.productName = name; tauriConf.tauri.bundle.identifier = identifier; + // 删除映射关系 + if (process.platform === "linux") { + delete tauriConf.tauri.bundle.deb.files; + } + // 处理应用图标 const exists = await fs.stat(options.icon) .then(() => true) @@ -193,7 +198,6 @@ export async function mergeTauriConfig( } } if (process.platform === "linux") { - delete tauriConf.tauri.bundle.deb.files; if (customIconExt != ".png") { updateIconPath = false; logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`); From a02b70926c0e0c57b9774110329aba9c3bfbd5a4 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 11:36:56 +0800 Subject: [PATCH 14/22] =?UTF-8?q?=E5=88=A0=E9=99=A4pake-cli=20=E9=BB=98?= =?UTF-8?q?=E8=AE=A4linux=E5=B9=B3=E5=8F=B0=E7=9A=84=E6=A1=8C=E9=9D=A2?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E6=96=87=E4=BB=B6=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/cli.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dist/cli.js b/dist/cli.js index 306dc1e..97167b2 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1764,6 +1764,10 @@ function mergeTauriConfig(url, options, tauriConf) { } tauriConf.package.productName = name; tauriConf.tauri.bundle.identifier = identifier; + // 删除映射关系 + if (process.platform === "linux") { + delete tauriConf.tauri.bundle.deb.files; + } // 处理应用图标 const exists = yield fs$1.stat(options.icon) .then(() => true) @@ -1783,7 +1787,6 @@ function mergeTauriConfig(url, options, tauriConf) { } } if (process.platform === "linux") { - delete tauriConf.tauri.bundle.deb.files; if (customIconExt != ".png") { updateIconPath = false; logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`); From 7980ea8823a3309c014310d2f5cd74edc7889494 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 11:39:14 +0800 Subject: [PATCH 15/22] =?UTF-8?q?=E5=88=A0=E9=99=A4pake-cli=20=E9=BB=98?= =?UTF-8?q?=E8=AE=A4linux=E5=B9=B3=E5=8F=B0=E7=9A=84=E6=A1=8C=E9=9D=A2?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E6=96=87=E4=BB=B6=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/builders/common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/builders/common.ts b/bin/builders/common.ts index 27514e7..9dca3df 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -177,7 +177,7 @@ export async function mergeTauriConfig( // 删除映射关系 if (process.platform === "linux") { - delete tauriConf.tauri.bundle.deb.files; + tauriConf.tauri.bundle.deb.files = []; } // 处理应用图标 From f11b03d13c758752e3c9ab06efa64ba8def1ad72 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 11:45:35 +0800 Subject: [PATCH 16/22] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/builders/common.ts | 3 +++ dist/cli.js | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/builders/common.ts b/bin/builders/common.ts index 9dca3df..62ccf50 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -195,18 +195,21 @@ export async function mergeTauriConfig( } else { updateIconPath = false; logger.warn(`icon file in Windows must be 256 * 256 pix with .ico type, but you give ${customIconExt}`); + tauriConf.tauri.bundle.icon = ["png/icon_256.ico"]; } } if (process.platform === "linux") { if (customIconExt != ".png") { updateIconPath = false; logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`); + tauriConf.tauri.bundle.icon = ["png/icon_512.png"]; } } if (process.platform === "darwin" && customIconExt !== ".icns") { updateIconPath = false; logger.warn(`icon file in MacOS must be .icns type, but you give ${customIconExt}`); + tauriConf.tauri.bundle.icon = ["icons/icon.icns"]; } if (updateIconPath) { tauriConf.tauri.bundle.icon = [options.icon]; diff --git a/dist/cli.js b/dist/cli.js index 97167b2..f48a112 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1766,7 +1766,7 @@ function mergeTauriConfig(url, options, tauriConf) { tauriConf.tauri.bundle.identifier = identifier; // 删除映射关系 if (process.platform === "linux") { - delete tauriConf.tauri.bundle.deb.files; + tauriConf.tauri.bundle.deb.files = []; } // 处理应用图标 const exists = yield fs$1.stat(options.icon) @@ -1784,17 +1784,20 @@ function mergeTauriConfig(url, options, tauriConf) { else { updateIconPath = false; logger.warn(`icon file in Windows must be 256 * 256 pix with .ico type, but you give ${customIconExt}`); + tauriConf.tauri.bundle.icon = ["png/icon_256.ico"]; } } if (process.platform === "linux") { if (customIconExt != ".png") { updateIconPath = false; logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`); + tauriConf.tauri.bundle.icon = ["png/icon_512.png"]; } } if (process.platform === "darwin" && customIconExt !== ".icns") { updateIconPath = false; logger.warn(`icon file in MacOS must be .icns type, but you give ${customIconExt}`); + tauriConf.tauri.bundle.icon = ["icons/icon.icns"]; } if (updateIconPath) { tauriConf.tauri.bundle.icon = [options.icon]; From 8ef542bfc795fc37308faf58c0b68f6cddb04463 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 11:48:10 +0800 Subject: [PATCH 17/22] =?UTF-8?q?=E5=88=A0=E9=99=A4linux=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=98=A0=E5=B0=84=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/builders/common.ts | 2 +- dist/cli.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/builders/common.ts b/bin/builders/common.ts index 62ccf50..c5985fa 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -177,7 +177,7 @@ export async function mergeTauriConfig( // 删除映射关系 if (process.platform === "linux") { - tauriConf.tauri.bundle.deb.files = []; + delete tauriConf.tauri.bundle.deb.files; } // 处理应用图标 diff --git a/dist/cli.js b/dist/cli.js index f48a112..41cd397 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1766,7 +1766,7 @@ function mergeTauriConfig(url, options, tauriConf) { tauriConf.tauri.bundle.identifier = identifier; // 删除映射关系 if (process.platform === "linux") { - tauriConf.tauri.bundle.deb.files = []; + delete tauriConf.tauri.bundle.deb.files; } // 处理应用图标 const exists = yield fs$1.stat(options.icon) From 48c2707a44dab1dce286e8d1f02a628bdac70abb Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 11:54:01 +0800 Subject: [PATCH 18/22] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=9A=84=E8=87=AA=E5=AE=9A=E4=B9=89=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=97=B6=E5=80=99=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=9B=BE=E6=A0=87=E4=B8=BA=E5=BE=AE=E4=BF=A1=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/builders/common.ts | 9 +++++++++ dist/cli.js | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/bin/builders/common.ts b/bin/builders/common.ts index c5985fa..5baebd1 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -218,6 +218,15 @@ export async function mergeTauriConfig( } } else { logger.warn("the custom icon path may not exists. we will use default icon to replace it"); + if (process.platform === "win32") { + tauriConf.tauri.bundle.icon = ["png/icon_256.ico"]; + } + if (process.platform === "linux") { + tauriConf.tauri.bundle.icon = ["png/icon_512.png"]; + } + if (process.platform === "darwin") { + tauriConf.tauri.bundle.icon = ["icons/icon.icns"]; + } } // 处理托盘自定义图标 diff --git a/dist/cli.js b/dist/cli.js index 41cd397..2754600 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1808,6 +1808,15 @@ function mergeTauriConfig(url, options, tauriConf) { } else { logger.warn("the custom icon path may not exists. we will use default icon to replace it"); + if (process.platform === "win32") { + tauriConf.tauri.bundle.icon = ["png/icon_256.ico"]; + } + if (process.platform === "linux") { + tauriConf.tauri.bundle.icon = ["png/icon_512.png"]; + } + if (process.platform === "darwin") { + tauriConf.tauri.bundle.icon = ["icons/icon.icns"]; + } } // 处理托盘自定义图标 let useDefaultIcon = true; // 是否使用默认托盘图标 From 5dfe806c9861baccbb1dd8e3d4be0be069efcc56 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 12:56:36 +0800 Subject: [PATCH 19/22] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=92=E5=BD=92?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/README.md | 9 + bin/README_EN.md | 9 + bin/builders/common.ts | 34 ++- bin/cli.ts | 6 +- bin/defaults.ts | 2 +- bin/types.ts | 5 +- dist/cli.js | 42 ++-- dist/index.html | 559 ----------------------------------------- package.json | 2 + 9 files changed, 72 insertions(+), 596 deletions(-) delete mode 100644 dist/index.html diff --git a/bin/README.md b/bin/README.md index 39c70be..8d4f99d 100644 --- a/bin/README.md +++ b/bin/README.md @@ -119,4 +119,13 @@ url 为你需要打包的网页链接 🔗或者本地html文件,必须提供 ```shell --system-tray-icon +``` + + +#### [copy-iter-file] + +递归拷贝,当url为本地文件路径时候,若开启该选项,则将url路径文件所在文件夹以及所有子文件都拷贝到pake静态文件夹,默认不开启 + +```shell +--copy-iter-file ``` \ No newline at end of file diff --git a/bin/README_EN.md b/bin/README_EN.md index 331065a..27d5321 100644 --- a/bin/README_EN.md +++ b/bin/README_EN.md @@ -119,3 +119,12 @@ The notification tray icon is only valid when the notification tray is displayed ```shell --system-tray-icon ``` + + +#### [copy-iter-file] + +Recursive copy, when the url is a local file path, if this option is enabled, the folder where the url path file is located and all sub-files are copied to the pake static folder, which is not enabled by default + +```shell +--copy-iter-file +``` diff --git a/bin/builders/common.ts b/bin/builders/common.ts index 5baebd1..bfe58fb 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -2,9 +2,11 @@ import { PakeAppOptions } from '@/types.js'; import prompts from 'prompts'; import path from 'path'; import fs from 'fs/promises'; +import fs2 from 'fs-extra'; import { npmDirectory } from '@/utils/dir.js'; import logger from '@/options/logger.js'; + export async function promptText(message: string, initial?: string) { const response = await prompts({ type: 'text', @@ -31,7 +33,7 @@ export async function mergeTauriConfig( showMenu, showSystemTray, systemTrayIcon, - // iter_copy_file, + iterCopyFile, identifier, name, } = options; @@ -65,16 +67,8 @@ export async function mergeTauriConfig( // logger.warn(JSON.stringify(tauriConf.pake.windows, null, 4)); Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); // 判断一下url类型,是文件还是网站 - // 如果是文件,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下(待做) + // 如果是文件,并且开启了递归拷贝功能,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下,否则只拷贝单个文件。 - // const src_exists = await fs.stat("src") - // .then(() => true) - // .catch(() => false); - // if (!src_exists) { - // fs.mkdir("src") - // } else { - // fs.rm - // } const url_exists = await fs.stat(url) .then(() => true) .catch(() => false); @@ -82,9 +76,23 @@ export async function mergeTauriConfig( logger.warn("you input may a local file"); tauriConf.pake.windows[0].url_type = "local"; const file_name = path.basename(url); - // const dir_name = path.dirname(url); - const url_path = path.join(npmDirectory,"dist/", file_name); - await fs.copyFile(url, url_path); + const dir_name = path.dirname(url); + if (!iterCopyFile) { + const url_path = path.join(npmDirectory,"dist/", file_name); + await fs.copyFile(url, url_path); + } else { + const old_dir = path.join(npmDirectory,"dist/"); + const new_dir = path.join(npmDirectory,"dist_bak/"); + fs.rename(old_dir, new_dir); + fs2.copy(dir_name, old_dir); + // 将dist_bak里面的cli.js和about_pake.html拷贝回去 + const cli_path = path.join(new_dir, "cli.js") + const cli_path_target = path.join(old_dir, "cli.js") + const about_pake_path = path.join(new_dir, "about_pake.html"); + const about_patk_path_target = path.join(new_dir, "about_pake.html") + fs.copyFile(cli_path, cli_path_target); + fs.copyFile(about_pake_path, about_patk_path_target); + } tauriConf.pake.windows[0].url = file_name; tauriConf.pake.windows[0].url_type = "local"; } else { diff --git a/bin/cli.ts b/bin/cli.ts index c50f9fa..294a06b 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -27,13 +27,13 @@ program .option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu) .option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray) .option('--system-tray-icon ', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon) + .option('--iter-copy-file', + 'copy all static file to pake app when url is a local file', + DEFAULT_PAKE_OPTIONS.iterCopyFile) .option( '--targets ', 'only for linux, default is "deb", option "appaimge" or "all"(deb & appimage)', DEFAULT_PAKE_OPTIONS.targets) - // .option('--iter-copy-file', - // 'copy all static file to pake app when url is a static file', - // DEFAULT_PAKE_OPTIONS.iter_copy_file) .option('--debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent) .action(async (url: string, options: PakeCliOptions) => { checkUpdateTips(); diff --git a/bin/defaults.ts b/bin/defaults.ts index 50516eb..4200bb4 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -11,7 +11,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { showMenu: false, showSystemTray: false, targets: 'deb', - // iter_copy_file: false, + iterCopyFile: false, systemTrayIcon: '', debug: false, }; diff --git a/bin/types.ts b/bin/types.ts index 6725079..dbb9672 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -32,8 +32,9 @@ export interface PakeCliOptions { /** 托盘图标, Windows、Linux默认和应用图标共用一样的,MacOS需要提别提供, 格式为png或者ico */ systemTrayIcon: string; - // /** 递归拷贝,当url为本地文件路径时候,将文件所在文件夹下面的所有子文件都拷贝到pake静态文件夹,默认不开启 */ - // iter_copy_file: false; + // /** 递归拷贝,当url为本地文件路径时候,若开启该选项,则将url路径文件所在文件夹以及所有子文件都拷贝到pake静态文件夹,默认不开启 */ + iterCopyFile: false; + // 包输出产物,对linux用户有效,默认为deb,可选appimage, 或者all(即同时输出deb和all); targets: string; diff --git a/dist/cli.js b/dist/cli.js index 2754600..c003df5 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -7,6 +7,7 @@ import fs from 'fs'; import prompts from 'prompts'; import path from 'path'; import fs$1 from 'fs/promises'; +import fs2 from 'fs-extra'; import chalk from 'chalk'; import crypto from 'crypto'; import axios from 'axios'; @@ -52,7 +53,7 @@ const DEFAULT_PAKE_OPTIONS = { showMenu: false, showSystemTray: false, targets: 'deb', - // iter_copy_file: false, + iterCopyFile: false, systemTrayIcon: '', debug: false, }; @@ -1636,9 +1637,7 @@ function promptText(message, initial) { } function mergeTauriConfig(url, options, tauriConf) { return __awaiter(this, void 0, void 0, function* () { - const { width, height, fullscreen, transparent, resizable, userAgent, showMenu, showSystemTray, systemTrayIcon, - // iter_copy_file, - identifier, name, } = options; + const { width, height, fullscreen, transparent, resizable, userAgent, showMenu, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, } = options; const tauriConfWindowOptions = { width, height, @@ -1668,14 +1667,6 @@ function mergeTauriConfig(url, options, tauriConf) { Object.assign(tauriConf.pake.windows[0], Object.assign({ url }, tauriConfWindowOptions)); // 判断一下url类型,是文件还是网站 // 如果是文件,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下(待做) - // const src_exists = await fs.stat("src") - // .then(() => true) - // .catch(() => false); - // if (!src_exists) { - // fs.mkdir("src") - // } else { - // fs.rm - // } const url_exists = yield fs$1.stat(url) .then(() => true) .catch(() => false); @@ -1683,9 +1674,24 @@ function mergeTauriConfig(url, options, tauriConf) { logger.warn("you input may a local file"); tauriConf.pake.windows[0].url_type = "local"; const file_name = path.basename(url); - // const dir_name = path.dirname(url); - const url_path = path.join(npmDirectory, "dist/", file_name); - yield fs$1.copyFile(url, url_path); + const dir_name = path.dirname(url); + if (!iterCopyFile) { + const url_path = path.join(npmDirectory, "dist/", file_name); + yield fs$1.copyFile(url, url_path); + } + else { + const old_dir = path.join(npmDirectory, "dist/"); + const new_dir = path.join(npmDirectory, "dist_bak/"); + fs$1.rename(old_dir, new_dir); + fs2.copy(dir_name, old_dir); + // 将dist_bak里面的cli.js和about_pake.html拷贝回去 + const cli_path = path.join(new_dir, "cli.js"); + const cli_path_target = path.join(old_dir, "cli.js"); + const about_pake_path = path.join(new_dir, "about_pake.html"); + const about_patk_path_target = path.join(new_dir, "about_pake.html"); + fs$1.copyFile(cli_path, cli_path_target); + fs$1.copyFile(about_pake_path, about_patk_path_target); + } tauriConf.pake.windows[0].url = file_name; tauriConf.pake.windows[0].url_type = "local"; } @@ -2454,6 +2460,7 @@ var dependencies = { chalk: "^5.1.2", commander: "^9.4.1", "file-type": "^18.0.0", + "fs-extra": "^11.1.0", "is-url": "^1.2.4", loglevel: "^1.8.1", ora: "^6.1.2", @@ -2468,6 +2475,7 @@ var devDependencies = { "@rollup/plugin-json": "^5.0.1", "@rollup/plugin-terser": "^0.1.0", "@rollup/plugin-typescript": "^9.0.2", + "@types/fs-extra": "^9.0.13", "@types/is-url": "^1.2.30", "@types/page-icon": "^0.3.4", "@types/prompts": "^2.4.1", @@ -2520,10 +2528,8 @@ program .option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu) .option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray) .option('--system-tray-icon ', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon) + .option('--iter-copy-file', 'copy all static file to pake app when url is a local file', DEFAULT_PAKE_OPTIONS.iterCopyFile) .option('--targets ', 'only for linux, default is "deb", option "appaimge" or "all"(deb & appimage)', DEFAULT_PAKE_OPTIONS.targets) - // .option('--iter-copy-file', - // 'copy all static file to pake app when url is a static file', - // DEFAULT_PAKE_OPTIONS.iter_copy_file) .option('--debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent) .action((url, options) => __awaiter(void 0, void 0, void 0, function* () { checkUpdateTips(); diff --git a/dist/index.html b/dist/index.html deleted file mode 100644 index 8a32f1a..0000000 --- a/dist/index.html +++ /dev/null @@ -1,559 +0,0 @@ -AriaNg \ No newline at end of file diff --git a/package.json b/package.json index 0edaf8d..30fc33d 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "chalk": "^5.1.2", "commander": "^9.4.1", "file-type": "^18.0.0", + "fs-extra": "^11.1.0", "is-url": "^1.2.4", "loglevel": "^1.8.1", "ora": "^6.1.2", @@ -66,6 +67,7 @@ "@rollup/plugin-json": "^5.0.1", "@rollup/plugin-terser": "^0.1.0", "@rollup/plugin-typescript": "^9.0.2", + "@types/fs-extra": "^9.0.13", "@types/is-url": "^1.2.30", "@types/page-icon": "^0.3.4", "@types/prompts": "^2.4.1", From ad2887cdad0382ad312a9acf62a890ae2360eb33 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 12:56:50 +0800 Subject: [PATCH 20/22] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=92=E5=BD=92?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/cli.js b/dist/cli.js index c003df5..54d8e72 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1666,7 +1666,7 @@ function mergeTauriConfig(url, options, tauriConf) { // logger.warn(JSON.stringify(tauriConf.pake.windows, null, 4)); Object.assign(tauriConf.pake.windows[0], Object.assign({ url }, tauriConfWindowOptions)); // 判断一下url类型,是文件还是网站 - // 如果是文件,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下(待做) + // 如果是文件,并且开启了递归拷贝功能,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下,否则只拷贝单个文件。 const url_exists = yield fs$1.stat(url) .then(() => true) .catch(() => false); From 09d0300b3b6ac6bad56e766b7d6dee24b7887c7f Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 13:59:51 +0800 Subject: [PATCH 21/22] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=92=E5=BD=92?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E5=8A=9F=E8=83=BD=E6=8A=A5=E9=94=99=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/builders/common.ts | 9 +++++---- dist/cli.js | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bin/builders/common.ts b/bin/builders/common.ts index bfe58fb..6f60eb6 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -1,5 +1,5 @@ import { PakeAppOptions } from '@/types.js'; -import prompts from 'prompts'; +import prompts, { override } from 'prompts'; import path from 'path'; import fs from 'fs/promises'; import fs2 from 'fs-extra'; @@ -83,13 +83,14 @@ export async function mergeTauriConfig( } else { const old_dir = path.join(npmDirectory,"dist/"); const new_dir = path.join(npmDirectory,"dist_bak/"); - fs.rename(old_dir, new_dir); - fs2.copy(dir_name, old_dir); + fs2.moveSync(old_dir, new_dir, {"overwrite": true}); + fs2.copySync(dir_name, old_dir, {"overwrite": true}); + // logger.warn("dir name", dir_name); // 将dist_bak里面的cli.js和about_pake.html拷贝回去 const cli_path = path.join(new_dir, "cli.js") const cli_path_target = path.join(old_dir, "cli.js") const about_pake_path = path.join(new_dir, "about_pake.html"); - const about_patk_path_target = path.join(new_dir, "about_pake.html") + const about_patk_path_target = path.join(old_dir, "about_pake.html") fs.copyFile(cli_path, cli_path_target); fs.copyFile(about_pake_path, about_patk_path_target); } diff --git a/dist/cli.js b/dist/cli.js index 54d8e72..372bae8 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1682,13 +1682,14 @@ function mergeTauriConfig(url, options, tauriConf) { else { const old_dir = path.join(npmDirectory, "dist/"); const new_dir = path.join(npmDirectory, "dist_bak/"); - fs$1.rename(old_dir, new_dir); - fs2.copy(dir_name, old_dir); + fs2.moveSync(old_dir, new_dir, { "overwrite": true }); + fs2.copySync(dir_name, old_dir, { "overwrite": true }); + // logger.warn("dir name", dir_name); // 将dist_bak里面的cli.js和about_pake.html拷贝回去 const cli_path = path.join(new_dir, "cli.js"); const cli_path_target = path.join(old_dir, "cli.js"); const about_pake_path = path.join(new_dir, "about_pake.html"); - const about_patk_path_target = path.join(new_dir, "about_pake.html"); + const about_patk_path_target = path.join(old_dir, "about_pake.html"); fs$1.copyFile(cli_path, cli_path_target); fs$1.copyFile(about_pake_path, about_patk_path_target); } From a6328da6e484d5030d238a855bb5e9d21e2e53ea Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 29 Dec 2022 14:02:49 +0800 Subject: [PATCH 22/22] =?UTF-8?q?=E6=9B=B4=E6=96=B0.gitignore=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index a6966ae..f85b77a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,7 @@ output package-lock.json yarn.lock pnpm-lock.yaml +dist +!dist/about_pake.html +!dist/cli.js +!dist/.gitkeep