pake-cli 3.0.3 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/cli.js +29 -21
  2. package/dist/dev.js +6 -5
  3. package/dist/dev.js.map +1 -1
  4. package/package.json +2 -2
  5. package/src-tauri/.pake/pake.json +30 -0
  6. package/src-tauri/.pake/tauri.conf.json +24 -0
  7. package/src-tauri/.pake/tauri.macos.conf.json +15 -0
  8. package/src-tauri/Cargo.lock +396 -224
  9. package/src-tauri/Cargo.toml +9 -9
  10. package/src-tauri/capabilities/default.json +7 -1
  11. package/src-tauri/gen/schemas/acl-manifests.json +1 -1
  12. package/src-tauri/gen/schemas/capabilities.json +1 -1
  13. package/src-tauri/gen/schemas/desktop-schema.json +215 -0
  14. package/src-tauri/gen/schemas/macOS-schema.json +215 -0
  15. package/src-tauri/icons/excalidraw.icns +0 -0
  16. package/src-tauri/icons/gemini.icns +0 -0
  17. package/src-tauri/icons/xiaohongshu.icns +0 -0
  18. package/src-tauri/png/chatgpt_512.png +0 -0
  19. package/src-tauri/png/excalidraw_256.ico +0 -0
  20. package/src-tauri/png/excalidraw_32.ico +0 -0
  21. package/src-tauri/png/excalidraw_512.png +0 -0
  22. package/src-tauri/png/flomo_512.png +0 -0
  23. package/src-tauri/png/gemini_256.ico +0 -0
  24. package/src-tauri/png/gemini_32.ico +0 -0
  25. package/src-tauri/png/gemini_512.png +0 -0
  26. package/src-tauri/png/icon_512.png +0 -0
  27. package/src-tauri/png/lizhi_512.png +0 -0
  28. package/src-tauri/png/programmusic_512.png +0 -0
  29. package/src-tauri/png/qwerty_512.png +0 -0
  30. package/src-tauri/png/twitter_512.png +0 -0
  31. package/src-tauri/png/wechat_512.png +0 -0
  32. package/src-tauri/png/weread_512.png +0 -0
  33. package/src-tauri/png/xiaohongshu_256.ico +0 -0
  34. package/src-tauri/png/xiaohongshu_32.ico +0 -0
  35. package/src-tauri/png/xiaohongshu_512.png +0 -0
  36. package/src-tauri/png/youtube_512.png +0 -0
  37. package/src-tauri/png/youtubemusic_512.png +0 -0
  38. package/src-tauri/src/app/invoke.rs +20 -0
  39. package/src-tauri/src/app/mod.rs +1 -1
  40. package/src-tauri/src/app/setup.rs +95 -0
  41. package/src-tauri/src/app/window.rs +6 -2
  42. package/src-tauri/src/inject/event.js +32 -1
  43. package/src-tauri/src/inject/style.js +12 -4
  44. package/src-tauri/src/lib.rs +37 -87
  45. package/src-tauri/src/util.rs +1 -2
  46. package/src-tauri/icons/coderunner.icns +0 -0
  47. package/src-tauri/icons/devv.icns +0 -0
  48. package/src-tauri/icons/juchats.icns +0 -0
  49. package/src-tauri/icons/poe.icns +0 -0
  50. package/src-tauri/icons/reference.icns +0 -0
  51. package/src-tauri/icons/xiaoyuzhou.icns +0 -0
  52. package/src-tauri/png/coderunner_256.ico +0 -0
  53. package/src-tauri/png/coderunner_32.ico +0 -0
  54. package/src-tauri/png/coderunner_512.png +0 -0
  55. package/src-tauri/png/poe_256.ico +0 -0
  56. package/src-tauri/png/poe_32.ico +0 -0
  57. package/src-tauri/png/poe_512.png +0 -0
  58. package/src-tauri/png/reference_256.ico +0 -0
  59. package/src-tauri/png/reference_32.ico +0 -0
  60. package/src-tauri/png/reference_512.png +0 -0
  61. package/src-tauri/src/app/menu.rs +0 -36
