Skip to content

Commit 3f5454b

Browse files
committed
✨ 2.0 invoke compatible
1 parent 4ecfd65 commit 3f5454b

File tree

7 files changed

+104
-21
lines changed

7 files changed

+104
-21
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,3 @@ src-tauri/.cargo/
3939
.next
4040
src-tauri/.pake/
4141
src-tauri/gen
42-
src-tauri/capabilities

src-tauri/Cargo.lock

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ tauri-plugin-clipboard-manager = "2.0.2"
2727
tauri-plugin-http = "2.0.3"
2828
[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
2929
tauri-plugin-global-shortcut = { version = "2.0.1" }
30+
tauri-plugin-shell = "2.0.0"
3031

3132
[dev-dependencies]
3233
cargo-bloat = "0.12.1"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "../gen/schemas/desktop-schema.json",
3+
"identifier": "pake-capability",
4+
"description": "Capability for the pake app.",
5+
"webviews": ["pake"],
6+
"remote": {
7+
"urls": ["https://*.*"]
8+
},
9+
"permissions": [
10+
"core:window:allow-theme",
11+
"core:window:allow-start-dragging",
12+
"core:window:allow-toggle-maximize",
13+
"core:window:allow-is-fullscreen",
14+
"core:window:allow-set-fullscreen",
15+
"core:webview:allow-internal-toggle-devtools",
16+
"shell:allow-open"
17+
]
18+
}

src-tauri/src/app/invoke.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::io::Write;
44
use std::str::FromStr;
55
use tauri::http::Method;
66
use tauri_plugin_http::reqwest::{ClientBuilder, Request};
7-
// use tauri::http::{ClientBuilder, HttpRequestBuilder, ResponseType};
87
use tauri::{command, AppHandle, Manager, Url, WebviewWindow};
98

109
#[derive(serde::Deserialize)]

src-tauri/src/inject/event.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function isDownloadLink(url) {
4343
'3gp', '7z', 'ai', 'apk', 'avi', 'bmp', 'csv', 'dmg', 'doc', 'docx',
4444
'fla', 'flv', 'gif', 'gz', 'gzip', 'ico', 'iso', 'indd', 'jar', 'jpeg',
4545
'jpg', 'm3u8', 'mov', 'mp3', 'mp4', 'mpa', 'mpg', 'mpeg', 'msi', 'odt',
46-
'ogg', 'ogv', 'pdf', 'png', 'ppt', 'pptx', 'psd', 'rar', 'raw', 'rss',
46+
'ogg', 'ogv', 'pdf', 'png', 'ppt', 'pptx', 'psd', 'rar', 'raw',
4747
'svg', 'swf', 'tar', 'tif', 'tiff', 'ts', 'txt', 'wav', 'webm', 'webp',
4848
'wma', 'wmv', 'xls', 'xlsx', 'xml', 'zip', 'json', 'yaml', '7zip', 'mkv'
4949
];
@@ -56,15 +56,11 @@ function externalDownLoadLink() {
5656
return ['quickref.me'].indexOf(location.hostname) > -1;
5757
}
5858

59-
// Directly jumping out without hostname address.
60-
function externalTargetLink() {
61-
return ['zbook.lol'].indexOf(location.hostname) > -1;
62-
}
6359

6460
document.addEventListener('DOMContentLoaded', () => {
6561
const tauri = window.__TAURI__;
66-
const appWindow = tauri.window.appWindow;
67-
const invoke = tauri.tauri.invoke;
62+
const appWindow = tauri.window.getCurrentWindow();
63+
const invoke = tauri.core.invoke;
6864

6965
if (!document.getElementById('pake-top-dom')) {
7066
const topDom = document.createElement('div');
@@ -75,19 +71,19 @@ document.addEventListener('DOMContentLoaded', () => {
7571
const domEl = document.getElementById('pake-top-dom');
7672

7773
domEl.addEventListener('touchstart', () => {
78-
appWindow.startDragging().then();
74+
appWindow.startDragging();
7975
});
8076

8177
domEl.addEventListener('mousedown', e => {
8278
e.preventDefault();
8379
if (e.buttons === 1 && e.detail !== 2) {
84-
appWindow.startDragging().then();
80+
appWindow.startDragging();
8581
}
8682
});
8783

8884
domEl.addEventListener('dblclick', () => {
8985
appWindow.isFullscreen().then(fullscreen => {
90-
appWindow.setFullscreen(!fullscreen).then();
86+
appWindow.setFullscreen(!fullscreen);
9187
});
9288
});
9389

@@ -176,8 +172,6 @@ document.addEventListener('DOMContentLoaded', () => {
176172
// case: download from dataURL -> convert dataURL ->
177173
} else if (url.startsWith('data:')) {
178174
downloadFromDataUri(url, filename);
179-
} else if (isDownloadLink(url) || anchorEle.host !== window.location.host) {
180-
handleExternalLink(e, url);
181175
}
182176
},
183177
true,
@@ -187,7 +181,6 @@ document.addEventListener('DOMContentLoaded', () => {
187181
};
188182
}
189183

190-
const isExternalLink = link => window.location.host !== link.host;
191184
// process special download protocol['data:','blob:']
192185
const isSpecialDownload = url => ['blob', 'data'].some(protocol => url.startsWith(protocol));
193186

@@ -214,12 +207,6 @@ document.addEventListener('DOMContentLoaded', () => {
214207
const absoluteUrl = hrefUrl.href;
215208
let filename = anchorElement.download || getFilenameFromUrl(absoluteUrl);
216209

217-
// Handling external link redirection.
218-
if ((isExternalLink(absoluteUrl) && ['_blank', '_new'].includes(anchorElement.target)) || externalTargetLink()) {
219-
handleExternalLink(e, absoluteUrl);
220-
return;
221-
}
222-
223210
// Process download links for Rust to handle.
224211
if (isDownloadRequired(absoluteUrl, anchorElement, e) && !externalDownLoadLink() && !isSpecialDownload(absoluteUrl)) {
225212
handleDownloadLink(e, absoluteUrl, filename);

src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn run_app() {
2626
.plugin(windowStatePlugin::default().build())
2727
.plugin(tauri_plugin_oauth::init())
2828
.plugin(tauri_plugin_http::init())
29+
.plugin(tauri_plugin_shell::init())
2930
.invoke_handler(tauri::generate_handler![
3031
download_file,
3132
download_file_by_binary

0 commit comments

Comments
 (0)