Fixed asset:// loading and tweak curl stuff

This commit is contained in:
Gregory Schier
2024-05-13 23:20:30 -07:00
parent 7e74f71c79
commit 0b494bbfbf
11 changed files with 91 additions and 129 deletions

57
src-tauri/Cargo.lock generated
View File

@@ -2447,6 +2447,12 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "http-range"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
[[package]] [[package]]
name = "httparse" name = "httparse"
version = "1.8.0" version = "1.8.0"
@@ -4936,9 +4942,9 @@ dependencies = [
[[package]] [[package]]
name = "schemars" name = "schemars"
version = "0.8.16" version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" checksum = "fc6e7ed6919cb46507fb01ff1654309219f62b4d603822501b0b80d42f6f21ef"
dependencies = [ dependencies = [
"dyn-clone", "dyn-clone",
"indexmap 1.9.3", "indexmap 1.9.3",
@@ -4950,14 +4956,14 @@ dependencies = [
[[package]] [[package]]
name = "schemars_derive" name = "schemars_derive"
version = "0.8.16" version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" checksum = "185f2b7aa7e02d418e453790dde16890256bbd2bcd04b7dc5348811052b53f49"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"serde_derive_internals", "serde_derive_internals",
"syn 1.0.109", "syn 2.0.58",
] ]
[[package]] [[package]]
@@ -5072,13 +5078,13 @@ dependencies = [
[[package]] [[package]]
name = "serde_derive_internals" name = "serde_derive_internals"
version = "0.26.0" version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" checksum = "330f01ce65a3a5fe59a60c82f3c9a024b573b8a6e875bd233fe5f934e71d54e3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.109", "syn 2.0.58",
] ]
[[package]] [[package]]
@@ -5771,9 +5777,9 @@ dependencies = [
[[package]] [[package]]
name = "tao" name = "tao"
version = "0.27.1" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92bcf8885e147b56d6e26751263b45876284f32ca404703f6d3b8f80d16ff4dd" checksum = "12a8121bd5721ebbbe0889f8286d5824673beeb04071519b68916fbed04f3093"
dependencies = [ dependencies = [
"bitflags 2.5.0", "bitflags 2.5.0",
"cocoa", "cocoa",
@@ -5844,9 +5850,9 @@ checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a"
[[package]] [[package]]
name = "tauri" name = "tauri"
version = "2.0.0-beta.17" version = "2.0.0-beta.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fedd5490eddf117253945f0baedafded43474c971cba546a818f527d5c26266" checksum = "6f8e5bc2e4f5eb7496d1a3e5f4d272f69f1333db5f8efed28d79d7f93334fe95"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@@ -5860,6 +5866,7 @@ dependencies = [
"gtk", "gtk",
"heck 0.5.0", "heck 0.5.0",
"http 1.1.0", "http 1.1.0",
"http-range",
"jni", "jni",
"libc", "libc",
"log", "log",
@@ -5893,9 +5900,9 @@ dependencies = [
[[package]] [[package]]
name = "tauri-build" name = "tauri-build"
version = "2.0.0-beta.13" version = "2.0.0-beta.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abcf98a9b4527567c3e5ca9723431d121e001c2145651b3fa044d22b5e025a7e" checksum = "8aa28eebafcda490fa7097a6e3a4d07f65967614d35dd88b2aaa19dbb49241cd"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cargo_toml", "cargo_toml",
@@ -5915,9 +5922,9 @@ dependencies = [
[[package]] [[package]]
name = "tauri-codegen" name = "tauri-codegen"
version = "2.0.0-beta.13" version = "2.0.0-beta.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b383f341efb803852b0235a2f330ca90c4c113f422dd6d646b888685b372cace" checksum = "727d13a28e9ec895f537d90a09acb0aa3593f703a715fe8a77f87269d3245b52"
dependencies = [ dependencies = [
"base64 0.22.0", "base64 0.22.0",
"brotli", "brotli",
@@ -5942,11 +5949,11 @@ dependencies = [
[[package]] [[package]]
name = "tauri-macros" name = "tauri-macros"
version = "2.0.0-beta.13" version = "2.0.0-beta.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71be71718cfe48b149507157bfbad0e2ba0e98ea51658be26c7c677eb188fb0c" checksum = "258667612ad901d256e04ace71ac54d4b3dd8fb1e5baa24403b50991cade4365"
dependencies = [ dependencies = [
"heck 0.4.1", "heck 0.5.0",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.58", "syn 2.0.58",
@@ -6121,9 +6128,9 @@ dependencies = [
[[package]] [[package]]
name = "tauri-runtime" name = "tauri-runtime"
version = "2.0.0-beta.14" version = "2.0.0-beta.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "148b6e6aff8e63fe5d4ae1d50159d50cfc0b4309abdeca64833c887c6b5631ef" checksum = "574f3d59cbe6c76b6d849bc35aa3a9e8061ff8f75f557dc33f38c0e43cf55a41"
dependencies = [ dependencies = [
"dpi", "dpi",
"gtk", "gtk",
@@ -6140,9 +6147,9 @@ dependencies = [
[[package]] [[package]]
name = "tauri-runtime-wry" name = "tauri-runtime-wry"
version = "2.0.0-beta.14" version = "2.0.0-beta.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "398d065c6e0fbf3c4304583759b6e153bc1e0daeb033bede6834ebe4df371fc3" checksum = "d6d1f223de1d674aaa561c900ac650b3160f11520e9b191a3574f6c493fc77fa"
dependencies = [ dependencies = [
"cocoa", "cocoa",
"gtk", "gtk",
@@ -6164,9 +6171,9 @@ dependencies = [
[[package]] [[package]]
name = "tauri-utils" name = "tauri-utils"
version = "2.0.0-beta.13" version = "2.0.0-beta.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4709765385f035338ecc330f3fba753b8ee283c659c235da9768949cdb25469" checksum = "2b4251529d92b5c611ccaa611f8a31cb41b1aa00db8bcc0a49efe5d966bfa911"
dependencies = [ dependencies = [
"brotli", "brotli",
"cargo_metadata", "cargo_metadata",

View File

@@ -34,10 +34,7 @@ reqwest = { version = "0.11.23", features = ["multipart", "cookies", "gzip", "br
serde = { version = "1.0.198", features = ["derive"] } serde = { version = "1.0.198", features = ["derive"] }
serde_json = { version = "1.0.116", features = ["raw_value"] } serde_json = { version = "1.0.116", features = ["raw_value"] }
sqlx = { version = "0.7.4", features = ["sqlite", "runtime-tokio-rustls", "json", "chrono", "time"] } sqlx = { version = "0.7.4", features = ["sqlite", "runtime-tokio-rustls", "json", "chrono", "time"] }
tauri = { version = "2.0.0-beta.17", features = [ tauri = { version = "2.0.0-beta.19", features = ["config-toml", "devtools", "protocol-asset"] }
"config-toml",
"devtools",
] }
tauri-plugin-clipboard-manager = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } tauri-plugin-clipboard-manager = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-dialog = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } tauri-plugin-dialog = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2", features = ["colored"] } tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2", features = ["colored"] }

View File

@@ -47,6 +47,7 @@
"window:allow-set-title", "window:allow-set-title",
"window:allow-start-dragging", "window:allow-start-dragging",
"window:allow-unmaximize", "window:allow-unmaximize",
"clipboard-manager:default" "clipboard-manager:allow-read-text",
"clipboard-manager:allow-write-text"
] ]
} }

View File

@@ -1 +1 @@
{"main":{"identifier":"main","description":"Main permissions","local":true,"windows":["*"],"permissions":["os:allow-os-type","event:allow-emit","clipboard-manager:allow-write-text","clipboard-manager:allow-read-text","dialog:allow-open","dialog:allow-save","event:allow-listen","event:allow-unlisten","fs:allow-read-file","fs:allow-read-text-file",{"identifier":"fs:scope","allow":[{"path":"$APPDATA"},{"path":"$APPDATA/**"}]},"shell:allow-open",{"identifier":"shell:allow-execute","allow":[{"args":true,"name":"protoc","sidecar":true}]},"window:allow-close","window:allow-is-fullscreen","window:allow-maximize","window:allow-minimize","window:allow-set-decorations","window:allow-set-title","window:allow-start-dragging","window:allow-unmaximize","clipboard-manager:default"]}} {"main":{"identifier":"main","description":"Main permissions","local":true,"windows":["*"],"permissions":["os:allow-os-type","event:allow-emit","clipboard-manager:allow-write-text","clipboard-manager:allow-read-text","dialog:allow-open","dialog:allow-save","event:allow-listen","event:allow-unlisten","fs:allow-read-file","fs:allow-read-text-file",{"identifier":"fs:scope","allow":[{"path":"$APPDATA"},{"path":"$APPDATA/**"}]},"shell:allow-open",{"identifier":"shell:allow-execute","allow":[{"args":true,"name":"protoc","sidecar":true}]},"window:allow-close","window:allow-is-fullscreen","window:allow-maximize","window:allow-minimize","window:allow-set-decorations","window:allow-set-title","window:allow-start-dragging","window:allow-unmaximize","clipboard-manager:allow-read-text","clipboard-manager:allow-write-text"]}}

View File

@@ -48,7 +48,7 @@ use crate::models::{
get_cookie_jar, get_environment, get_folder, get_grpc_connection, get_cookie_jar, get_environment, get_folder, get_grpc_connection,
get_grpc_request, get_http_request, get_http_response, get_key_value_raw, get_grpc_request, get_http_request, get_http_response, get_key_value_raw,
get_or_create_settings, get_workspace, get_workspace_export_resources, GrpcConnection, GrpcEvent, get_or_create_settings, get_workspace, get_workspace_export_resources, GrpcConnection, GrpcEvent,
GrpcEventType, GrpcRequest, HttpRequest, HttpRequestHeader, HttpResponse, GrpcEventType, GrpcRequest, HttpRequest, HttpResponse,
KeyValue, list_cookie_jars, list_environments, list_folders, list_grpc_connections, KeyValue, list_cookie_jars, list_environments, list_folders, list_grpc_connections,
list_grpc_events, list_grpc_requests, list_http_requests, list_responses, list_workspaces, list_grpc_events, list_grpc_requests, list_http_requests, list_responses, list_workspaces,
ModelType, set_key_value_raw, Settings, update_response_if_id, update_settings, upsert_cookie_jar, ModelType, set_key_value_raw, Settings, update_response_if_id, update_settings, upsert_cookie_jar,
@@ -1184,30 +1184,12 @@ async fn cmd_duplicate_grpc_request(id: &str, w: WebviewWindow) -> Result<GrpcRe
#[tauri::command] #[tauri::command]
async fn cmd_create_http_request( async fn cmd_create_http_request(
workspace_id: &str, request: HttpRequest,
name: &str,
sort_priority: f64,
folder_id: Option<&str>,
method: Option<&str>,
headers: Option<Vec<HttpRequestHeader>>,
body_type: Option<&str>,
w: WebviewWindow, w: WebviewWindow,
) -> Result<HttpRequest, String> { ) -> Result<HttpRequest, String> {
upsert_http_request( upsert_http_request(&w, request)
&w, .await
HttpRequest { .map_err(|e| e.to_string())
workspace_id: workspace_id.to_string(),
name: name.to_string(),
folder_id: folder_id.map(|s| s.to_string()),
body_type: body_type.map(|s| s.to_string()),
method: method.map(|s| s.to_string()).unwrap_or("GET".to_string()),
headers: Json(headers.unwrap_or_default()),
sort_priority,
..Default::default()
},
)
.await
.map_err(|e| e.to_string())
} }
#[tauri::command] #[tauri::command]

View File

@@ -12,9 +12,12 @@
"withGlobalTauri": false, "withGlobalTauri": false,
"security": { "security": {
"assetProtocol": { "assetProtocol": {
"scope": [ "enable": true,
"$APPDATA/responses/*" "scope": {
] "allow": [
"$APPDATA/responses/*"
]
}
} }
} }
}, },
@@ -24,48 +27,6 @@
"https://update.yaak.app/check/{{target}}/{{arch}}/{{current_version}}" "https://update.yaak.app/check/{{target}}/{{arch}}/{{current_version}}"
], ],
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEMxRDJFREQ1MjExQjdGN0IKUldSN2Z4c2gxZTNTd1FHNCtmYnFXMHVVQzhuNkJOM1cwOFBodmdLall3ckhKenpKUytHSTR1MlkK" "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEMxRDJFREQ1MjExQjdGN0IKUldSN2Z4c2gxZTNTd1FHNCtmYnFXMHVVQzhuNkJOM1cwOFBodmdLall3ckhKenpKUytHSTR1MlkK"
},
"allowlist": {
"all": false,
"os": {
"allow-os-type": true
},
"fs": {
"readFile": true,
"scope": [
"$RESOURCE/*",
"$APPDATA/responses/*"
]
},
"shell": {
"all": false,
"open": true,
"sidecar": true,
"scope": [
{
"name": "protoc",
"sidecar": true,
"args": true
}
]
},
"window": {
"close": true,
"maximize": true,
"minimize": true,
"setDecorations": true,
"setTitle": true,
"startDragging": true,
"unmaximize": true
},
"dialog": {
"all": false,
"open": true,
"save": true
},
"path": {
"all": true
}
} }
}, },
"bundle": { "bundle": {

View File

@@ -7,10 +7,10 @@ import { motion } from 'framer-motion';
export function ImportCurlButton() { export function ImportCurlButton() {
const [clipboardText] = useClipboardText(); const [clipboardText] = useClipboardText();
const [lastImportedCmd, setLastImportedCmd] = useState<string>(''); const importCurl = useImportCurl({ clearClipboard: true });
const importCurl = useImportCurl(); const [isLoading, setIsLoading] = useState(false);
if (!clipboardText?.trim().startsWith('curl ') || lastImportedCmd === clipboardText) { if (!clipboardText?.trim().startsWith('curl ')) {
return null; return null;
} }
@@ -25,13 +25,15 @@ export function ImportCurlButton() {
variant="border" variant="border"
color="secondary" color="secondary"
leftSlot={<Icon icon="paste" size="sm" />} leftSlot={<Icon icon="paste" size="sm" />}
isLoading={isLoading}
onClick={() => { onClick={() => {
importCurl.mutate({ setIsLoading(true);
requestId: null, // Create request importCurl
command: clipboardText, .mutateAsync({
}); requestId: null, // Create request
// setClipboardText(''); command: clipboardText,
setLastImportedCmd(clipboardText); })
.finally(() => setIsLoading(false));
}} }}
> >
Import Curl Import Curl

View File

@@ -230,7 +230,7 @@ export const RequestPane = memo(function RequestPane({
const isLoading = useIsResponseLoading(activeRequestId ?? null); const isLoading = useIsResponseLoading(activeRequestId ?? null);
const { updateKey } = useRequestUpdateKey(activeRequestId ?? null); const { updateKey } = useRequestUpdateKey(activeRequestId ?? null);
const importCurl = useImportCurl(); const importCurl = useImportCurl({ clearClipboard: true });
return ( return (
<div <div

View File

@@ -1,18 +1,25 @@
import { readText, writeText } from '@tauri-apps/plugin-clipboard-manager'; import { readText, writeText } from '@tauri-apps/plugin-clipboard-manager';
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect } from 'react';
import { useWindowFocus } from './useWindowFocus'; import { useWindowFocus } from './useWindowFocus';
import { createGlobalState } from 'react-use';
const useClipboardTextState = createGlobalState<string>('');
export function useClipboardText() { export function useClipboardText() {
const [value, setValue] = useState<string>(''); const [value, setValue] = useClipboardTextState();
const focused = useWindowFocus(); const focused = useWindowFocus();
useEffect(() => { useEffect(() => {
readText().then(setValue); readText().then(setValue);
}, [focused]); }, [focused, setValue]);
const setText = useCallback((text: string) => { const setText = useCallback(
writeText(text).catch(console.error); (text: string) => {
}, []); writeText(text).catch(console.error);
setValue(text);
},
[setValue],
);
return [value, setText] as const; return [value, setText] as const;
} }

View File

@@ -13,13 +13,7 @@ export function useCreateHttpRequest() {
const activeRequest = useActiveRequest(); const activeRequest = useActiveRequest();
const routes = useAppRoutes(); const routes = useAppRoutes();
return useMutation< return useMutation<HttpRequest, unknown, Partial<HttpRequest>>({
HttpRequest,
unknown,
Partial<
Pick<HttpRequest, 'name' | 'sortPriority' | 'folderId' | 'bodyType' | 'method' | 'headers'>
>
>({
mutationFn: (patch) => { mutationFn: (patch) => {
if (workspaceId === null) { if (workspaceId === null) {
throw new Error("Cannot create request when there's no active workspace"); throw new Error("Cannot create request when there's no active workspace");
@@ -34,7 +28,8 @@ export function useCreateHttpRequest() {
} }
} }
patch.folderId = patch.folderId || activeRequest?.folderId; patch.folderId = patch.folderId || activeRequest?.folderId;
return invoke('cmd_create_http_request', { workspaceId, name: '', ...patch }); console.log('PATCH', patch);
return invoke('cmd_create_http_request', { request: { workspaceId, ...patch } });
}, },
onSettled: () => trackEvent('http_request', 'create'), onSettled: () => trackEvent('http_request', 'create'),
onSuccess: async (request) => { onSuccess: async (request) => {

View File

@@ -5,13 +5,15 @@ import { useRequestUpdateKey } from './useRequestUpdateKey';
import { useUpdateAnyHttpRequest } from './useUpdateAnyHttpRequest'; import { useUpdateAnyHttpRequest } from './useUpdateAnyHttpRequest';
import { useToast } from '../components/ToastContext'; import { useToast } from '../components/ToastContext';
import { useCreateHttpRequest } from './useCreateHttpRequest'; import { useCreateHttpRequest } from './useCreateHttpRequest';
import { useClipboardText } from './useClipboardText';
export function useImportCurl() { export function useImportCurl({ clearClipboard }: { clearClipboard?: boolean } = {}) {
const workspaceId = useActiveWorkspaceId(); const workspaceId = useActiveWorkspaceId();
const updateRequest = useUpdateAnyHttpRequest(); const updateRequest = useUpdateAnyHttpRequest();
const createRequest = useCreateHttpRequest(); const createRequest = useCreateHttpRequest();
const { wasUpdatedExternally } = useRequestUpdateKey(null); const { wasUpdatedExternally } = useRequestUpdateKey(null);
const toast = useToast(); const toast = useToast();
const [, setClipboardText] = useClipboardText();
return useMutation({ return useMutation({
mutationFn: async ({ requestId, command }: { requestId: string | null; command: string }) => { mutationFn: async ({ requestId, command }: { requestId: string | null; command: string }) => {
@@ -21,16 +23,24 @@ export function useImportCurl() {
}); });
delete request.id; delete request.id;
const id = requestId ?? (await createRequest.mutateAsync({})).id; let verb;
await updateRequest.mutateAsync({ id, update: request }); if (requestId == null) {
verb = 'Created';
await createRequest.mutateAsync(request);
} else {
verb = 'Updated';
await updateRequest.mutateAsync({ id: requestId, update: request });
setTimeout(() => wasUpdatedExternally(requestId), 100);
}
const verb = requestId ? 'updated' : 'created';
toast.show({ toast.show({
variant: 'success', variant: 'success',
message: `Request ${verb} from Curl`, message: `${verb} request from Curl`,
}); });
wasUpdatedExternally(id); if (clearClipboard) {
setClipboardText('');
}
}, },
}); });
} }