Skip to content

Commit a176114

Browse files
committed
fix: release permissions
1 parent e1e3eb4 commit a176114

File tree

6 files changed

+32
-20
lines changed

6 files changed

+32
-20
lines changed

src-tauri/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55
/project_db/
66
/query_db/
7-
7+
/Cache/
8+
/AppData/
9+
/projects/

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ edition = "2021"
1313
tauri-build = { version = "1.5", features = [] }
1414

1515
[dependencies]
16-
tauri = { version = "1.5.2", features = ["shell-open"] }
16+
tauri = { version = "1.5.2", features = [ "shell-open", "fs-all"] }
1717
serde = { version = "1.0.193", features = ["derive"] }
1818
serde_json = "1.0.108"
1919
tokio = "1.34.0"

src-tauri/src/main.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ impl Default for AppState {
2828
Self {
2929
connection_strings: Arc::new(Mutex::new(String::new())),
3030
client: Arc::new(Mutex::new(None)),
31-
project_db: Arc::new(Mutex::new(Some(
32-
sled::open(constant::PROJECT_DB_PATH).unwrap(),
33-
))),
34-
query_db: Arc::new(Mutex::new(Some(
35-
sled::open(constant::QUERY_DB_PATH).unwrap(),
36-
))),
31+
project_db: Arc::new(Mutex::new(None)),
32+
query_db: Arc::new(Mutex::new(None)),
3733
}
3834
}
3935
}

src-tauri/src/postgres.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
use tauri::{Result, State};
1+
use tauri::{AppHandle, Manager, Result, State};
22
use tokio_postgres::{connect, NoTls};
33

4-
use crate::{utils::reflective_get, AppState};
4+
use crate::{constant::PROJECT_DB_PATH, utils::reflective_get, AppState};
55

66
#[tauri::command]
7-
pub async fn pg_connector(
8-
project: &str,
9-
key: &str,
10-
app_state: State<'_, AppState>,
11-
) -> Result<Vec<String>> {
12-
let db = app_state.project_db.lock().await;
7+
pub async fn pg_connector(project: &str, key: &str, app: AppHandle) -> Result<Vec<String>> {
8+
let app_state = app.state::<AppState>();
9+
let mut db = app_state.project_db.lock().await;
10+
if db.clone().is_none() {
11+
let app_dir = app.path_resolver().app_data_dir().unwrap();
12+
let db_path = app_dir.join(PROJECT_DB_PATH);
13+
let _db = sled::open(db_path).unwrap();
14+
*db = Some(_db);
15+
}
1316
db.clone().unwrap().insert(project, key).unwrap();
1417

1518
let (client, connection) = connect(key, NoTls).await.expect("connection error");

src-tauri/src/project_db.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::Serialize;
2-
use tauri::{Result, State};
2+
use tauri::{AppHandle, Manager, Result, State};
33

4-
use crate::AppState;
4+
use crate::{constant::PROJECT_DB_PATH, AppState};
55

66
#[derive(Default, Serialize)]
77
pub struct ProjectDetails {
@@ -12,8 +12,15 @@ pub struct ProjectDetails {
1212
}
1313

1414
#[tauri::command]
15-
pub async fn get_projects(app_state: State<'_, AppState>) -> Result<Vec<String>> {
16-
let db = app_state.project_db.lock().await;
15+
pub async fn get_projects(app: AppHandle) -> Result<Vec<String>> {
16+
let app_state = app.state::<AppState>();
17+
let mut db = app_state.project_db.lock().await;
18+
if db.clone().is_none() {
19+
let app_dir = app.path_resolver().app_data_dir().unwrap();
20+
let db_path = app_dir.join(PROJECT_DB_PATH);
21+
let _db = sled::open(db_path).unwrap();
22+
*db = Some(_db);
23+
}
1724
let db = db.clone().unwrap();
1825
let projects = db
1926
.iter()

src-tauri/tauri.conf.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"tauri": {
1414
"allowlist": {
1515
"all": false,
16+
"fs": {
17+
"all": true,
18+
"scope": ["$APPDATA/*"]
19+
},
1620
"shell": {
1721
"all": false,
1822
"open": true

0 commit comments

Comments
 (0)