pake-cli 2.0.5 → 2.0.7-beta

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.
@@ -12,12 +12,12 @@ rust-version = "1.63.0"
12
12
  # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13
13
 
14
14
  [build-dependencies]
15
- tauri-build = { version = "1.2.1", features = [] }
15
+ tauri-build = { version = "1.4.0", features = [] }
16
16
 
17
17
  [dependencies]
18
- serde_json = "1.0.89"
19
- serde = { version = "1.0.150", features = ["derive"] }
20
- tauri = { version = "1.2.4", features = ["api-all", "system-tray"] }
18
+ serde_json = "1.0.96"
19
+ serde = { version = "1.0.163", features = ["derive"] }
20
+ tauri = { version = "1.4.0", features = ["api-all", "system-tray"] }
21
21
  download_rs = { version = "0.2.0", features = ["sync_download"] }
22
22
  tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
23
23
 
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -8,26 +8,6 @@ pub struct DownloadFileParams {
8
8
  filename: String,
9
9
  }
10
10
 
11
- #[command]
12
- pub fn drag_window(app: AppHandle) {
13
- app.get_window("pake").unwrap().start_dragging().unwrap();
14
- }
15
-
16
- #[command]
17
- pub fn fullscreen(app: AppHandle) {
18
- let win = app.get_window("pake").unwrap();
19
- if win.is_fullscreen().unwrap() {
20
- win.set_fullscreen(false).unwrap();
21
- } else {
22
- win.set_fullscreen(true).unwrap();
23
- }
24
- }
25
-
26
- #[command]
27
- pub fn open_browser(app: AppHandle, url: String) {
28
- api::shell::open(&app.shell_scope(), url, None).unwrap();
29
- }
30
-
31
11
  #[command]
