-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: Tauri | ||
description: Want to make Pawnote run under Tauri ? Here's how to do it. | ||
--- | ||
|
||
## Fetcher (for Tauri v1) | ||
|
||
Since Pawnote uses [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) as default fetcher, you need to create a custom fetcher to make it work with the [Tauri HTTP API](https://tauri.app/v1/api/js/http). | ||
|
||
Here's a simple one that should always work for Pawnote: | ||
|
||
```typescript | ||
import { type PawnoteFetcher } from "pawnote"; | ||
import { Body, ResponseType, getClient } from "@tauri-apps/api/http"; | ||
|
||
const tauriPawnoteFetcher: PawnoteFetcher = async (url, options) => { | ||
const client = await getClient(options.redirect === "manual" ? { | ||
maxRedirections: 0 | ||
} : void 0); | ||
|
||
const response = await client.request<string>({ | ||
url, | ||
method: options.method, | ||
headers: options.headers, | ||
body: options.method !== "GET" && options.body ? Body.text(options.body) : void 0, | ||
responseType: ResponseType.Text | ||
}); | ||
|
||
return { | ||
headers: response.headers, | ||
text: async () => response.data, | ||
json: async <T>() => JSON.parse(response.data) as T | ||
} | ||
}; | ||
|
||
export default tauriPawnoteFetcher; | ||
``` |