@@ -0,0 +1,95 @@
1
+ use std::str::FromStr;
2
+ use std::sync::{Arc, Mutex};
3
+ use std::time::{Duration, Instant};
4
+ use tauri::{
5
+ menu::{MenuBuilder, MenuItemBuilder},
6
+ tray::TrayIconBuilder,
7
+ AppHandle, Manager,
8
+ };
9
+ use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
10
+ use tauri_plugin_window_state::{AppHandleExt, StateFlags};
11
+
12
+ pub fn set_system_tray(app: &AppHandle, show_system_tray: bool) -> tauri::Result<()> {
13
+ if !show_system_tray {
14
+ app.remove_tray_by_id("pake-tray");
15
+ return Ok(());
16
+ }
17
+
18
+ let hide_app = MenuItemBuilder::with_id("hide_app", "Hide").build(app)?;
19
+ let show_app = MenuItemBuilder::with_id("show_app", "Show").build(app)?;
20
+ let quit = MenuItemBuilder::with_id("quit", "Quit").build(app)?;
21
+
22
+ let menu = MenuBuilder::new(app)
23
+ .items(&[&hide_app, &show_app, &quit])
24
+ .build()?;
25
+
26
+ app.app_handle().remove_tray_by_id("pake-tray");
27
+
28
+ let tray = TrayIconBuilder::new()
29
+ .menu(&menu)
30
+ .on_menu_event(move |app, event| match event.id().as_ref() {
31
+ "hide_app" => {
32
+ if let Some(window) = app.get_webview_window("pake") {
33
+ window.minimize().unwrap();
34
+ }
35
+ }
36
+ "show_app" => {
37
+ if let Some(window) = app.get_webview_window("pake") {
38
+ window.show().unwrap();
39
+ }
40
+ }
41
+ "quit" => {
42
+ app.save_window_state(StateFlags::all()).unwrap();
43
+ std::process::exit(0);
44
+ }
45
+ _ => (),
46
+ })
47
+ .icon(app.default_window_icon().unwrap().clone())
48
+ .build(app)?;
49
+
50
+ tray.set_icon_as_template(false)?;
51
+ Ok(())
52
+ }
53
+
54
+ pub fn set_global_shortcut(app: &AppHandle, shortcut: String) -> tauri::Result<()> {
55
+ if shortcut.is_empty() {
56
+ return Ok(());
57
+ }
58
+
59
+ let app_handle = app.clone();
60
+ let shortcut_hotkey = Shortcut::from_str(&shortcut).unwrap();
61
+ let last_triggered = Arc::new(Mutex::new(Instant::now()));
62
+
63
+ app_handle
64
+ .plugin(
65
+ tauri_plugin_global_shortcut::Builder::new()
66
+ .with_handler({
67
+ let last_triggered = Arc::clone(&last_triggered);
68
+ move |app, event, _shortcut| {
69
+ let mut last_triggered = last_triggered.lock().unwrap();
70
+ if Instant::now().duration_since(*last_triggered) < Duration::from_millis(300) {
71
+ return;
72
+ }
73
+ *last_triggered = Instant::now();
74
+
75
+ if shortcut_hotkey.eq(event) {
76
+ if let Some(window) = app.get_webview_window("pake") {
77
+ let is_visible = window.is_visible().unwrap();
78
+ if is_visible {
79
+ window.hide().unwrap();
80
+ } else {
81
+ window.show().unwrap();
82
+ window.set_focus().unwrap();
83
+ }
84
+ }
85
+ }
86
+ }
87
+ })
88
+ .build(),
89
+ )
90
+ .expect("Failed to set global shortcut");
91
+
92
+ app.global_shortcut().register(shortcut_hotkey).unwrap();
93
+
94
+ Ok(())
95
+ }
@@ -1,11 +1,15 @@
1
1
  use crate::app::config::PakeConfig;
2
+ use crate::util::get_data_dir;
2
3
  use std::{path::PathBuf, str::FromStr};
3
- use tauri::{App, Url, WebviewUrl, WebviewWindow, WebviewWindowBuilder};
4
+ use tauri::{App, Config, Url, WebviewUrl, WebviewWindow, WebviewWindowBuilder};
4
5
 
5
6
  #[cfg(target_os = "macos")]
6
7
  use tauri::{Theme, TitleBarStyle};
7
8
 
