pake-cli 2.0.6 → 2.0.7-beta1

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
 
@@ -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();
@@ -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,84 +1,83 @@
1
1
  const shortcuts = {
2
- ArrowUp: () => scrollTo(0, 0),
3
- ArrowDown: () => scrollTo(0, document.body.scrollHeight),
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(),
8
- '[': () => window.history.back(),
9
- ']': () => window.history.forward(),
10
- r: () => window.location.reload(),
11
- '-': () => zoomOut(),
12
- '=': () => zoomIn(),
13
- '+': () => zoomIn(),
14
- 0: () => setZoom('100%'),
2
+ ArrowUp: () => scrollTo(0, 0),
3
+ ArrowDown: () => scrollTo(0, document.body.scrollHeight),
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(),
8
+ '[': () => window.history.back(),
9
+ ']': () => window.history.forward(),
10
+ r: () => window.location.reload(),
11
+ '-': () => zoomOut(),
12
+ '=': () => zoomIn(),
13
+ '+': () => zoomIn(),
14
+ 0: () => setZoom('100%'),
15
15
  };
16
16
 
17
17
  function setZoom(zoom) {
18
- const html = document.getElementsByTagName('html')[0];
19
- html.style.zoom = zoom;
20
- window.localStorage.setItem('htmlZoom', zoom);
18
+ const html = document.getElementsByTagName('html')[0];
19
+ html.style.zoom = zoom;
20
+ window.localStorage.setItem('htmlZoom', zoom);
21
21
  }
22
22
 
23
23
  function zoomCommon(zoomChange) {
24
- const currentZoom = window.localStorage.getItem('htmlZoom') || '100%';
25
- setZoom(zoomChange(currentZoom));
24
+ const currentZoom = window.localStorage.getItem('htmlZoom') || '100%';
25
+ setZoom(zoomChange(currentZoom));
26
26
  }
27
27
 
28
28
  function zoomIn() {
29
- zoomCommon((currentZoom) => `${Math.min(parseInt(currentZoom) + 10, 200)}%`);
29
+ zoomCommon((currentZoom) => `${Math.min(parseInt(currentZoom) + 10, 200)}%`);
30
30
  }
31
31
 
32
32
  function zoomOut() {
33
- zoomCommon((currentZoom) => `${Math.max(parseInt(currentZoom) - 10, 30)}%`);
33
+ zoomCommon((currentZoom) => `${Math.max(parseInt(currentZoom) - 10, 30)}%`);
34
34
  }
35
35
 
36
36
  function handleShortcut(event) {
37
- if (shortcuts[event.key]) {
38
- event.preventDefault();
39
- shortcuts[event.key]();
40
- }
37
+ if (shortcuts[event.key]) {
38
+ event.preventDefault();
39
+ shortcuts[event.key]();
40
+ }
41
41
  }
42
42
 
43
43
  //这里参考 ChatGPT 的代码
44
44
  const uid = () => window.crypto.getRandomValues(new Uint32Array(1))[0];
45
45
 
