This commit is contained in:
che
2026-07-26 20:30:38 +05:00
parent 1441a14b90
commit 560b3fe44e
12 changed files with 908 additions and 271 deletions
+111 -237
View File
@@ -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"
+1 -2
View File
@@ -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
View File
@@ -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
+1 -3
View 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?;