Feat/add db#3
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces SQLite persistence (SeaORM) to the Tauri backend and migrates the frontend from “stores” to “services” for state + backend communication, adding connection session tracking.
Changes:
- Added SeaORM-backed SQLite database with migrations, entities, and commands for proxies, settings, and connection sessions.
- Replaced Svelte stores (
proxyStore,settingsStore,connectionStore) with service modules that encapsulate state +invoke()calls. - Updated UI components/pages to consume the new services and added app-start loading of proxies/settings.
Reviewed changes
Copilot reviewed 36 out of 37 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/types/index.ts | Updates shared TS types (proxy lastUsedAt + adds ConnectionSession). |
| src/lib/stores/settings.svelte.ts | Removes localStorage-backed settings store (migrated to DB-backed service). |
| src/lib/stores/proxy.svelte.ts | Removes in-memory proxy store (replaced by DB-backed proxy service). |
| src/lib/services/settings.service.svelte.ts | Adds DB-backed settings service via Tauri commands. |
| src/lib/services/session.service.ts | Adds session service wrapper for session commands. |
| src/lib/services/proxy.service.svelte.ts | Adds DB-backed proxy service + reactive proxy state. |
| src/lib/services/connection.service.svelte.ts | Refactors connection logic to use services + session tracking. |
| src/lib/pages/SettingsPage.svelte | Switches page actions to settingsService. |
| src/lib/pages/ProxiesPage.svelte | Switches page wiring to proxyService sheet state. |
| src/lib/components/settings/ConnectionSettings.svelte | Switches settings form bindings to settingsService. |
| src/lib/components/proxies/ProxyTableRow.svelte | Uses services for connect/delete; removes latency rendering. |
| src/lib/components/proxies/ProxyTable.svelte | Renders proxies from proxyService and opens add sheet via service. |
| src/lib/components/proxies/ProxyFiltersBar.svelte | Opens add proxy sheet via proxyService. |
| src/lib/components/proxies/AddProxySheet.svelte | Persists new proxies via proxyService + adds error handling. |
| src/lib/components/layout/TopAppBar.svelte | Opens add proxy sheet via proxyService. |
| src/lib/components/layout/Sidebar.svelte | Uses connectionService to show connection status. |
| src/lib/components/dashboard/RecentProxiesTable.svelte | Computes recent proxies via lastUsedAt and connects via connectionService. |
| src/lib/components/dashboard/QuickStats.svelte | Reads connection state from connectionService. |
| src/lib/components/dashboard/ConnectionCard.svelte | Uses connectionService/proxyService for connect/disconnect UI. |
| src/App.svelte | Loads proxies/settings on startup via services and shows toast on failure. |
| src-tauri/src/lib.rs | Adds DB + crypto integration and new Tauri commands for CRUD/settings/sessions. |
| src-tauri/src/db/mod.rs | Initializes SQLite DB, runs migrations, seeds default settings row. |
| src-tauri/src/db/migrations/mod.rs | Registers DB migrations. |
| src-tauri/src/db/migrations/m20240101_000001_create_proxies.rs | Creates proxies table schema. |
| src-tauri/src/db/migrations/m20240101_000002_create_settings.rs | Creates settings table schema. |
| src-tauri/src/db/migrations/m20240101_000003_create_connection_sessions.rs | Creates connection_sessions table schema + FK to proxies. |
| src-tauri/src/db/entities/settings.rs | Adds SeaORM settings entity model. |
| src-tauri/src/db/entities/proxy.rs | Adds SeaORM proxy entity model. |
| src-tauri/src/db/entities/connection_session.rs | Adds SeaORM connection session entity model. |
| src-tauri/src/db/entities/mod.rs | Exposes entity modules. |
| src-tauri/src/db/entities/enums/mod.rs | Exposes DB enum modules. |
| src-tauri/src/db/entities/enums/proxy.rs | Adds SeaORM ActiveEnum definitions for protocol/status. |
| src-tauri/src/crypto.rs | Adds AES-GCM encryption + HKDF key derivation for stored secrets. |
| src-tauri/Cargo.toml | Bumps rust-version and adds SeaORM/crypto deps. |
| src-tauri/Cargo.lock | Updates lockfile for new deps (format v4). |
| README.md | Documents new services structure and DB-backed backend commands. |
| CLAUDE.md | Updates project conventions for services + DB layout and command list. |
Comments suppressed due to low confidence (1)
src/lib/services/connection.service.svelte.ts:53
- If
sessionService.open(...)fails afterconnect_proxysucceeds, the catch block resets frontend state todisconnectedbut does not calldisconnect_proxy, leaving the system proxy potentially still enabled while the UI reports disconnected. Handle session creation failures explicitly (e.g.,try { sessionId = ... } catch { await invoke('disconnect_proxy') ... }) or move session creation into the backend connect flow so connect is atomic.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Introduced a new service architecture for managing proxies and connections, replacing the previous store-based approach. - Created `proxyService` and `connectionService` to handle proxy CRUD operations and connection management. - Updated components to utilize the new services, enhancing maintainability and readability. - Removed old proxy and settings stores to streamline the codebase. - Added session management for tracking active connections and their states. - Implemented database interactions for proxy and settings management. - Enhanced error handling and user feedback through toast notifications. feat: restructure database migrations to separate proxies, settings, and connection sessions feat: update CLAUDE.md to clarify state management, services, and database integration feat: update README.md to clarify project structure and Tauri commands feat: enhance proxy and settings management with validation and error handling feat: implement encryption and decryption for proxy credentials, update connection handling feat: enhance proxy and settings management with new fields and error handling
…ord from Proxy TS type Agent-Logs-Url: https://github.com/Sol1de/Whirm/sessions/bfe25f43-4b48-4ff7-8b15-bf72ed535efa Co-authored-by: Sol1de <127517324+Sol1de@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 36 out of 37 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (2)
src/lib/services/connection.service.svelte.ts:33
connect_proxyis invoked with{ proxyId: proxy.id }, but the Rust command argument is namedproxy_id. Unless you rename the Rust param or wrap it in an input struct, this will fail to deserialize at runtime. Align the invoke argument key with the Rust command signature.
src/lib/services/connection.service.svelte.ts:48- After a successful connection,
open_sessionupdateslast_used_atin the DB, butproxyService.proxiesis never refreshed/updated locally. This meanslastUsedAt-driven UI (e.g. recent proxies sorting) won’t reflect the new usage until a full reload. Consider updating the in-memory proxy entry (setlastUsedAttonew Date().toISOString()) or re-fetching proxies after opening the session.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+264
to
+267
| let mut result = new_proxy | ||
| .insert(&state.db) | ||
| .await | ||
| .map_err(|e| e.to_string())?; |
Comment on lines
+279
to
+302
| } | ||
|
|
||
| let updated_proxy = proxy::ActiveModel { | ||
| id: Set(input.id), | ||
| name: Set(input.name), | ||
| host: Set(input.host), | ||
| port: Set(input.port), | ||
| protocol: Set(input.protocol), | ||
| country: Set(input.country), | ||
| country_code: Set(input.country_code), | ||
| username: Set(input.username), | ||
| password: match input.new_password { | ||
| Some(ref p) if !p.is_empty() => { | ||
| let key = crypto::derive_key()?; | ||
| Set(Some(crypto::encrypt(p, &key)?)) | ||
| } | ||
| Some(_) => Set(None), | ||
| None => sea_orm::ActiveValue::NotSet, | ||
| }, | ||
| status: Set(input.status), | ||
| category: Set(input.category), | ||
| updated_at: Set(Utc::now()), | ||
| ..Default::default() | ||
| }; |
Comment on lines
+137
to
+146
| let saved = state | ||
| .saved_proxy | ||
| .lock() | ||
| .map_err(|_| "Corrupted mutex (poisoned lock)".to_string())? | ||
| .take(); | ||
|
|
||
| match saved { | ||
| Some(proxy) => { | ||
| proxy | ||
| .set_system_proxy() | ||
| .map_err(|e| format!("Failed to restore system proxy: {e}"))?; | ||
| } | ||
| None => { | ||
| return Ok(()); | ||
| } | ||
| if let Some(proxy) = saved { | ||
| proxy | ||
| .set_system_proxy() | ||
| .map_err(|e| format!("Failed to restore system proxy: {e}"))?; |
Comment on lines
+5
to
+10
| open(proxyId: string, ipAddress: string): Promise<string> { | ||
| return invoke<string>('open_session', { proxyId, ipAddress }); | ||
| }, | ||
| close(sessionId: string): Promise<void> { | ||
| return invoke<void>('close_session', { sessionId }); | ||
| }, |
Comment on lines
+20
to
+28
| let db_path = data_dir.join("whirm.db"); | ||
| let path_str = db_path | ||
| .to_str() | ||
| .ok_or("Invalid DB path (non-UTF8 characters)")? | ||
| .replace('\\', "/"); | ||
|
|
||
| let connection_string = format!("sqlite://{}?mode=rwc", path_str); | ||
|
|
||
| let db = Database::connect(&connection_string) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.