46
- function transformCallback(callback = () => {
47
- }, once = false) {
48
- const identifier = uid();
49
- const prop = `_${identifier}`;
50
- Object.defineProperty(window, prop, {
51
- value: (result) => {
52
- if (once) {
53
- Reflect.deleteProperty(window, prop);
54
- }
55
- return callback(result);
56
- },
57
- writable: false,
58
- configurable: true,
59
- });
60
- return identifier;
46
+ function transformCallback(callback = () => {}, once = false) {
47
+ const identifier = uid();
48
+ const prop = `_${identifier}`;
49
+ Object.defineProperty(window, prop, {
50
+ value: (result) => {
51
+ if (once) {
52
+ Reflect.deleteProperty(window, prop);
53
+ }
54
+ return callback(result);
55
+ },
56
+ writable: false,
57
+ configurable: true,
58
+ });
59
+ return identifier;
61
60
  }
62
61
 
63
62
  async function invoke(cmd, args) {
64
- return new Promise((resolve, reject) => {
65
- if (!window.__TAURI_POST_MESSAGE__)
66
- reject('__TAURI_POST_MESSAGE__ does not exist~');
67
- const callback = transformCallback((e) => {
68
- resolve(e);
69
- Reflect.deleteProperty(window, `_${error}`);
70
- }, true);
71
- const error = transformCallback((e) => {
72
- reject(e);
73
- Reflect.deleteProperty(window, `_${callback}`);
74
- }, true);
75
- window.__TAURI_POST_MESSAGE__({
76
- cmd,
77
- callback,
78
- error,
79
- ...args,
80
- });
63
+ return new Promise((resolve, reject) => {
64
+ if (!window.__TAURI_POST_MESSAGE__)
65
+ reject('__TAURI_POST_MESSAGE__ does not exist~');
66
+ const callback = transformCallback((e) => {
67
+ resolve(e);
68
+ Reflect.deleteProperty(window, `_${error}`);
69
+ }, true);
70
+ const error = transformCallback((e) => {
71
+ reject(e);
72
+ Reflect.deleteProperty(window, `_${callback}`);
73
+ }, true);
74
+ window.__TAURI_POST_MESSAGE__({
75
+ cmd,
76
+ callback,
77
+ error,
78
+ ...args,
81
79
  });
80
+ });
82
81
  }
83
82
 
84
83
  // Judgment of file download.
@@ -95,130 +94,197 @@ function isDownloadLink(url) {
95
94
 
96
95
  // No need to go to the download link.
97
96
  function externalDownLoadLink() {
98
- return ['quickref.me'].indexOf(location.hostname) > -1;
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;
99
103
  }
100
104
 
101
105
  document.addEventListener('DOMContentLoaded', () => {
102
- const topDom = document.createElement('div');
103
- topDom.id = 'pack-top-dom';
104
- document.body.appendChild(topDom);
105
- const domEl = document.getElementById('pack-top-dom');
106
+ const tauri = window.__TAURI__;
107
+ const appWindow = tauri.window.appWindow;
106
108
 
107
- domEl.addEventListener('mousedown', (e) => {
108
- e.preventDefault();
109
- if (e.buttons === 1 && e.detail !== 2) {
110
- invoke('drag_window');
111
- }
112
- });
109
+ const topDom = document.createElement('div');
110
+ topDom.id = 'pack-top-dom';
111
+ document.body.appendChild(topDom);
112
+ const domEl = document.getElementById('pack-top-dom');
113
113
 
114
- domEl.addEventListener('touchstart', () => {
115
- invoke('drag_window');
116
- });
114
+ domEl.addEventListener('mousedown', (e) => {
115
+ e.preventDefault();
116
+ if (e.buttons === 1 && e.detail !== 2) {
117
+ appWindow.startDragging().then();
118
+ }
119
+ });
117
120
 
118
- domEl.addEventListener('dblclick', () => {
119
- invoke('fullscreen');
120
- });
121
+ domEl.addEventListener('touchstart', () => {
122
+ appWindow.startDragging().then();
123
+ });
121
124
 
122
- document.addEventListener('keyup', (event) => {
123
- if (/windows|linux/i.test(navigator.userAgent) && event.ctrlKey) {
124
- handleShortcut(event);
125
- }
126
- if (/macintosh|mac os x/i.test(navigator.userAgent) && event.metaKey) {
127
- handleShortcut(event);
128
- }
125
+ domEl.addEventListener('dblclick', () => {
126
+ appWindow.isFullscreen().then((fullscreen) => {
127
+ appWindow.setFullscreen(!fullscreen).then();
129
128
  });
129
+ });
130
130
 
131
- // Prevent some special websites from executing in advance, before the click event is triggered.
132
- document.addEventListener('mousedown', (e) => {
133
- const anchorElement = e.target.closest('a');
134
-
135
- if (anchorElement && anchorElement.href) {
136
- const target = anchorElement.target;
137
- anchorElement.target = '_self';
138
- const hrefUrl = new URL(anchorElement.href);
139
- const absoluteUrl = hrefUrl.href;
140
-
141
- // Handling external link redirection.
142
- if (
143
- window.location.host !== hrefUrl.host &&
144
- (target === '_blank' || target === '_new')
145
- ) {
146
- e.preventDefault();
147
- invoke('open_browser', {url: absoluteUrl});
148
- return;
149
- }
150
-
151
- let filename = anchorElement.download ? anchorElement.download : getFilenameFromUrl(absoluteUrl)
152
- // Process download links for Rust to handle.
153
- // If the download attribute is set, the download attribute is used as the file name.
154
- if ((anchorElement.download || e.metaKey || e.ctrlKey || isDownloadLink(absoluteUrl))
155
- && !externalDownLoadLink()
156
- ) {
157
- e.preventDefault();
158
- invoke('download_file', {
159
- params: {
160
- url: absoluteUrl,
161
- filename,
162
- },
163
- });
164
- }
165
- }
166
- });
131
+ document.addEventListener('keyup', (event) => {
132
+ if (/windows|linux/i.test(navigator.userAgent) && event.ctrlKey) {
133
+ handleShortcut(event);
134
+ }
135
+ if (/macintosh|mac os x/i.test(navigator.userAgent) && event.metaKey) {
136
+ handleShortcut(event);
137
+ }
138
+ });
167
139
 
168
- // Rewrite the window.open function.
169
- const originalWindowOpen = window.open;
170
- window.open = function (url, name, specs) {
171
- // Apple login and google login
172
- if (name === 'AppleAuthentication') {
173
- //do nothing
174
- } else if (specs.includes('height=') || specs.includes('width=')) {
175
- location.href = url;
176
- } else {
177
- const baseUrl = window.location.origin + window.location.pathname;
178
- const hrefUrl = new URL(url, baseUrl);
179
- invoke('open_browser', {url: hrefUrl.href});
180
- }
181
- // Call the original window.open function to maintain its normal functionality.
182
- return originalWindowOpen.call(window, url, name, specs);
183
- };
140
+ const detectAnchorElementClick = (e) => {
141
+ const anchorElement = e.target.closest('a');
142
+ if (anchorElement && anchorElement.href) {
143
+ const target = anchorElement.target;
144
+ anchorElement.target = '_self';
145
+ const hrefUrl = new URL(anchorElement.href);
146
+ const absoluteUrl = hrefUrl.href;
147
+
148
+ // Handling external link redirection.
149
+ if (
150
+ window.location.host !== hrefUrl.host &&
151
+ (target === '_blank' || target === '_new' || externalTargetLink())
152
+ ) {
153
+ e.preventDefault && e.preventDefault();
154
+ tauri.shell.open(absoluteUrl);
155
+ return;
156
+ }
184
157
 
185
- // Set the default zoom, There are problems with Loop without using try-catch.
186
- try {
187
- setDefaultZoom();
188
- } catch (e) {
189
- console.log(e);
158
+ let filename = anchorElement.download || getFilenameFromUrl(absoluteUrl);
159
+ // Process download links for Rust to handle.
160
+ // If the download attribute is set, the download attribute is used as the file name.
161
+ if (
162
+ (anchorElement.download ||
163
+ e.metaKey ||
164
+ e.ctrlKey ||
165
+ isDownloadLink(absoluteUrl)) &&
166
+ !externalDownLoadLink()
167
+ ) {
168
+ e.preventDefault();
169
+ invoke('download_file', {
170
+ params: {
171
+ url: absoluteUrl,
172
+ filename,
173
+ },
174
+ });
175
+ }
176
+ }
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();
184
+
185
+ // Rewrite the window.open function.
186
+ const originalWindowOpen = window.open;
187
+ window.open = function (url, name, specs) {
188
+ // Apple login and google login
189
+ if (name === 'AppleAuthentication') {
190
+ //do nothing
191
+ } else if (specs.includes('height=') || specs.includes('width=')) {
192
+ location.href = url;
193
+ } else {
194
+ const baseUrl = window.location.origin + window.location.pathname;
195
+ const hrefUrl = new URL(url, baseUrl);
196
+ tauri.shell.open(hrefUrl.href);
190
197
  }
198
+ // Call the original window.open function to maintain its normal functionality.
199
+ return originalWindowOpen.call(window, url, name, specs);
200
+ };
201
+
202
+ // Set the default zoom, There are problems with Loop without using try-catch.
203
+ try {
204
+ setDefaultZoom();
205
+ } catch (e) {
206
+ console.log(e);
207
+ }
191
208
  });
192
209
 
193
210
  function setDefaultZoom() {
194
- const htmlZoom = window.localStorage.getItem('htmlZoom');
195
- if (htmlZoom) {
196
- setZoom(htmlZoom);
197
- }
211
+ const htmlZoom = window.localStorage.getItem('htmlZoom');
212
+ if (htmlZoom) {
213
+ setZoom(htmlZoom);
214
+ }
198
215
  }
199
216
 
200
217
  function getFilenameFromUrl(url) {
201
- const urlPath = new URL(url).pathname;
202
- const filename = urlPath.substring(urlPath.lastIndexOf('/') + 1);
203
- return filename;
218
+ const urlPath = new URL(url).pathname;
219
+ const filename = urlPath.substring(urlPath.lastIndexOf('/') + 1);
220
+ return filename;
204
221
  }
205
222
 
206
223
  function removeUrlParameters(url) {
207
- const parsedUrl = new URL(url);
208
- parsedUrl.search = '';
209
- return parsedUrl.toString();
224
+ const parsedUrl = new URL(url);
225
+ parsedUrl.search = '';
226
+ return parsedUrl.toString();
210
227
  }
211
228
 
212
-
213
229
  // Toggle video playback when the window is hidden.
214
230
  function toggleVideoPlayback(pause) {
215
- const videos = document.getElementsByTagName('video');
216
- for (const video of videos) {
217
- if (pause) {
218
- video.pause();
219
- } else {
220
- video.play();
221
- }
231
+ const videos = document.getElementsByTagName('video');
232
+ for (const video of videos) {
233
+ if (pause) {
234
+ video.pause();
235
+ } else {
236
+ video.play();
222
237
  }
238
+ }
223
239
  }
224
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;
@@ -60,8 +72,8 @@ window.addEventListener('DOMContentLoaded', (_event) => {
60
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{
61
73
  margin-top:20px;
62
74
  margin-left: 10px;
63
- }
64
-
75
+ }
76
+
65
77
  .chakra-ui-light #app .chakra-heading,
66
78
  .chakra-ui-dark #app .chakra-heading,
67
79
  .chakra-ui-light #app .chakra-stack,
@@ -304,7 +316,8 @@ window.addEventListener('DOMContentLoaded', (_event) => {
304
316
  }
305
317
 
306
318
  @media (min-width:1024px){
307
- #__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\\] {
308
321
  max-width: 44rem;
309
322
  }
310
323
  }
@@ -319,6 +332,20 @@ window.addEventListener('DOMContentLoaded', (_event) => {
319
332
  #__next .overflow-hidden.w-full .max-w-full>.sticky.top-0 {
320
333
  padding-top: 20px;
321
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
+ }
322
349
  }
323
350
 
324
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": {