Fixed requests, race condition

This commit is contained in:
Kurvaz 2026-01-07 06:25:31 -07:00
parent 51df9a02df
commit e961b45341
10 changed files with 246 additions and 17 deletions

14
package-lock.json generated
View file

@ -1,17 +1,18 @@
{
"name": "aventura",
"version": "0.2.3",
"version": "0.2.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "aventura",
"version": "0.2.3",
"version": "0.2.4",
"license": "MIT",
"dependencies": {
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-dialog": "^2",
"@tauri-apps/plugin-fs": "^2",
"@tauri-apps/plugin-http": "^2.5.4",
"@tauri-apps/plugin-opener": "^2",
"@tauri-apps/plugin-process": "^2.3.1",
"@tauri-apps/plugin-sql": "^2",
@ -1240,6 +1241,15 @@
"@tauri-apps/api": "^2.8.0"
}
},
"node_modules/@tauri-apps/plugin-http": {
"version": "2.5.4",
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-http/-/plugin-http-2.5.4.tgz",
"integrity": "sha512-/i4U/9za3mrytTgfRn5RHneKubZE/dwRmshYwyMvNRlkWjvu1m4Ma72kcbVJMZFGXpkbl+qLyWMGrihtWB76Zg==",
"license": "MIT OR Apache-2.0",
"dependencies": {
"@tauri-apps/api": "^2.8.0"
}
},
"node_modules/@tauri-apps/plugin-opener": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-opener/-/plugin-opener-2.5.2.tgz",

View file

