Skip to content

Commit

Permalink
Fix fetch (#2)
Browse files Browse the repository at this point in the history
* upgrade all dep

* fix: fetch API body fetching
  • Loading branch information
HuakunShen authored Nov 18, 2024
1 parent 5f9635d commit 36d3229
Show file tree
Hide file tree
Showing 9 changed files with 1,283 additions and 770 deletions.
1,010 changes: 616 additions & 394 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ edition = "2021"
tauri-build = { version = "2.0.0-rc", features = ["isolation"] }

[dependencies]
tauri = { version = "2.0.0-rc", features = ["isolation", "devtools"] }
tauri = { version = "2.1.1", features = ["isolation", "devtools"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-clipboard = "2.1.8"
tauri-plugin-shellx = "2.0.10"
tauri-plugin-fs = "2.0.0-rc"
tauri-plugin-dialog = "2.0.0-rc"
tauri-plugin-notification = "2.0.0-rc"
tauri-plugin-os = "2.0.0-rc"
tauri-plugin-http = "2.0.0-rc"
tauri-plugin-network = "2.0.2"
tauri-plugin-system-info = "2.0.2"
tauri-plugin-log = "2.0.0-rc"
tauri-plugin-upload = "2.0.0-rc"
tauri-plugin-clipboard = "2.1.11"
tauri-plugin-shellx = "2.0.12"
tauri-plugin-fs = "2.0.3"
tauri-plugin-dialog = "2.0.3"
tauri-plugin-notification = "2.0.1"
tauri-plugin-os = "2.0.1"
tauri-plugin-http = "2.0.3"
tauri-plugin-network = "2.0.4"
tauri-plugin-system-info = "2.0.8"
tauri-plugin-log = "2.0.2"
tauri-plugin-upload = "2.1.0"
7 changes: 6 additions & 1 deletion apps/desktop/src/lib/sample-worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clipboard, dialog, shell } from 'tauri-api-adapter/worker'
import { clipboard, dialog, fetch, shell } from 'tauri-api-adapter/worker'

clipboard.readText().then((text) => {
console.log('From Worker: ', text)
Expand All @@ -10,3 +10,8 @@ shell.executeBashScript('echo "Hello from Worker"').then(console.log)
// dialog.confirm('Are you sure?').then((response) => {
// console.log('From Worker: ', response)
// })
fetch('https://ifconfig.co/country')
.then((res) => res.text())
.then((data) => {
console.log('In Web Worker fetch ip country: ', data)
})
4 changes: 3 additions & 1 deletion apps/extension/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
})
fetch('https://ifconfig.co/country')
.then((res) => res.text())
.then(console.log)
.then((data) => {
console.log('In Iframe Extension fetch ip country: ', data)
})
// console.log(await os.platform())
// console.log(await path.desktopDir())
// console.log(path.BaseDirectory)
Expand Down
2 changes: 1 addition & 1 deletion packages/tauri-api-adapter/jsr.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://jsr.io/schema/config-file.v1.json",
"name": "@hk/tauri-api-adapter",
"version": "0.3.11",
"version": "0.3.12",
"exports": {
".": "./src/index.ts",
"./worker": "./src/worker.ts",
Expand Down
40 changes: 20 additions & 20 deletions packages/tauri-api-adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tauri-api-adapter",
"version": "0.3.11",
"version": "0.3.12",
"type": "module",
"exports": {
".": {
Expand Down Expand Up @@ -36,31 +36,31 @@
},
"license": "MIT",
"devDependencies": {
"@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-typescript": "^12.1.1",
"@types/bun": "latest",
"typedoc": "^0.26.6"
"typedoc": "^0.26.11",
"rollup": "^4.27.2"
},
"dependencies": {
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-typescript": "^11.1.6",
"@tauri-apps/api": "^2.0.0-rc.4",
"@tauri-apps/plugin-dialog": "~2.0.0-rc.0",
"@tauri-apps/plugin-fs": "~2.0.0-rc.0",
"@tauri-apps/plugin-http": "~2.0.0-rc.1",
"@tauri-apps/plugin-log": "~2.0.0-rc.0",
"@tauri-apps/plugin-notification": "~2.0.0-rc.0",
"@tauri-apps/plugin-os": "~2.0.0-rc.0",
"@tauri-apps/plugin-shell": "~2.0.0-rc.0",
"@tauri-apps/plugin-upload": "~2.0.0-rc.0",
"@tauri-apps/api": "^2.1.1",
"@tauri-apps/plugin-dialog": "^2.0.1",
"@tauri-apps/plugin-fs": "^2.0.2",
"@tauri-apps/plugin-http": "^2.0.1",
"@tauri-apps/plugin-log": "^2.0.0",
"@tauri-apps/plugin-notification": "^2.0.0",
"@tauri-apps/plugin-os": "^2.0.0",
"@tauri-apps/plugin-shell": "^2.0.1",
"@tauri-apps/plugin-upload": "^2.1.0",
"kkrpc": "^0.0.7",
"rimraf": "^5.0.7",
"rollup": "^4.18.0",
"rimraf": "^6.0.1",
"shx": "^0.3.4",
"tauri-plugin-clipboard-api": "^2.1.8",
"tauri-plugin-network-api": "^2.0.3",
"tauri-plugin-shellx-api": "^2.0.10",
"tauri-plugin-system-info-api": "^2.0.5",
"tauri-plugin-clipboard-api": "^2.1.11",
"tauri-plugin-network-api": "^2.0.4",
"tauri-plugin-shellx-api": "^2.0.14",
"tauri-plugin-system-info-api": "^2.0.8",
"tsc-alias": "^1.8.10",
"typescript": "^5.0.0",
"typescript": "^5.6.3",
"valibot": "^0.40.0"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/tauri-api-adapter/src/api/client/updownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { IUpdownload } from './types'
interface ProgressPayload {
progress: number
total: number
transferSpeed: number
}
type ProgressHandler = (progress: ProgressPayload) => void

Expand Down
10 changes: 9 additions & 1 deletion packages/tauri-api-adapter/src/api/server/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ export function constructFetchApi(permissions: FetchPermission[]): IFetchInterna
fetchReadBody: checkPermission<FetchPermission>(
FetchPermissionMap.fetchReadBody,
permissions
)((rid: number) => invoke<ArrayBuffer | number[]>('plugin:http|fetch_read_body', { rid }))
)((rid: number) =>
invoke<ArrayBuffer | number[]>('plugin:http|fetch_read_body', { rid }).then((body) => {
if (body instanceof ArrayBuffer) {
// convert ArrayBuffer to number[], kkrpc channel uses JSON.stringify, which doesn't work with ArrayBuffer
return Array.from(new Uint8Array(body))
}
return body
})
)
}
}
export const defaultFetchApi = constructFetchApi(['fetch:all'])
Loading

0 comments on commit 36d3229

Please sign in to comment.