32
12
  pub async fn download_file(app: AppHandle, params: DownloadFileParams) -> Result<(), String> {
33
13
  let window: Window = app.get_window("pake").unwrap();
@@ -26,6 +26,7 @@ pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> Wind
26
26
  .resizable(window_config.resizable)
27
27
  .fullscreen(window_config.fullscreen)
28
28
  .inner_size(window_config.width, window_config.height)
29
+ .disable_file_drop_handler() //Very annoying, otherwise dragging files to the window will not work.
29
30
  .initialization_script(include_str!("../inject/style.js"))
30
31
  .initialization_script(include_str!("../inject/event.js"))
31
32
  .initialization_script(include_str!("../inject/component.js"));
@@ -75,6 +75,12 @@ document.addEventListener('DOMContentLoaded', () => {
75
75
  background: #fff;
76
76
  color: #11182B;
77
77
  }
78
+
79
+ #pakeUrlInput {
80
+ min-width: 320px;
81
+ text-align: left;
82
+ min-height: 30px;
83
+ }
78
84
  `;
79
85
 
80
86
  const modalDiv = document.createElement('div');
@@ -1,8 +1,10 @@
1
1
  const shortcuts = {
2
2
  ArrowUp: () => scrollTo(0, 0),
3
3
  ArrowDown: () => scrollTo(0, document.body.scrollHeight),
4
- ArrowLeft: () => window.history.back(),
5
- ArrowRight: () => window.history.forward(),
4
+ // Don't use command + ArrowLeft or command + ArrowRight
5
+ // When editing text in page, it causes unintended page navigation.
6
+ // ArrowLeft: () => window.history.back(),
7
+ // ArrowRight: () => window.history.forward(),
6
8
  '[': () => window.history.back(),
7
9
  ']': () => window.history.forward(),
8
10
  r: () => window.location.reload(),
@@ -40,6 +42,7 @@ function handleShortcut(event) {
40
42
 
41
43
  //这里参考 ChatGPT 的代码
42
44
  const uid = () => window.crypto.getRandomValues(new Uint32Array(1))[0];
45
+
43
46
  function transformCallback(callback = () => {}, once = false) {
44
47
  const identifier = uid();
45
48
  const prop = `_${identifier}`;
@@ -55,6 +58,7 @@ function transformCallback(callback = () => {}, once = false) {
55
58
  });
56
59
  return identifier;
57
60
  }
61
+
58
62
  async function invoke(cmd, args) {
59
63
  return new Promise((resolve, reject) => {
60
64
  if (!window.__TAURI_POST_MESSAGE__)
@@ -76,7 +80,32 @@ async function invoke(cmd, args) {
76
80
  });
77
81
  }
78
82
 
83
+ // Judgment of file download.
84
+ function isDownloadLink(url) {
85
+ const fileExtensions = [
86
+ '3gp', '7z', 'ai', 'apk', 'avi', 'bmp', 'csv', 'dmg', 'doc', 'docx', 'fla', 'flv', 'gif', 'gz', 'gzip',
87
+ 'ico', 'iso', 'indd', 'jar', 'jpeg', 'jpg', 'm3u8', 'mov', 'mp3', 'mp4', 'mpa', 'mpg',
88
+ 'mpeg', 'msi', 'odt', 'ogg', 'ogv', 'pdf', 'png', 'ppt', 'pptx', 'psd', 'rar', 'raw', 'rss', 'svg',
89
+ 'swf', 'tar', 'tif', 'tiff', 'ts', 'txt', 'wav', 'webm', 'webp', 'wma', 'wmv', 'xls', 'xlsx', 'xml', 'zip'
90
+ ];
91
+ const downloadLinkPattern = new RegExp(`\\.(${fileExtensions.join('|')})$`, 'i');
92
+ return downloadLinkPattern.test(url);
93
+ }
94
+
95
+ // No need to go to the download link.
96
+ function externalDownLoadLink() {
97
+ return ['quickref.me'].indexOf(location.hostname) > -1;
98
+ }
99
+
100
+ // Directly jumping out without hostname address.
101
+ function externalTargetLink() {
102
+ return ['zbook.lol'].indexOf(location.hostname) > -1;
103
+ }
104
+
79
105
  document.addEventListener('DOMContentLoaded', () => {
106
+ const tauri = window.__TAURI__;
107
+ const appWindow = tauri.window.appWindow;
108
+
80
109
  const topDom = document.createElement('div');
81
110
  topDom.id = 'pack-top-dom';
82
111
  document.body.appendChild(topDom);
@@ -85,16 +114,18 @@ document.addEventListener('DOMContentLoaded', () => {
85
114
  domEl.addEventListener('mousedown', (e) => {
86
115
  e.preventDefault();
87
116
  if (e.buttons === 1 && e.detail !== 2) {
88
- invoke('drag_window');
117
+ appWindow.startDragging().then();
89
118
  }
90
119
  });
91
120
 
92
121
  domEl.addEventListener('touchstart', () => {
93
- invoke('drag_window');
122
+ appWindow.startDragging().then();
94
123
  });
95
124
 
96
125
  domEl.addEventListener('dblclick', () => {
97
- invoke('fullscreen');
126
+ appWindow.isFullscreen().then((fullscreen) => {
127
+ appWindow.setFullscreen(!fullscreen).then();
128
+ });
98
129
  });
99
130
 
100
131
  document.addEventListener('keyup', (event) => {
@@ -106,9 +137,8 @@ document.addEventListener('DOMContentLoaded', () => {
106
137
  }
107
138
  });
108
139
 
109
- document.addEventListener('click', (e) => {
140
+ const detectAnchorElementClick = (e) => {
110
141
  const anchorElement = e.target.closest('a');
111
-
112
142
  if (anchorElement && anchorElement.href) {
113
143
  const target = anchorElement.target;
114
144
  anchorElement.target = '_self';
@@ -118,28 +148,39 @@ document.addEventListener('DOMContentLoaded', () => {
118
148
  // Handling external link redirection.
119
149
  if (
120
150
  window.location.host !== hrefUrl.host &&
121
- (target === '_blank' || target === '_new')
151
+ (target === '_blank' || target === '_new' || externalTargetLink())
122
152
  ) {
123
- e.preventDefault();
124
- invoke('open_browser', { url: absoluteUrl });
153
+ e.preventDefault && e.preventDefault();
154
+ tauri.shell.open(absoluteUrl);
125
155
  return;
126
156
  }
127
157
 
158
+ let filename = anchorElement.download || getFilenameFromUrl(absoluteUrl);
128
159
  // Process download links for Rust to handle.
160
+ // If the download attribute is set, the download attribute is used as the file name.
129
161
  if (
130
- /\.[a-zA-Z0-9]+$/i.test(removeUrlParameters(absoluteUrl)) &&
162
+ (anchorElement.download ||
163
+ e.metaKey ||
164
+ e.ctrlKey ||
165
+ isDownloadLink(absoluteUrl)) &&
131
166
  !externalDownLoadLink()
132
167
  ) {
133
168
  e.preventDefault();
134
169
  invoke('download_file', {
135
170
  params: {
136
171
  url: absoluteUrl,
137
- filename: getFilenameFromUrl(absoluteUrl),
172
+ filename,
138
173
  },
139
174
  });
140
175
  }
141
176
  }
142
- });
177
+ };
178
+
179
+ // Prevent some special websites from executing in advance, before the click event is triggered.
180
+ document.addEventListener('click', detectAnchorElementClick, true);
181
+
182
+ collectUrlToBlobs();
183
+ detectDownloadByCreateAnchor();
143
184
 
144
185
  // Rewrite the window.open function.
145
186
  const originalWindowOpen = window.open;
@@ -152,7 +193,7 @@ document.addEventListener('DOMContentLoaded', () => {
152
193
  } else {
153
194
  const baseUrl = window.location.origin + window.location.pathname;
154
195
  const hrefUrl = new URL(url, baseUrl);
155
- invoke('open_browser', { url: hrefUrl.href });
196
+ tauri.shell.open(hrefUrl.href);
156
197
  }
157
198
  // Call the original window.open function to maintain its normal functionality.
158
199
  return originalWindowOpen.call(window, url, name, specs);
@@ -185,11 +226,6 @@ function removeUrlParameters(url) {
185
226
  return parsedUrl.toString();
186
227
  }
187
228
 
188
- // No need to go to the download link.
189
- function externalDownLoadLink() {
190
- return ['quickref.me'].indexOf(location.hostname) > -1;
191
- }
192
-
193
229
  // Toggle video playback when the window is hidden.
194
230
  function toggleVideoPlayback(pause) {
195
231
  const videos = document.getElementsByTagName('video');
@@ -202,3 +238,53 @@ function toggleVideoPlayback(pause) {
202
238
  }
203
239
  }
204
240
 
241
+ // Collect blob urls to blob by overriding window.URL.createObjectURL
242
+ function collectUrlToBlobs() {
243
+ const backupCreateObjectURL = window.URL.createObjectURL;
244
+ window.blobToUrlCaches = new Map();
245
+ window.URL.createObjectURL = (blob) => {
246
+ const url = backupCreateObjectURL.call(window.URL, blob);
247
+ window.blobToUrlCaches.set(url, blob);
248
+ return url;
249
+ };
250
+ }
251
+
252
+ function convertBlobUrlToBinary(blobUrl) {
253
+ return new Promise((resolve) => {
254
+ const blob = window.blobToUrlCaches.get(blobUrl);
255
+ const reader = new FileReader();
256
+
257
+ reader.readAsArrayBuffer(blob);
258
+ reader.onload = () => {
259
+ resolve(reader.result);
260
+ };
261
+ });
262
+ }
263
+
264
+ // detect blob download by createElement("a")
265
+ function detectDownloadByCreateAnchor() {
266
+ const createEle = document.createElement;
267
+ document.createElement = (el) => {
268
+ if (el !== "a") return createEle.call(document, el);
269
+ const anchorEle = createEle.call(document, el);
270
+ const anchorClick = anchorEle.click;
271
+
272
+ Object.defineProperties(anchorEle, {
273
+ click: {
274
+ get: () => {
275
+ if (anchorEle.href && anchorEle.href.includes('blob:')) {
276
+ const url = anchorEle.href;
277
+ convertBlobUrlToBinary(url).then((binary) => {
278
+ tauri.fs.writeBinaryFile(anchorEle.download || getFilenameFromUrl(url), binary, {
279
+ dir: tauri.fs.BaseDirectory.Download,
280
+ });
281
+ });
282
+ }
283
+ return anchorClick.bind(anchorEle);
284
+ }
285
+ }
286
+ })
287
+
288
+ return anchorEle;
289
+ }
290
+ }
@@ -41,6 +41,14 @@ window.addEventListener('DOMContentLoaded', (_event) => {
41
41
  display: none !important;
42
42
  }
43
43
 
44
+ #__next header.HeaderBar_header__jn5ju{
45
+ padding-top: 16px;
46
+ }
47
+
48
+ #__next .ChatPageSidebar_menuFooter__E1KTY,#__next > div.PageWithSidebarLayout_centeringDiv___L9br > div > aside > div > menu > section:nth-child(6) {
49
+ display: none;
50
+ }
51
+
44
52
  #page .main_header, .cb-layout-basic--navbar,
45
53
  #app .splitpanes.splitpanes--horizontal.no-splitter header,
46
54
  .fui-FluentProvider .fui-Button[data-testid="HomeButton"],
@@ -48,6 +56,10 @@ window.addEventListener('DOMContentLoaded', (_event) => {
48
56
  padding-top: 20px;
49
57
  }
50
58
 
59
+ #__next > div.overflow-hidden.w-full.h-full .min-h-\\[20px\\].items-start.gap-4.whitespace-pre-wrap.break-words {
60
+ word-break: break-all;
61
+ }
62
+
51
63
  #__next .PageWithSidebarLayout_mainSection__i1yOg {
52
64
  width: 100%;
53
65
  max-width: 1000px;
@@ -57,6 +69,11 @@ window.addEventListener('DOMContentLoaded', (_event) => {
57
69
  min-width: 260px;
58
70
  }
59
71
 
72
+ #__next > div.overflow-hidden.w-full.h-full.relative.flex.z-0 > div.relative.flex.h-full.max-w-full.flex-1.overflow-hidden > div > main > div.absolute.left-2.top-2.z-10.hidden.md\\:inline-block{
73
+ margin-top:20px;
74
+ margin-left: 10px;
75
+ }
76
+
60
77
  .chakra-ui-light #app .chakra-heading,
61
78
  .chakra-ui-dark #app .chakra-heading,
62
79
  .chakra-ui-light #app .chakra-stack,
@@ -84,6 +101,19 @@ window.addEventListener('DOMContentLoaded', (_event) => {
84
101
  width: 100%;
85
102
  }
86
103
 
104
+ #tabs-sidebar--tabpanel-0 > div.tw-flex.tw-items-center.tw-mb-\\[12px\\].tw-mt-\\[14px\\].tw-px-4 {
105
+ padding-top: 15px;
106
+ }
107
+
108
+ #tabs-sidebar--tabpanel-1 > div > div.tw-p-\\[16px\\].tw-flex.tw-flex-col.tw-gap-1\\.5{
109
+ padding-top: 30px;
110
+ }
111
+
112
+ #tabs-sidebar--tabpanel-2 > div > h2 {
113
+ padding-top: 20px;
114
+ height: 70px;
115
+ }
116
+
87
117
  .lark > .dashboard-sidebar, .lark > .dashboard-sidebar > .sidebar-user-info , .lark > .dashboard-sidebar .index-module_wrapper_F-Wbq{
88
118
  padding-top:15px;
89
119
  }
@@ -135,10 +165,12 @@ window.addEventListener('DOMContentLoaded', (_event) => {
135
165
  margin-top:24px;
136
166
  }
137
167
 
168
+
138
169
  #react-root [data-testid="placementTracking"] article,
139
170
  #react-root a[href*="quick_promote_web"],
140
171
  #react-root [data-testid="AppTabBar_Explore_Link"],
141
172
  #react-root a[href*="/lists"][role="link"][aria-label],
173
+ #react-root a[href*="/i/communitynotes"][role="link"][aria-label],
142
174
  #react-root a[href*="/i/verified-orgs-signup"][role="link"][aria-label] {
143
175
  display: none !important;
144
176
  }
@@ -284,7 +316,8 @@ window.addEventListener('DOMContentLoaded', (_event) => {
284
316
  }
285
317
 
286
318
  @media (min-width:1024px){
287
- #__next .text-base.lg\\:max-w-xl, #__next form.stretch.lg\\:max-w-2xl {
319
+ #__next .text-base.lg\\:max-w-xl, #__next form.stretch.lg\\:max-w-2xl,
320
+ #__next > .w-full.h-full .lg\\:max-w-\\[38rem\\] {
288
321
  max-width: 44rem;
289
322
  }
290
323
  }
@@ -299,6 +332,20 @@ window.addEventListener('DOMContentLoaded', (_event) => {
299
332
  #__next .overflow-hidden.w-full .max-w-full>.sticky.top-0 {
300
333
  padding-top: 20px;
301
334
  }
335
+
336
+ #__next .overflow-hidden.w-full main.relative.h-full.w-full.flex-1{
337
+ padding-bottom: 82px;
338
+ }
339
+
340
+ #__next > div.overflow-hidden.w-full.h-full main.relative.h-full.w-full.flex-1 > .flex-1.overflow-hidden .h-32.md\\:h-48.flex-shrink-0{
341
+ height: 0px;
342
+ }
343
+ }
344
+
345
+ @media (max-width:565px){
346
+ #__next .overflow-hidden.w-full main.relative.h-full.w-full.flex-1{
347
+ padding-bottom: 98px;
348
+ }
302
349
  }
303
350
 
304
351
  #__next .prose ol li p {
@@ -7,7 +7,7 @@ mod app;
7
7
  mod util;
8
8
 
9
9
  use app::{invoke, menu, window};
10
- use invoke::{download_file, drag_window, fullscreen, open_browser};
10
+ use invoke::download_file;
11
11
  use menu::{get_menu, menu_event_handle};
12
12
  use tauri_plugin_window_state::Builder as windowStatePlugin;
13
13
  use util::{get_data_dir, get_pake_config};
@@ -41,12 +41,7 @@ pub fn run_app() {
41
41
 
42
42
  tauri_app
43
43
  .plugin(windowStatePlugin::default().build())
44
- .invoke_handler(tauri::generate_handler![
45
- drag_window,
46
- fullscreen,
47
- open_browser,
48
- download_file
49
- ])
44
+ .invoke_handler(tauri::generate_handler![download_file])
50
45
  .setup(|app| {
51
46
  let _window = get_window(app, pake_config, data_dir);
52
47
  // Prevent initial shaking
@@ -5,7 +5,16 @@
5
5
  },
6
6
  "tauri": {
7
7
  "security": {
8
- "csp": null
8
+ "csp": null,
9
+ "dangerousRemoteDomainIpcAccess": [
10
+ {
11
+ "domain": "weread.qq.com",
12
+ "windows": [
13
+ "pake"
14
+ ],
15
+ "enableTauriAPI": true
16
+ }
17
+ ]
9
18
  },
10
19
  "updater": {
11
20
  "active": false
@@ -15,7 +24,13 @@
15
24
  "iconAsTemplate": true
16
25
  },
17
26
  "allowlist": {
18
- "all": true
27
+ "all": true,
28
+ "fs": {
29
+ "all": true,
30
+ "scope": [
31
+ "$DOWNLOAD/*"
32
+ ]
33
+ }
19
34
  }
20
35
  },
21
36
  "build": {