pref: 缓存显示器参数读数。#5.

This commit is contained in:
2023-02-18 14:47:41 +08:00
parent 070100cdbc
commit 550328ba1e
10 changed files with 245 additions and 51 deletions

25
src-tauri/src/db/db.rs Normal file
View File

@@ -0,0 +1,25 @@
use std::env::current_dir;
use once_cell::sync::OnceCell;
use redb::Database;
use tauri::api::path::config_dir;
use crate::picker;
trait GlobalDatabase<T> {
fn global() -> &'static T;
}
impl GlobalDatabase<Database> for Database {
fn global() -> &'static Database {
static GLOBAL_DATABASE: OnceCell<Database> = OnceCell::new();
GLOBAL_DATABASE.get_or_init(|| {
let path = config_dir()
.unwrap_or(current_dir().unwrap())
.join("main.redb");
let db = Database::create(path).unwrap();
return db;
})
}
}

3
src-tauri/src/db/mod.rs Normal file
View File

@@ -0,0 +1,3 @@
mod db;
pub use db::*;