@ -1,6 +1,6 @@
{
"name": "aventura",
"version": "0.2.3",
"version": "0.2.4",
"description": "AI-powered adventure and creative writing frontend",
"type": "module",
"scripts": {
@ -16,6 +16,7 @@
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-dialog": "^2",
"@tauri-apps/plugin-fs": "^2",
"@tauri-apps/plugin-http": "^2.5.4",
"@tauri-apps/plugin-opener": "^2",
"@tauri-apps/plugin-process": "^2.3.1",
"@tauri-apps/plugin-sql": "^2",

185
src-tauri/Cargo.lock generated
View file

@ -260,7 +260,7 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "aventura"
version = "0.2.3"
version = "0.2.4"
dependencies = [
"axum",
"base64 0.22.1",
@ -274,6 +274,7 @@ dependencies = [
"tauri-build",
"tauri-plugin-dialog",
"tauri-plugin-fs",
"tauri-plugin-http",
"tauri-plugin-opener",
"tauri-plugin-process",
"tauri-plugin-sql",
@ -617,10 +618,57 @@ version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747"
dependencies = [
"percent-encoding",
"time",
"version_check",
]
[[package]]
name = "cookie_store"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eac901828f88a5241ee0600950ab981148a18f2f756900ffba1b125ca6a3ef9"
dependencies = [
"cookie",
"document-features",
"idna",
"log",
"publicsuffix",
"serde",
"serde_derive",
"serde_json",
"time",
"url",
]
[[package]]
name = "cookie_store"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fc4bff745c9b4c7fb1e97b25d13153da2bc7796260141df62378998d070207f"
dependencies = [
"cookie",
"document-features",
"idna",
"log",
"publicsuffix",
"serde",
"serde_derive",
"serde_json",
"time",
"url",
]
[[package]]
name = "core-foundation"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation"
version = "0.10.1"
@ -644,7 +692,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa95a34622365fa5bbf40b20b75dba8dfa8c94c734aea8ac9a5ca38af14316f1"
dependencies = [
"bitflags 2.10.0",
"core-foundation",
"core-foundation 0.10.1",
"core-graphics-types",
"foreign-types",
"libc",
@ -657,7 +705,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb"
dependencies = [
"bitflags 2.10.0",
"core-foundation",
"core-foundation 0.10.1",
"libc",
]
@ -835,6 +883,12 @@ dependencies = [
"syn 2.0.113",
]
[[package]]
name = "data-url"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376"
[[package]]
name = "der"
version = "0.7.10"
@ -1005,6 +1059,15 @@ dependencies = [
"syn 2.0.113",
]
[[package]]
name = "document-features"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61"
dependencies = [
"litrs",
]
[[package]]
name = "dotenvy"
version = "0.15.7"
@ -1082,6 +1145,15 @@ version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7"
[[package]]
name = "encoding_rs"
version = "0.8.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
dependencies = [
"cfg-if",
]
[[package]]
name = "endi"
version = "1.1.1"
@ -1703,6 +1775,25 @@ dependencies = [
"syn 2.0.113",
]
[[package]]
name = "h2"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54"
dependencies = [
"atomic-waker",
"bytes",
"fnv",
"futures-core",
"futures-sink",
"http",
"indexmap 2.12.1",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
@ -1853,6 +1944,7 @@ dependencies = [
"bytes",
"futures-channel",
"futures-core",
"h2",
"http",
"http-body",
"httparse",
@ -1901,9 +1993,11 @@ dependencies = [
"percent-encoding",
"pin-project-lite",
"socket2",
"system-configuration",
"tokio",
"tower-service",
"tracing",
"windows-registry",
]
[[package]]
@ -2333,6 +2427,12 @@ version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77"
[[package]]
name = "litrs"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092"
[[package]]
name = "local-ip-address"
version = "0.6.8"
@ -3360,6 +3460,22 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "psl-types"
version = "2.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33cb294fe86a74cbcf50d4445b37da762029549ebeea341421c7c70370f86cac"
[[package]]
name = "publicsuffix"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42ea446cab60335f76979ec15e12619a2165b5ae2c12166bef27d283a9fadf"
dependencies = [
"idna",
"psl-types",
]
[[package]]
name = "pxfm"
version = "0.1.27"
@ -3659,8 +3775,12 @@ checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"
dependencies = [
"base64 0.22.1",
"bytes",
"cookie",
"cookie_store 0.22.0",
"encoding_rs",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"http-body-util",
@ -3669,6 +3789,7 @@ dependencies = [
"hyper-util",
"js-sys",
"log",
"mime",
"percent-encoding",
"pin-project-lite",
"quinn",
@ -4570,6 +4691,27 @@ dependencies = [
"syn 2.0.113",
]
[[package]]
name = "system-configuration"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b"
dependencies = [
"bitflags 2.10.0",
"core-foundation 0.9.4",
"system-configuration-sys",
]
[[package]]
name = "system-configuration-sys"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "system-deps"
version = "6.2.2"
@ -4591,7 +4733,7 @@ checksum = "f3a753bdc39c07b192151523a3f77cd0394aa75413802c883a0f6f6a0e5ee2e7"
dependencies = [
"bitflags 2.10.0",
"block2",
"core-foundation",
"core-foundation 0.10.1",
"core-graphics",
"crossbeam-channel",
"dispatch",
@ -4822,6 +4964,30 @@ dependencies = [
"url",
]
[[package]]
name = "tauri-plugin-http"
version = "2.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c00685aceab12643cf024f712ab0448ba8fcadf86f2391d49d2e5aa732aacc70"
dependencies = [
"bytes",
"cookie_store 0.21.1",
"data-url",
"http",
"regex",
"reqwest",
"schemars 0.8.22",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"tauri-plugin-fs",
"thiserror 2.0.17",
"tokio",
"url",
"urlpattern",
]
[[package]]
name = "tauri-plugin-opener"
version = "2.5.2"
@ -6024,6 +6190,17 @@ dependencies = [
"windows-link 0.1.3",
]
[[package]]
name = "windows-registry"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"
dependencies = [
"windows-link 0.2.1",
"windows-result 0.4.1",
"windows-strings 0.5.1",
]
[[package]]
name = "windows-result"
version = "0.3.4"

View file

@ -1,6 +1,6 @@
[package]
name = "aventura"
version = "0.2.3"
version = "0.2.4"
description = "AI-powered adventure and creative writing frontend"
authors = ["Karelian"]
edition = "2021"
@ -22,6 +22,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-updater = "2.9.0"
tauri-plugin-process = "2.3.1"
tauri-plugin-http = "2"
# Local network sync
axum = "0.8"

View file

@ -26,6 +26,23 @@
"updater:allow-download-and-install",
"process:default",
"process:allow-restart",
"process:allow-exit"
"process:allow-exit",
"http:default",
{
"identifier": "http:allow-fetch",
"allow": [{ "url": "https://*" }, { "url": "http://*" }]
},
{
"identifier": "http:allow-fetch-cancel",
"allow": [{ "url": "https://*" }, { "url": "http://*" }]
},
{
"identifier": "http:allow-fetch-read-body",
"allow": [{ "url": "https://*" }, { "url": "http://*" }]
},
{
"identifier": "http:allow-fetch-send",
"allow": [{ "url": "https://*" }, { "url": "http://*" }]
}
]
}

View file

@ -54,6 +54,7 @@ pub fn run() {
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_http::init())
.invoke_handler(tauri::generate_handler![
start_sync_server,
stop_sync_server,

View file

@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "Aventura",
"version": "0.2.3",
"version": "0.2.4",
"identifier": "com.karelian.aventura",
"build": {
"beforeDevCommand": "npm run dev",

View file

@ -3,6 +3,7 @@
import type { APIProfile } from '$lib/types';
import { X, Plus, Trash2, RefreshCw, Check, AlertCircle } from 'lucide-svelte';
import { ask } from '@tauri-apps/plugin-dialog';
import { fetch } from '@tauri-apps/plugin-http';
// Check if the current profile can be deleted
let canDelete = $derived(editingProfile ? settings.canDeleteProfile(editingProfile.id) : false);

View file

@ -67,6 +67,9 @@
let downloadProgress = $state<UpdateProgress | null>(null);
let updateError = $state<string | null>(null);
// Reset state - prevents modal close during reset operation
let isResettingSettings = $state(false);
// Model fetching state
let isLoadingModels = $state(false);
let modelError = $state<string | null>(null);
@ -442,7 +445,18 @@
);
if (!confirmed) return;
await settings.resetAllSettings(true);
isResettingSettings = true;
try {
await settings.resetAllSettings(true);
} finally {
isResettingSettings = false;
}
}
// Safe close that prevents closing during reset operations
function safeClose() {
if (isResettingSettings) return;
ui.closeSettings();
}
async function handleCheckForUpdates() {
@ -504,11 +518,11 @@
// Swipe down to dismiss modal on mobile
function handleSwipeDown() {
ui.closeSettings();
safeClose();
}
</script>
<div class="fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/60" onclick={() => ui.closeSettings()}>
<div class="fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/60" onclick={() => safeClose()}>
<div
class="card w-full sm:max-w-2xl max-h-[95vh] sm:max-h-[80vh] overflow-hidden rounded-b-none sm:rounded-b-xl flex flex-col"
onclick={(e) => e.stopPropagation()}
@ -522,7 +536,7 @@
<!-- Header -->
<div class="flex items-center justify-between border-b border-surface-700 pb-3 sm:pb-4 pt-0 sm:pt-0 flex-shrink-0">
<h2 class="text-lg sm:text-xl font-semibold text-surface-100">Settings</h2>
<button class="btn-ghost rounded-lg p-2 min-h-[44px] min-w-[44px] flex items-center justify-center" onclick={() => ui.closeSettings()}>
<button class="btn-ghost rounded-lg p-2 min-h-[44px] min-w-[44px] flex items-center justify-center" onclick={() => safeClose()} disabled={isResettingSettings}>
<X class="h-5 w-5" />
</button>
</div>
@ -3323,11 +3337,17 @@
</p>
</div>
<button
class="px-4 py-2 text-sm font-medium text-red-400 border border-red-500/50 rounded-lg hover:bg-red-500/20 transition-colors flex items-center gap-2"
class="px-4 py-2 text-sm font-medium text-red-400 border border-red-500/50 rounded-lg hover:bg-red-500/20 transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed"
onclick={handleResetAll}
disabled={isResettingSettings}
>
<RotateCcw class="h-4 w-4" />
Reset All
{#if isResettingSettings}
<Loader2 class="h-4 w-4 animate-spin" />
Resetting...
{:else}
<RotateCcw class="h-4 w-4" />
Reset All
{/if}
</button>
</div>
</div>

View file

@ -15,6 +15,7 @@ import type {
} from './types';
import { settings } from '$lib/stores/settings.svelte';
import { ui } from '$lib/stores/ui.svelte';
import { fetch } from '@tauri-apps/plugin-http';
export const OPENROUTER_API_URL = 'https://openrouter.ai/api/v1/' //Used as the default.
const DEBUG = true;