fix
This commit is contained in:
@@ -0,0 +1,243 @@
|
||||
# AGENTS.md
|
||||
|
||||
## Project Overview
|
||||
|
||||
`ewa-mobile` is a Vue 3 + Vite + Vant frontend with a Tauri 2 Rust backend.
|
||||
|
||||
The app uses local and remote model resources exposed through `che-tauri`, which is built on top of `che-orm`. Frontend model access should go through the generated TypeScript API in `src/generated`.
|
||||
|
||||
## Main Stack
|
||||
|
||||
- Vue 3 with `<script setup>` single-file components.
|
||||
- TypeScript with strict checks enabled.
|
||||
- Vite for frontend dev/build.
|
||||
- Vant for mobile UI components.
|
||||
- Vue Router with hash history.
|
||||
- Tauri 2 backend in `src-tauri`.
|
||||
- SQLite local storage through `che-orm`.
|
||||
- Remote REST integration through `che-tauri` and `reqwest`.
|
||||
|
||||
## Important Paths
|
||||
|
||||
Frontend:
|
||||
|
||||
- `package.json`: npm scripts and frontend dependencies.
|
||||
- `vite.config.ts`: Vite/Tauri dev server config.
|
||||
- `tsconfig.json`: strict TypeScript config.
|
||||
- `src/main.ts`: Vue app bootstrap.
|
||||
- `src/App.vue`: shell layout, nav bar, tabbar.
|
||||
- `src/app/router/index.ts`: main router and auth guard.
|
||||
- `src/apps/auth`: login feature.
|
||||
- `src/apps/tasks`: task list/detail/create feature.
|
||||
- `src/apps/contracts`: contract list/detail/PDF feature.
|
||||
- `src/apps/users`: users feature.
|
||||
- `src/apps/personnel`: personnel shared UI.
|
||||
- `src/shared/auth/useAuth.ts`: frontend auth state and token restore.
|
||||
- `src/shared/composables/useModelApi.ts`: shared model API loading helper.
|
||||
|
||||
Generated frontend API:
|
||||
|
||||
- `src/generated/api_client.ts`
|
||||
- `src/generated/api.ts`
|
||||
- `src/generated/models.ts`
|
||||
|
||||
Tauri backend:
|
||||
|
||||
- `src-tauri/Cargo.toml`: Rust backend dependencies.
|
||||
- `src-tauri/tauri.conf.json`: Tauri app config.
|
||||
- `src-tauri/app.toml`: database and remote API config.
|
||||
- `src-tauri/src/lib.rs`: Tauri commands and API initialization.
|
||||
- `src-tauri/src/main.rs`: native entry point.
|
||||
- `src-tauri/src/bin/manage.rs`: management CLI entry point.
|
||||
- `src-tauri/src/apps/mod.rs`: installed app list.
|
||||
- `src-tauri/src/sync.rs`: contract sync and file download logic.
|
||||
|
||||
## Installed Backend Apps
|
||||
|
||||
Current `che-tauri` app modules:
|
||||
|
||||
- `users`
|
||||
- `frcapp`
|
||||
- `projectapp`
|
||||
- `personemanagment`
|
||||
- `contractapp`
|
||||
|
||||
Each app usually contains:
|
||||
|
||||
- `models.rs`: `che_orm::Model` structs.
|
||||
- `serializers.rs`: frontend/remote field mapping.
|
||||
- `filters.rs`: list filter metadata and remote query mapping.
|
||||
- `mod.rs`: resource registration.
|
||||
- `migrations/`: local SQLite migration SQL and `schema.json` when applicable.
|
||||
|
||||
## Commands
|
||||
|
||||
Install dependencies:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
Frontend development:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Frontend build/typecheck:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
Tauri development:
|
||||
|
||||
```bash
|
||||
npm run tauri dev
|
||||
```
|
||||
|
||||
Tauri build:
|
||||
|
||||
```bash
|
||||
npm run tauri build
|
||||
```
|
||||
|
||||
Backend checks:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo fmt
|
||||
cargo check
|
||||
```
|
||||
|
||||
Management CLI from `src-tauri`:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo run --bin manage -- migrate
|
||||
cargo run --bin manage -- generate-ts --out ../src/generated
|
||||
```
|
||||
|
||||
Create or update migrations for one backend app:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo run --bin manage -- makemigrations <app>
|
||||
cargo run --bin manage -- migrate <app>
|
||||
```
|
||||
|
||||
## Generated API Rules
|
||||
|
||||
- Do not manually edit files under `src/generated` unless explicitly requested.
|
||||
- Generated API is produced from Rust app/module metadata.
|
||||
- After changing backend models, serializers, filters, or resources, regenerate TypeScript:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo run --bin manage -- generate-ts --out ../src/generated
|
||||
```
|
||||
|
||||
- Frontend code should import model APIs from `src/generated/api`, for example:
|
||||
|
||||
```ts
|
||||
import { taskApi } from "../../../generated/api";
|
||||
```
|
||||
|
||||
- Shared loading/list state should prefer `useModelApi` from `src/shared/composables/useModelApi.ts`.
|
||||
|
||||
## Tauri Commands
|
||||
|
||||
Commands are registered in `src-tauri/src/lib.rs`.
|
||||
|
||||
Important commands:
|
||||
|
||||
- `che_api`: generic model API dispatch used by generated API client.
|
||||
- `auth_login`: remote token login.
|
||||
- `auth_set_token`: restore saved token into backend state.
|
||||
- `auth_logout`: clear backend token.
|
||||
- `auth_status`: backend auth status.
|
||||
- `current_employee`: fetch current employee from remote API.
|
||||
- `sync_contracts`: sync contracts and application files into local SQLite.
|
||||
- `load_application_file`: load a local file or download it from remote URL.
|
||||
|
||||
## Adding Or Changing A Resource
|
||||
|
||||
For local SQLite-backed resources:
|
||||
|
||||
1. Edit `src-tauri/src/apps/<app>/models.rs`.
|
||||
2. Update `serializers.rs`.
|
||||
3. Update `filters.rs` if frontend list filtering needs the field.
|
||||
4. Register or adjust the resource in `<app>/mod.rs`.
|
||||
5. Run `cargo run --bin manage -- makemigrations <app>` from `src-tauri`.
|
||||
6. Run `cargo run --bin manage -- migrate <app>` from `src-tauri` if local DB needs updating.
|
||||
7. Run `cargo run --bin manage -- generate-ts --out ../src/generated`.
|
||||
8. Run `npm run build` from project root.
|
||||
|
||||
For remote-only resources:
|
||||
|
||||
- Use `ctx.remote_resource` or `ctx.mapped_remote_resource` in the app module.
|
||||
- Keep serializer `Field::source(...)` mappings aligned with remote JSON field names.
|
||||
- Keep filters aligned with backend query params and generated frontend list params.
|
||||
- Regenerate TS after resource metadata changes.
|
||||
|
||||
## Frontend Conventions
|
||||
|
||||
- Use Vue 3 `<script setup lang="ts">`.
|
||||
- Keep TypeScript strict-mode clean: no unused locals or parameters.
|
||||
- Prefer existing Vant components and the current mobile layout language.
|
||||
- Preserve current feature grouping under `src/apps/<feature>`.
|
||||
- Use generated API types from `src/generated/models`.
|
||||
- Keep auth-sensitive routes guarded with route metadata and the router guard in `src/app/router/index.ts`.
|
||||
- Do not bypass `useAuth` for login/logout/token restore unless changing auth architecture intentionally.
|
||||
|
||||
## Backend Conventions
|
||||
|
||||
- Keep Rust formatted with `cargo fmt`.
|
||||
- Use `che_orm::Model` for model structs.
|
||||
- Keep model, serializer, filter, resource registration, migration, and generated TS in sync.
|
||||
- Prefer management CLI for migrations instead of hand-writing migration files.
|
||||
- Do not edit old migration files unless the task is specifically migration repair.
|
||||
- Avoid inspecting or modifying `src-tauri/target` and generated Android build artifacts unless the task requires it.
|
||||
|
||||
## Config And Local Data
|
||||
|
||||
- `src-tauri/app.toml` contains database and remote API settings.
|
||||
- `src-tauri/src/lib.rs` currently constructs `AppConfig` inline; do not assume `app.toml` is always the runtime source of truth.
|
||||
- `src-tauri/ewa-mobile.sqlite` is a local SQLite artifact.
|
||||
- Remote API URLs may be environment-specific and may not be reachable on every machine.
|
||||
|
||||
## Validation Checklist
|
||||
|
||||
Frontend-only change:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
Tauri backend-only change:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo fmt
|
||||
cargo check
|
||||
```
|
||||
|
||||
Backend metadata or generated API change:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo fmt
|
||||
cargo check
|
||||
cargo run --bin manage -- generate-ts --out ../src/generated
|
||||
cd ..
|
||||
npm run build
|
||||
```
|
||||
|
||||
Full app confidence check:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
cd src-tauri
|
||||
cargo fmt
|
||||
cargo check
|
||||
```
|
||||
@@ -1,7 +1,191 @@
|
||||
# Tauri + Vue + TypeScript
|
||||
# ewa-mobile
|
||||
|
||||
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
Mobile/desktop EWA client built with Vue 3, Vite, Vant and Tauri 2.
|
||||
|
||||
## Recommended IDE Setup
|
||||
The frontend uses generated TypeScript APIs from the Tauri backend. The backend exposes local and remote model resources through `che-tauri`, backed by `che-orm` and SQLite.
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Vue - Official](https://marketplace.visualstudio.com/items?itemName=Vue.volar) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
|
||||
## Stack
|
||||
|
||||
- Vue 3 with `<script setup>`.
|
||||
- TypeScript strict mode.
|
||||
- Vite.
|
||||
- Vue Router with hash history.
|
||||
- Vant mobile UI components.
|
||||
- Tauri 2 Rust backend.
|
||||
- SQLite via `che-orm`.
|
||||
- Remote REST access and sync via `che-tauri`/`reqwest`.
|
||||
|
||||
## Setup
|
||||
|
||||
Install frontend dependencies:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
Run frontend dev server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Run the Tauri app in development mode:
|
||||
|
||||
```bash
|
||||
npm run tauri dev
|
||||
```
|
||||
|
||||
Build frontend:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
Build Tauri app:
|
||||
|
||||
```bash
|
||||
npm run tauri build
|
||||
```
|
||||
|
||||
## Backend Commands
|
||||
|
||||
Run backend checks:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo fmt
|
||||
cargo check
|
||||
```
|
||||
|
||||
Apply migrations:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo run --bin manage -- migrate
|
||||
```
|
||||
|
||||
Generate TypeScript API from Rust metadata:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo run --bin manage -- generate-ts --out ../src/generated
|
||||
```
|
||||
|
||||
Create and apply migrations for one app:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo run --bin manage -- makemigrations <app>
|
||||
cargo run --bin manage -- migrate <app>
|
||||
```
|
||||
|
||||
## Project Structure
|
||||
|
||||
```text
|
||||
src/
|
||||
app/router/ Main Vue Router setup and auth guard
|
||||
apps/auth/ Login feature
|
||||
apps/tasks/ Task list/detail/create screens
|
||||
apps/contracts/ Contract screens and PDF preview
|
||||
apps/users/ Users screens
|
||||
apps/personnel/ Personnel shared components
|
||||
generated/ Generated TypeScript API and models
|
||||
shared/auth/ Auth token state and restore logic
|
||||
shared/composables/ Shared model API helpers
|
||||
|
||||
src-tauri/
|
||||
src/lib.rs Tauri commands and API initialization
|
||||
src/sync.rs Contract sync and file download logic
|
||||
src/bin/manage.rs Management CLI entry point
|
||||
src/apps/ che-tauri app modules
|
||||
```
|
||||
|
||||
## Backend App Modules
|
||||
|
||||
Installed modules are registered in `src-tauri/src/apps/mod.rs`:
|
||||
|
||||
- `users`
|
||||
- `frcapp`
|
||||
- `projectapp`
|
||||
- `personemanagment`
|
||||
- `contractapp`
|
||||
|
||||
Each module usually contains `models.rs`, `serializers.rs`, `filters.rs`, `mod.rs`, and optional `migrations/`.
|
||||
|
||||
## Generated API
|
||||
|
||||
Generated files live in `src/generated`:
|
||||
|
||||
- `api_client.ts`
|
||||
- `api.ts`
|
||||
- `models.ts`
|
||||
|
||||
Do not edit generated files manually unless there is a specific reason. After changing backend models, serializers, filters, or resource registration, regenerate them:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo run --bin manage -- generate-ts --out ../src/generated
|
||||
```
|
||||
|
||||
Frontend code should use generated APIs, for example:
|
||||
|
||||
```ts
|
||||
import { taskApi } from "../../../generated/api";
|
||||
```
|
||||
|
||||
Shared list/detail loading should prefer `src/shared/composables/useModelApi.ts`.
|
||||
|
||||
## Tauri Commands
|
||||
|
||||
Important commands registered in `src-tauri/src/lib.rs`:
|
||||
|
||||
- `che_api`: generic model API dispatch used by generated clients.
|
||||
- `auth_login`: login against remote API.
|
||||
- `auth_set_token`: restore saved auth token into backend state.
|
||||
- `auth_logout`: clear backend token.
|
||||
- `auth_status`: backend auth status.
|
||||
- `current_employee`: fetch current employee from remote API.
|
||||
- `sync_contracts`: sync contracts and application files to local SQLite.
|
||||
- `load_application_file`: load local file bytes or download from remote URL.
|
||||
|
||||
## Configuration
|
||||
|
||||
- `src-tauri/app.toml` contains database and remote API settings.
|
||||
- `src-tauri/src/lib.rs` currently creates `AppConfig` inline, so do not assume `app.toml` is always the runtime source of truth.
|
||||
- `src-tauri/ewa-mobile.sqlite` is a local SQLite database artifact.
|
||||
- Remote API URLs are environment-specific.
|
||||
|
||||
## Validation
|
||||
|
||||
Frontend change:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
Backend change:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo fmt
|
||||
cargo check
|
||||
```
|
||||
|
||||
Backend metadata or generated API change:
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo fmt
|
||||
cargo check
|
||||
cargo run --bin manage -- generate-ts --out ../src/generated
|
||||
cd ..
|
||||
npm run build
|
||||
```
|
||||
|
||||
## Developer Notes
|
||||
|
||||
- Keep frontend code TypeScript-strict and avoid unused locals/parameters.
|
||||
- Keep model, serializer, filter, resource registration, migration and generated TS in sync.
|
||||
- Prefer the management CLI for migrations.
|
||||
- Avoid editing generated TypeScript and old migration files by hand.
|
||||
- Avoid inspecting or modifying `src-tauri/target` and generated Android build artifacts unless needed.
|
||||
|
||||
Generated
+111
-237
@@ -278,6 +278,29 @@ version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||
|
||||
[[package]]
|
||||
name = "aws-lc-rs"
|
||||
version = "1.17.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00bdb5da18dac48ca2cc7cd4a98e533e8635a58e2361d13a1a4ee3888e0d72f1"
|
||||
dependencies = [
|
||||
"aws-lc-sys",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aws-lc-sys"
|
||||
version = "0.43.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43103168cc76fe62678a375e722fc9cb3a0146159ac5828bc4f0dfd755c2224c"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cmake",
|
||||
"dunce",
|
||||
"fs_extra",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.21.7"
|
||||
@@ -488,6 +511,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c89588d05638b5b4594a3348a2d6c20277e43a7f5c5202b05cc56888475a47b8"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"jobserver",
|
||||
"libc",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
@@ -557,7 +582,7 @@ dependencies = [
|
||||
"async-trait",
|
||||
"che-orm",
|
||||
"clap",
|
||||
"reqwest 0.12.28",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
@@ -617,6 +642,15 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
|
||||
|
||||
[[package]]
|
||||
name = "cmake"
|
||||
version = "0.1.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.5"
|
||||
@@ -658,16 +692,6 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[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"
|
||||
@@ -691,9 +715,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "064badf302c3194842cf2c5d61f56cc88e54a759313879cdf03abdd27d0c3b97"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"core-foundation 0.10.1",
|
||||
"core-foundation",
|
||||
"core-graphics-types",
|
||||
"foreign-types 0.5.0",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
]
|
||||
|
||||
@@ -704,7 +728,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"core-foundation 0.10.1",
|
||||
"core-foundation",
|
||||
"libc",
|
||||
]
|
||||
|
||||
@@ -1080,15 +1104,6 @@ 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"
|
||||
@@ -1181,8 +1196,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"che-orm",
|
||||
"che-tauri",
|
||||
"openssl-sys",
|
||||
"reqwest 0.12.28",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
@@ -1261,15 +1275,6 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
dependencies = [
|
||||
"foreign-types-shared 0.1.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types"
|
||||
version = "0.5.0"
|
||||
@@ -1277,7 +1282,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"
|
||||
dependencies = [
|
||||
"foreign-types-macros",
|
||||
"foreign-types-shared 0.3.1",
|
||||
"foreign-types-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1291,12 +1296,6 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types-shared"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types-shared"
|
||||
version = "0.3.1"
|
||||
@@ -1312,6 +1311,12 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fs_extra"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.33"
|
||||
@@ -1703,25 +1708,6 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "h2"
|
||||
version = "0.4.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6cb093c84e8bd9b188d4c4a8cb6579fc016968d14c99882163cd3ff402a4f155"
|
||||
dependencies = [
|
||||
"atomic-waker",
|
||||
"bytes",
|
||||
"fnv",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"http",
|
||||
"indexmap 2.14.0",
|
||||
"slab",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
@@ -1864,7 +1850,6 @@ dependencies = [
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"h2",
|
||||
"http",
|
||||
"http-body",
|
||||
"httparse",
|
||||
@@ -1888,23 +1873,6 @@ dependencies = [
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tower-service",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-tls"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"native-tls",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1925,11 +1893,9 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"system-configuration",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
"windows-registry",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2211,6 +2177,16 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33"
|
||||
dependencies = [
|
||||
"getrandom 0.3.4",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.103"
|
||||
@@ -2459,23 +2435,6 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "native-tls"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"openssl",
|
||||
"openssl-probe",
|
||||
"openssl-sys",
|
||||
"schannel",
|
||||
"security-framework",
|
||||
"security-framework-sys",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ndk"
|
||||
version = "0.9.0"
|
||||
@@ -2797,59 +2756,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.81"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"cfg-if",
|
||||
"foreign-types 0.3.2",
|
||||
"libc",
|
||||
"openssl-macros",
|
||||
"openssl-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-probe"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"
|
||||
|
||||
[[package]]
|
||||
name = "openssl-src"
|
||||
version = "300.5.5+3.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f1787d533e03597a7934fd0a765f0d28e94ecc5fb7789f8053b1e699a56f709"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.117"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"openssl-src",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "option-ext"
|
||||
version = "0.2.0"
|
||||
@@ -3218,6 +3130,7 @@ version = "0.11.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"bytes",
|
||||
"getrandom 0.3.4",
|
||||
"lru-slab",
|
||||
@@ -3411,50 +3324,6 @@ version = "0.8.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.12.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
"encoding_rs",
|
||||
"futures-core",
|
||||
"h2",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-rustls",
|
||||
"hyper-tls",
|
||||
"hyper-util",
|
||||
"js-sys",
|
||||
"log",
|
||||
"mime",
|
||||
"native-tls",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"quinn",
|
||||
"rustls",
|
||||
"rustls-pki-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
"tokio-rustls",
|
||||
"tower",
|
||||
"tower-http",
|
||||
"tower-service",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.13.4"
|
||||
@@ -3469,15 +3338,22 @@ dependencies = [
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-rustls",
|
||||
"hyper-util",
|
||||
"js-sys",
|
||||
"log",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"quinn",
|
||||
"rustls",
|
||||
"rustls-pki-types",
|
||||
"rustls-platform-verifier",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-util",
|
||||
"tower",
|
||||
"tower-http",
|
||||
@@ -3557,14 +3433,26 @@ version = "0.23.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c54fcab019b409d04215d3a17cb438fd7fbf192ee61461f20f4fe18704bc138"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"once_cell",
|
||||
"ring",
|
||||
"rustls-pki-types",
|
||||
"rustls-webpki",
|
||||
"subtle",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-native-certs"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63"
|
||||
dependencies = [
|
||||
"openssl-probe",
|
||||
"rustls-pki-types",
|
||||
"schannel",
|
||||
"security-framework",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-pki-types"
|
||||
version = "1.15.0"
|
||||
@@ -3575,12 +3463,40 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-platform-verifier"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784"
|
||||
dependencies = [
|
||||
"core-foundation",
|
||||
"core-foundation-sys",
|
||||
"jni",
|
||||
"log",
|
||||
"once_cell",
|
||||
"rustls",
|
||||
"rustls-native-certs",
|
||||
"rustls-platform-verifier-android",
|
||||
"rustls-webpki",
|
||||
"security-framework",
|
||||
"security-framework-sys",
|
||||
"webpki-root-certs",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-platform-verifier-android"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f"
|
||||
|
||||
[[package]]
|
||||
name = "rustls-webpki"
|
||||
version = "0.103.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"ring",
|
||||
"rustls-pki-types",
|
||||
"untrusted",
|
||||
@@ -3680,7 +3596,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"core-foundation 0.10.1",
|
||||
"core-foundation",
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
"security-framework-sys",
|
||||
@@ -4351,27 +4267,6 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-configuration"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"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"
|
||||
@@ -4393,7 +4288,7 @@ checksum = "d1c93047acf68669466a34690ac58cca7010bd1b201e1ec86f1fd0a75d3dd4a9"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"block2",
|
||||
"core-foundation 0.10.1",
|
||||
"core-foundation",
|
||||
"core-graphics",
|
||||
"crossbeam-channel",
|
||||
"dbus",
|
||||
@@ -4472,7 +4367,7 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
"plist",
|
||||
"raw-window-handle",
|
||||
"reqwest 0.13.4",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
@@ -4836,16 +4731,6 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-native-tls"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
|
||||
dependencies = [
|
||||
"native-tls",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.26.4"
|
||||
@@ -5480,10 +5365,10 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "1.0.7"
|
||||
name = "webpki-root-certs"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52f5ee44c96cf55f1b349600768e3ece3a8f26010c05265ab73f945bb1a2eb9d"
|
||||
checksum = "804f18a4ac2676ffb4e8b5b5fa9ae38af06df08162314f96a68d2a363e21a8ca"
|
||||
dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
@@ -5683,17 +5568,6 @@ 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"
|
||||
|
||||
@@ -26,5 +26,4 @@ tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||
reqwest = { version = "0.12", features = ["json", "rustls-tls"] }
|
||||
openssl-sys = { version = "0.9", features = ["vendored"] }
|
||||
reqwest = { version = "0.13", default-features = false, features = ["json", "query", "rustls"] }
|
||||
|
||||
+168
-22
@@ -1,6 +1,8 @@
|
||||
pub mod apps;
|
||||
pub mod sync;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use che_orm::SqliteBackend;
|
||||
use che_tauri::{
|
||||
ApiError, ApiRequest, AppConfig, AppState, AuthTokenResponse, DatabaseConfig, RemoteConfig,
|
||||
@@ -10,6 +12,108 @@ use tauri::Manager;
|
||||
|
||||
use crate::sync::SyncContractsResult;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
const REMOTE_BASE_URL: &str = "http://10.0.2.2:8000";
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
const REMOTE_BASE_URL: &str = "http://127.0.0.1:8000";
|
||||
|
||||
const DEFAULT_AUTH_PATH: &str = "/api-token-auth/";
|
||||
|
||||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
|
||||
struct AppSettings {
|
||||
remote_base_url: String,
|
||||
auth_path: String,
|
||||
}
|
||||
|
||||
impl Default for AppSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
remote_base_url: String::from(REMOTE_BASE_URL),
|
||||
auth_path: String::from(DEFAULT_AUTH_PATH),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn build_api(database_url: String, settings: AppSettings) -> Result<TauriApi, ApiError> {
|
||||
let config = AppConfig {
|
||||
database: DatabaseConfig { url: database_url },
|
||||
remote: Some(settings_to_remote_config(&settings)),
|
||||
};
|
||||
let db = SqliteBackend::connect(&config.database.url).await?;
|
||||
let state = AppState::new(config, db);
|
||||
|
||||
TauriApi::new(state)
|
||||
.install(apps::installed_apps())
|
||||
.build()
|
||||
.await
|
||||
}
|
||||
|
||||
fn settings_to_remote_config(settings: &AppSettings) -> RemoteConfig {
|
||||
RemoteConfig {
|
||||
base_url: normalize_base_url(&settings.remote_base_url),
|
||||
auth_path: Some(normalize_auth_path(&settings.auth_path)),
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_settings(settings: AppSettings) -> AppSettings {
|
||||
AppSettings {
|
||||
remote_base_url: normalize_base_url(&settings.remote_base_url),
|
||||
auth_path: normalize_auth_path(&settings.auth_path),
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_base_url(base_url: &str) -> String {
|
||||
base_url.trim().trim_end_matches('/').to_string()
|
||||
}
|
||||
|
||||
fn normalize_auth_path(auth_path: &str) -> String {
|
||||
let clean = auth_path.trim().trim_matches('/');
|
||||
if clean.is_empty() {
|
||||
String::from(DEFAULT_AUTH_PATH)
|
||||
} else {
|
||||
format!("/{clean}/")
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_settings(settings: &AppSettings) -> Result<(), ApiError> {
|
||||
if !(settings.remote_base_url.starts_with("http://")
|
||||
|| settings.remote_base_url.starts_with("https://"))
|
||||
{
|
||||
return Err(ApiError::bad_request(
|
||||
"Удаленный URL должен начинаться с http:// или https://",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn settings_path(app_data_dir: &Path) -> PathBuf {
|
||||
app_data_dir.join("settings.json")
|
||||
}
|
||||
|
||||
async fn load_settings(app_data_dir: &Path) -> Result<AppSettings, ApiError> {
|
||||
let path = settings_path(app_data_dir);
|
||||
match tokio::fs::read_to_string(path).await {
|
||||
Ok(content) => serde_json::from_str::<AppSettings>(&content)
|
||||
.map(normalize_settings)
|
||||
.map_err(|error| ApiError::new("settings_error", error.to_string())),
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(AppSettings::default()),
|
||||
Err(error) => Err(ApiError::new("settings_error", error.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
async fn save_settings(app_data_dir: &Path, settings: &AppSettings) -> Result<(), ApiError> {
|
||||
tokio::fs::create_dir_all(app_data_dir)
|
||||
.await
|
||||
.map_err(|error| ApiError::new("settings_error", error.to_string()))?;
|
||||
let content = serde_json::to_string_pretty(settings)
|
||||
.map_err(|error| ApiError::new("settings_error", error.to_string()))?;
|
||||
tokio::fs::write(settings_path(app_data_dir), content)
|
||||
.await
|
||||
.map_err(|error| ApiError::new("settings_error", error.to_string()))
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct CurrentEmployee {
|
||||
id: i64,
|
||||
@@ -55,9 +159,57 @@ fn auth_status(api: tauri::State<'_, TauriApi>) -> bool {
|
||||
api.is_authenticated()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn get_app_settings(app: tauri::AppHandle) -> Result<AppSettings, ApiError> {
|
||||
let app_data_dir = app
|
||||
.path()
|
||||
.app_data_dir()
|
||||
.map_err(|error| ApiError::new("settings_error", error.to_string()))?;
|
||||
load_settings(&app_data_dir).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn update_app_settings(
|
||||
app: tauri::AppHandle,
|
||||
api: tauri::State<'_, TauriApi>,
|
||||
settings: AppSettings,
|
||||
) -> Result<AppSettings, ApiError> {
|
||||
let settings = normalize_settings(settings);
|
||||
validate_settings(&settings)?;
|
||||
|
||||
let app_data_dir = app
|
||||
.path()
|
||||
.app_data_dir()
|
||||
.map_err(|error| ApiError::new("settings_error", error.to_string()))?;
|
||||
save_settings(&app_data_dir, &settings).await?;
|
||||
api.state()
|
||||
.set_remote_config(Some(settings_to_remote_config(&settings)));
|
||||
api.logout();
|
||||
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn reset_app_settings(
|
||||
app: tauri::AppHandle,
|
||||
api: tauri::State<'_, TauriApi>,
|
||||
) -> Result<AppSettings, ApiError> {
|
||||
let settings = AppSettings::default();
|
||||
let app_data_dir = app
|
||||
.path()
|
||||
.app_data_dir()
|
||||
.map_err(|error| ApiError::new("settings_error", error.to_string()))?;
|
||||
save_settings(&app_data_dir, &settings).await?;
|
||||
api.state()
|
||||
.set_remote_config(Some(settings_to_remote_config(&settings)));
|
||||
api.logout();
|
||||
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn current_employee(api: tauri::State<'_, TauriApi>) -> Result<CurrentEmployee, ApiError> {
|
||||
let remote = api.state().config.remote.as_ref().ok_or_else(|| {
|
||||
let remote = api.state().remote_config().ok_or_else(|| {
|
||||
ApiError::bad_request("current_employee requires [remote].base_url config")
|
||||
})?;
|
||||
|
||||
@@ -145,29 +297,20 @@ pub fn run() {
|
||||
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
||||
}
|
||||
|
||||
let api = tauri::async_runtime::block_on(async {
|
||||
// let state = AppState::from_config_file("app.toml").await?;
|
||||
let config = AppConfig {
|
||||
database: DatabaseConfig {
|
||||
url: String::from("sqlite://ewa-mobile.sqlite?mode=rwc"),
|
||||
},
|
||||
remote: Some(RemoteConfig {
|
||||
base_url: String::from("http://127.0.0.1:8000/"),
|
||||
auth_path: Some(String::from(" /api-token-auth/")),
|
||||
}),
|
||||
};
|
||||
let db = SqliteBackend::connect(&config.database.url).await?;
|
||||
let state = AppState::new(config, db);
|
||||
TauriApi::new(state)
|
||||
.install(apps::installed_apps())
|
||||
.build()
|
||||
.await
|
||||
})
|
||||
.expect("failed to initialize che-tauri");
|
||||
|
||||
tauri::Builder::default()
|
||||
.manage(api)
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.setup(|app| {
|
||||
let app_data_dir = app.path().app_data_dir()?;
|
||||
std::fs::create_dir_all(&app_data_dir)?;
|
||||
let database_path = app_data_dir.join("ewa-mobile.sqlite");
|
||||
let database_url = format!("sqlite://{}?mode=rwc", database_path.to_string_lossy());
|
||||
let settings = tauri::async_runtime::block_on(load_settings(&app_data_dir))
|
||||
.map_err(|error| Box::<dyn std::error::Error>::from(error.to_string()))?;
|
||||
let api = tauri::async_runtime::block_on(build_api(database_url, settings))
|
||||
.map_err(|error| Box::<dyn std::error::Error>::from(error.to_string()))?;
|
||||
app.manage(api);
|
||||
Ok(())
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
greet,
|
||||
che_api,
|
||||
@@ -175,6 +318,9 @@ pub fn run() {
|
||||
auth_set_token,
|
||||
auth_logout,
|
||||
auth_status,
|
||||
get_app_settings,
|
||||
update_app_settings,
|
||||
reset_app_settings,
|
||||
current_employee,
|
||||
sync_contracts,
|
||||
load_application_file
|
||||
|
||||
@@ -165,9 +165,7 @@ pub async fn sync_contracts(
|
||||
.auth_token()
|
||||
.ok_or_else(|| ApiError::new("not_authenticated", "authentication token is missing"))?;
|
||||
let remote = state
|
||||
.config
|
||||
.remote
|
||||
.as_ref()
|
||||
.remote_config()
|
||||
.ok_or_else(|| ApiError::bad_request("sync requires [remote].base_url config"))?;
|
||||
let client = reqwest::Client::new();
|
||||
sync_contract_categories(api, &client, &token, &remote.base_url).await?;
|
||||
|
||||
@@ -13,6 +13,10 @@ const activeTab = computed({
|
||||
return "/contracts";
|
||||
}
|
||||
|
||||
if (route.path.startsWith("/settings")) {
|
||||
return "/settings";
|
||||
}
|
||||
|
||||
return route.path.startsWith("/users") ? "/users" : "/tasks";
|
||||
},
|
||||
set(path: string) {
|
||||
@@ -63,6 +67,9 @@ async function logoutAndRedirect() {
|
||||
<van-tabbar-item to="/users" name="/users" icon="friends-o"
|
||||
>Пользователи</van-tabbar-item
|
||||
>
|
||||
<van-tabbar-item to="/settings" name="/settings" icon="setting-o"
|
||||
>Настройки</van-tabbar-item
|
||||
>
|
||||
</van-tabbar>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createRouter, createWebHashHistory } from "vue-router";
|
||||
import { isAuthenticated, useAuth } from "../../shared/auth/useAuth";
|
||||
import { loginRoute } from "../../apps/auth/routes";
|
||||
import { contractsRoutes } from "../../apps/contracts/routes";
|
||||
import { settingsRoute } from "../../apps/settings/routes";
|
||||
import { tasksRoutes } from "../../apps/tasks/routes";
|
||||
import { usersRoutes } from "../../apps/users/routes";
|
||||
|
||||
@@ -15,6 +16,7 @@ export const router = createRouter({
|
||||
...tasksRoutes,
|
||||
...usersRoutes,
|
||||
...contractsRoutes,
|
||||
settingsRoute,
|
||||
loginRoute,
|
||||
],
|
||||
});
|
||||
|
||||
@@ -82,6 +82,17 @@ function errorMessage(err: unknown) {
|
||||
<van-button block round type="primary" native-type="submit" :loading="loading">
|
||||
Войти
|
||||
</van-button>
|
||||
<van-button
|
||||
block
|
||||
round
|
||||
plain
|
||||
type="primary"
|
||||
native-type="button"
|
||||
:disabled="loading"
|
||||
@click="router.push('/settings')"
|
||||
>
|
||||
Настройки сервера
|
||||
</van-button>
|
||||
</div>
|
||||
</van-form>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import SettingsView from "./views/SettingsView.vue";
|
||||
|
||||
export const settingsRoute = {
|
||||
path: "/settings",
|
||||
name: "settings",
|
||||
component: SettingsView,
|
||||
meta: { title: "Настройки" },
|
||||
};
|
||||
@@ -0,0 +1,160 @@
|
||||
<script setup lang="ts">
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { onMounted, reactive, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { showToast } from "vant";
|
||||
import { clearAuthState } from "../../../shared/auth/useAuth";
|
||||
|
||||
interface AppSettings {
|
||||
remote_base_url: string;
|
||||
auth_path: string;
|
||||
}
|
||||
|
||||
const router = useRouter();
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const error = ref("");
|
||||
const settings = reactive<AppSettings>({
|
||||
remote_base_url: "",
|
||||
auth_path: "/api-token-auth/",
|
||||
});
|
||||
|
||||
onMounted(loadSettings);
|
||||
|
||||
async function loadSettings() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
|
||||
try {
|
||||
applySettings(await invoke<AppSettings>("get_app_settings"));
|
||||
} catch (err) {
|
||||
error.value = errorMessage(err, "Не удалось загрузить настройки");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveSettings() {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
|
||||
try {
|
||||
const saved = await invoke<AppSettings>("update_app_settings", {
|
||||
settings: {
|
||||
remote_base_url: settings.remote_base_url,
|
||||
auth_path: settings.auth_path,
|
||||
},
|
||||
});
|
||||
applySettings(saved);
|
||||
clearAuthState();
|
||||
showToast("Настройки сохранены. Войдите заново");
|
||||
router.replace("/login");
|
||||
} catch (err) {
|
||||
error.value = errorMessage(err, "Не удалось сохранить настройки");
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function resetSettings() {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
|
||||
try {
|
||||
applySettings(await invoke<AppSettings>("reset_app_settings"));
|
||||
clearAuthState();
|
||||
showToast("Настройки сброшены. Войдите заново");
|
||||
router.replace("/login");
|
||||
} catch (err) {
|
||||
error.value = errorMessage(err, "Не удалось сбросить настройки");
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function applySettings(nextSettings: AppSettings) {
|
||||
settings.remote_base_url = nextSettings.remote_base_url;
|
||||
settings.auth_path = nextSettings.auth_path;
|
||||
}
|
||||
|
||||
function errorMessage(err: unknown, fallback: string) {
|
||||
if (typeof err === "object" && err && "detail" in err) {
|
||||
return String((err as { detail: unknown }).detail);
|
||||
}
|
||||
|
||||
if (err instanceof Error) {
|
||||
return err.message;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<van-notice-bar
|
||||
v-if="error"
|
||||
class="notice"
|
||||
color="#991b1b"
|
||||
background="#fee2e2"
|
||||
left-icon="warning-o"
|
||||
wrapable
|
||||
:scrollable="false"
|
||||
:text="error"
|
||||
/>
|
||||
|
||||
<van-form class="card" @submit="saveSettings">
|
||||
<van-loading v-if="loading" class="state" type="spinner">Загрузка...</van-loading>
|
||||
|
||||
<template v-else>
|
||||
<van-field
|
||||
v-model="settings.remote_base_url"
|
||||
name="remote_base_url"
|
||||
label="Удаленный URL"
|
||||
placeholder="http://10.0.2.2:8000"
|
||||
clearable
|
||||
:disabled="saving"
|
||||
:rules="[{ required: true, message: 'Введите URL сервера' }]"
|
||||
/>
|
||||
<van-field
|
||||
v-model="settings.auth_path"
|
||||
name="auth_path"
|
||||
label="Auth path"
|
||||
placeholder="/api-token-auth/"
|
||||
clearable
|
||||
:disabled="saving"
|
||||
:rules="[{ required: true, message: 'Введите путь авторизации' }]"
|
||||
/>
|
||||
|
||||
<div class="settings-help">
|
||||
Для Android-эмулятора сервер на хосте обычно доступен как
|
||||
<code>http://10.0.2.2:8000</code>.
|
||||
</div>
|
||||
|
||||
<div class="form-actions stacked-actions">
|
||||
<van-button block round type="primary" native-type="submit" :loading="saving">
|
||||
Сохранить
|
||||
</van-button>
|
||||
<van-button
|
||||
block
|
||||
round
|
||||
type="default"
|
||||
native-type="button"
|
||||
plain
|
||||
:disabled="saving"
|
||||
@click="resetSettings"
|
||||
>
|
||||
Сбросить по умолчанию
|
||||
</van-button>
|
||||
</div>
|
||||
</template>
|
||||
</van-form>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.settings-help {
|
||||
padding: 12px 16px 0;
|
||||
color: #64748b;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
@@ -18,9 +18,7 @@ export function useAuth() {
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
authToken.value = "";
|
||||
localStorage.removeItem(TOKEN_STORAGE_KEY);
|
||||
restored = false;
|
||||
clearAuthState();
|
||||
await invoke("auth_logout");
|
||||
}
|
||||
|
||||
@@ -36,12 +34,19 @@ export function useAuth() {
|
||||
return {
|
||||
authToken,
|
||||
isAuthenticated,
|
||||
clearAuthState,
|
||||
login,
|
||||
logout,
|
||||
restoreToken,
|
||||
};
|
||||
}
|
||||
|
||||
export function clearAuthState() {
|
||||
authToken.value = "";
|
||||
localStorage.removeItem(TOKEN_STORAGE_KEY);
|
||||
restored = false;
|
||||
}
|
||||
|
||||
export function isAuthenticated() {
|
||||
return Boolean(authToken.value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user