8
- pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> WebviewWindow {
9
+ pub fn set_window(app: &mut App, config: &PakeConfig, tauri_config: &Config) -> WebviewWindow {
10
+ let package_name = tauri_config.clone().product_name.unwrap();
11
+ let _data_dir = get_data_dir(app.handle(), package_name);
12
+
9
13
  let window_config = config
10
14
  .windows
11
15
  .first()
@@ -187,7 +187,6 @@ document.addEventListener('DOMContentLoaded', () => {
187
187
  };
188
188
 
189
189
  const detectAnchorElementClick = e => {
190
-
191
190
  const anchorElement = e.target.closest('a');
192
191
 
193
192
  if (anchorElement && anchorElement.href) {
@@ -256,6 +255,38 @@ document.addEventListener('DOMContentLoaded', () => {
256
255
  );
257
256
  });
258
257
 
258
+ document.addEventListener('DOMContentLoaded', function () {
259
+ let permVal = 'granted';
260
+ window.Notification = function (title, options) {
261
+ const { invoke } = window.__TAURI__.core;
262
+ const body = options?.body || '';
263
+ let icon = options?.icon || '';
264
+
265
+ // If the icon is a relative path, convert to full path using URI
266
+ if (icon.startsWith('/')) {
267
+ icon = window.location.origin + icon;
268
+ }
269
+
270
+ invoke('send_notification', {
271
+ params: {
272
+ title,
273
+ body,
274
+ icon,
275
+ },
276
+ });
277
+ };
278
+
279
+ window.Notification.requestPermission = async () => 'granted';
280
+
281
+ Object.defineProperty(window.Notification, 'permission', {
282
+ enumerable: true,
283
+ get: () => permVal,
284
+ set: v => {
285
+ permVal = v;
286
+ },
287
+ });
288
+ });
289
+
259
290
  function setDefaultZoom() {
260
291
  const htmlZoom = window.localStorage.getItem('htmlZoom');
261
292
  if (htmlZoom) {
@@ -295,10 +295,14 @@ window.addEventListener('DOMContentLoaded', _event => {
295
295
  padding-top: 12px;
296
296
  }
297
297
 
298
- #__next header.HeaderBar_header__jn5ju{
298
+ #__next header.HeaderBar_header__jn5ju {
299
299
  padding-top: 16px;
300
300
  }
301
301
 
302
+ #root > .excalidraw-app> .excalidraw-container .App-menu.App-menu_top{
303
+ margin-top: 15px;
304
+ }
305
+
302
306
  .geist-page nav.dashboard_nav__PRmJv,
303
307
  #app > div.layout > div.header-container.showSearchBoxOrHeaderFixed > header > a {
304
308
  padding-top:10px;
@@ -334,11 +338,11 @@ window.addEventListener('DOMContentLoaded', _event => {
334
338
  #__next>div>div>.flex.h-screen.w-full.flex-col.items-center {
335
339
  padding-top: 20px;
336
340
  }
337
-
341
+
338
342
  body > div.relative.flex.h-full.w-full.overflow-hidden.transition-colors.z-0 > div.z-\\[21\\].flex-shrink-0.overflow-x-hidden.bg-token-sidebar-surface-primary.max-md\\:\\!w-0 > div > div > div > nav > div.flex.justify-between.h-\\[60px\\].items-center.md\\:h-header-height {
339
343
  padding-top: 25px;
340
344
  }
341
-
345
+
342
346
  body > div.relative.flex.h-full.w-full.overflow-hidden.transition-colors.z-0 > div.relative.flex.h-full.max-w-full.flex-1.flex-col.overflow-hidden > main > div.composer-parent.flex.h-full.flex-col.focus-visible\\:outline-0 > div.flex-1.overflow-hidden.\\@container\\/thread > div > div.absolute.left-0.right-0 > div{
343
347
  padding-top: 35px;
344
348
  }
@@ -384,10 +388,14 @@ window.addEventListener('DOMContentLoaded', _event => {
384
388
  padding-top:15px;
385
389
  }
386
390
 
391
+ #app-root .mat-mdc-tooltip-trigger.main-menu-button.mdc-icon-button {
392
+ margin-top: 15px;
393
+ }
394
+
387
395
  .lark > .main-wrapper [data-testid="aside"] {
388
396
  top: 15px;
389
397
  }
390
-
398
+
391
399
  #global > div.header-container > .mask-paper {
392
400
  padding-top: 20px;
393
401
  }
@@ -2,120 +2,70 @@
2
2
  mod app;
3
3
  mod util;
4
4
 
5
- use app::{invoke, menu::set_system_tray, window};
6
- use invoke::{download_file, download_file_by_binary};
7
- use std::str::FromStr;
8
- use std::sync::{Arc, Mutex};
9
- use std::time::{Duration, Instant};
10
-
11
5
  use tauri::Manager;
12
- use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
13
- use tauri_plugin_window_state::Builder as windowStatePlugin;
14
- use util::{get_data_dir, get_pake_config};
15
- use window::get_window;
6
+ use tauri_plugin_window_state::Builder as WindowStatePlugin;
7
+ use tauri_plugin_window_state::StateFlags;
8
+
9
+ #[cfg(target_os = "macos")]
10
+ use std::time::Duration;
11
+
12
+ use app::{
13
+ invoke::{download_file, download_file_by_binary, send_notification},
14
+ setup::{set_global_shortcut, set_system_tray},
15
+ window::set_window,
16
+ };
17
+ use util::get_pake_config;
16
18
 
17
19
  pub fn run_app() {
18
20
  let (pake_config, tauri_config) = get_pake_config();
19
-
20
21
  let tauri_app = tauri::Builder::default();
21
22
 
22
23
  let show_system_tray = pake_config.show_system_tray();
23
-
24
- // Save the value of toggle_app_shortcut before pake_config is moved
25
24
  let activation_shortcut = pake_config.windows[0].activation_shortcut.clone();
26
25
  let init_fullscreen = pake_config.windows[0].fullscreen;
27
26
 
28
- let window_state_plugin = if init_fullscreen {
29
- windowStatePlugin::default()
30
- .with_state_flags(tauri_plugin_window_state::StateFlags::FULLSCREEN)
31
- .build()
32
- } else {
33
- windowStatePlugin::default().build()
34
- };
27
+ let window_state_plugin = WindowStatePlugin::default()
28
+ .with_state_flags(if init_fullscreen {
29
+ StateFlags::FULLSCREEN
30
+ } else {
31
+ // Prevent flickering on the first open.
32
+ StateFlags::all() & !StateFlags::VISIBLE
33
+ })
34
+ .build();
35
35
 
36
+ #[allow(deprecated)]
36
37
  tauri_app
37
38
  .plugin(window_state_plugin)
38
39
  .plugin(tauri_plugin_oauth::init())
39
40
  .plugin(tauri_plugin_http::init())
40
41
  .plugin(tauri_plugin_shell::init())
42
+ .plugin(tauri_plugin_notification::init())
41
43
  .plugin(tauri_plugin_single_instance::init(|_, _, _| ()))
42
44
  .invoke_handler(tauri::generate_handler![
43
45
  download_file,
44
- download_file_by_binary
46
+ download_file_by_binary,
47
+ send_notification,
45
48
  ])
46
49
  .setup(move |app| {
47
- let data_dir = get_data_dir(app.app_handle(), tauri_config.clone());
48
-
49
- let _window = get_window(app, &pake_config, data_dir);
50
-
51
- // Prevent initial shaking
52
- _window.show().unwrap();
53
-
54
- if show_system_tray {
55
- let _ = set_system_tray(app.app_handle());
56
- } else {
57
- app.app_handle().remove_tray_by_id("pake-tray");
58
- }
59
-
60
- if !activation_shortcut.is_empty() {
61
- let app_handle = app.app_handle().clone();
62
- let shortcut_hotkey = Shortcut::from_str(activation_shortcut.as_str()).unwrap();
63
- let last_triggered = Arc::new(Mutex::new(Instant::now()));
64
-
65
- app_handle
66
- .plugin(
67
- tauri_plugin_global_shortcut::Builder::new()
68
- .with_handler({
69
- let last_triggered = Arc::clone(&last_triggered);
70
- move |app, event, _shortcut| {
71
- // Fixed the bug of tauri's hidden call, which caused repeated execution
72
- let now = Instant::now();
73
- let mut last = last_triggered.lock().unwrap();
74
- if now.duration_since(*last) < Duration::from_millis(500) {
75
- return;
76
- }
77
- *last = now;
78
-
79
- if shortcut_hotkey.eq(event) {
80
- let window = app.get_webview_window("pake").unwrap();
81
- let is_visible = window.is_visible().unwrap();
82
-
83
- match is_visible {
84
- true => {
85
- window.minimize().unwrap();
86
- }
87
- false => {
88
- window.unminimize().unwrap();
89
- window.set_focus().unwrap();
90
- }
91
- }
92
- }
93
- }
94
- })
95
- .build(),
96
- )
97
- .expect("Error registering global evoke shortcuts!");
98
-
99
- app.global_shortcut().register(shortcut_hotkey)?;
100
- }
101
-
50
+ let window = set_window(app, &pake_config, &tauri_config);
51
+ set_system_tray(app.app_handle(), show_system_tray).unwrap();
52
+ set_global_shortcut(app.app_handle(), activation_shortcut).unwrap();
53
+ // Prevent flickering on the first open.
54
+ window.show().unwrap();
102
55
  Ok(())
103
56
  })
104
57
  .on_window_event(|_window, _event| {
105
58
  #[cfg(target_os = "macos")]
106
59
  if let tauri::WindowEvent::CloseRequested { api, .. } = _event {
107
60
  let window = _window.clone();
108
- {
109
- tauri::async_runtime::spawn(async move {
110
- if window.is_fullscreen().unwrap_or(false) {
111
- window.set_fullscreen(false).unwrap();
112
- // Give a small delay to ensure the full-screen exit operation is completed.
113
- tokio::time::sleep(Duration::from_millis(900)).await;
114
- }
115
- window.minimize().unwrap();
116
- window.hide().unwrap();
117
- });
118
- }
61
+ tauri::async_runtime::spawn(async move {
62
+ if window.is_fullscreen().unwrap_or(false) {
63
+ window.set_fullscreen(false).unwrap();
64
+ tokio::time::sleep(Duration::from_millis(900)).await;
65
+ }
66
+ window.minimize().unwrap();
67
+ window.hide().unwrap();
68
+ });
119
69
  api.prevent_close();
120
70
  }
121
71
  })
@@ -23,9 +23,8 @@ pub fn get_pake_config() -> (PakeConfig, Config) {
23
23
  (pake_config, tauri_config)
24
24
  }
25
25
 
26
- pub fn get_data_dir(app: &AppHandle, _tauri_config: Config) -> PathBuf {
26
+ pub fn get_data_dir(app: &AppHandle, package_name: String) -> PathBuf {
27
27
  {
28
- let package_name = _tauri_config.product_name.unwrap();
29
28
  let data_dir = app
30
29
  .path()
31
30
  .config_dir()
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,36 +0,0 @@
1
- use tauri::{
2
- menu::{MenuBuilder, MenuItemBuilder},
3
- tray::TrayIconBuilder,
4
- AppHandle, Manager,
5
- };
6
- use tauri_plugin_window_state::{AppHandleExt, StateFlags};
7
-
8
- pub fn set_system_tray(app: &AppHandle) -> tauri::Result<()> {
9
- let hide_app = MenuItemBuilder::with_id("hide_app", "Hide").build(app)?;
10
- let show_app = MenuItemBuilder::with_id("show_app", "Show").build(app)?;
11
- let quit = MenuItemBuilder::with_id("quit", "Quit").build(app)?;
12
- let menu = MenuBuilder::new(app)
13
- .items(&[&hide_app, &show_app, &quit])
14
- .build()?;
15
- app.app_handle().remove_tray_by_id("pake-tray");
16
- let tray = TrayIconBuilder::new()
17
- .menu(&menu)
18
- .on_menu_event(move |app, event| match event.id().as_ref() {
19
- "hide_app" => {
20
- app.get_webview_window("pake").unwrap().minimize().unwrap();
21
- }
22
- "show_app" => {
23
- app.get_webview_window("pake").unwrap().show().unwrap();
24
- }
25
- "quit" => {
26
- let _res = app.save_window_state(StateFlags::all());
27
- std::process::exit(0);
28
- }
29
- _ => (),
30
- })
31
- .icon(app.default_window_icon().unwrap().clone())
32
- .build(app)?;
33
-
34
- tray.set_icon_as_template(false)?;
35
- Ok(())
36
- }