Skip to content

Commit

Permalink
v0.1.3
Browse files Browse the repository at this point in the history
* Hide CLI on Windows

* Refresh automatically on sync

* Move Database and Config File to Roaming instead of local appdata to avoid deletion of data on nsis upgrade
  • Loading branch information
0xGingi committed Nov 13, 2024
1 parent 0c52cd5 commit a2a502c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1.28", features = ["full"] }
futures = "0.3"
rand = "0.8"

[[bin]]
name = "rusty-notes"
path = "src/main.rs"
windows-subsystem = "windows"
22 changes: 8 additions & 14 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
mod types;
mod crypto;
mod sync;
Expand Down Expand Up @@ -36,12 +37,7 @@ fn get_settings_path(app_handle: &AppHandle) -> PathBuf {

#[tauri::command]
async fn get_sync_settings(app_handle: AppHandle) -> Result<SyncSettings, String> {
let app_dir = app_handle
.path()
.app_local_data_dir()
.expect("Failed to get app data directory");
let settings_path = app_dir.join("sync_settings.json");

let settings_path = get_settings_path(&app_handle);
println!("Loading settings from: {:?}", settings_path);

if settings_path.exists() {
Expand All @@ -61,15 +57,13 @@ async fn get_sync_settings(app_handle: AppHandle) -> Result<SyncSettings, String

#[tauri::command]
async fn save_sync_settings(app_handle: AppHandle, settings: SyncSettings) -> Result<(), String> {
let app_dir = app_handle
.path()
.app_local_data_dir()
.expect("Failed to get app data directory");
let settings_path = get_settings_path(&app_handle);

fs::create_dir_all(&app_dir)
.map_err(|e| format!("Failed to create settings directory: {}", e))?;
if let Some(parent) = settings_path.parent() {
fs::create_dir_all(parent)
.map_err(|e| format!("Failed to create settings directory: {}", e))?;
}

let settings_path = app_dir.join("sync_settings.json");
println!("Saving settings to: {:?}", settings_path);

let settings_str = serde_json::to_string_pretty(&settings)
Expand All @@ -85,7 +79,7 @@ async fn save_sync_settings(app_handle: AppHandle, settings: SyncSettings) -> Re
fn initialize_database(app_handle: &AppHandle) -> Result<Connection, rusqlite::Error> {
let app_dir = app_handle
.path()
.app_local_data_dir()
.app_data_dir()
.expect("Failed to get app local data directory");

fs::create_dir_all(&app_dir).expect("Failed to create app data directory");
Expand Down
16 changes: 13 additions & 3 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
{
"title": "rusty-notes",
"width": 800,
"height": 600
"height": 600,
"visible": true
}
],
"security": {
Expand All @@ -30,6 +31,15 @@
"icons/[email protected]",
"icons/icon.icns",
"icons/icon.ico"
]
],
"windows": {
"webviewInstallMode": {
"type": "downloadBootstrapper",
"silent": true
},
"nsis": {
"installMode": "currentUser"
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ async function handleSave() {
title="Sync Settings"
size="lg"
>
<SyncSettings />
<SyncSettings onSync={loadNotes} />
</Modal>
</AppShell>
);
Expand Down
12 changes: 11 additions & 1 deletion src/components/SyncSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ const DEFAULT_SERVERS = [
{ label: 'Local Server', value: 'http://localhost:3222' },
];

export function SyncSettings() {
interface SyncSettingsProps {
onSync?: () => Promise<void>;
}

export function SyncSettings({ onSync }: SyncSettingsProps) {
const [seedPhrase, setSeedPhrase] = useState('');
const [autoSync, setAutoSync] = useState(false);
const [showNewSeedPhrase, setShowNewSeedPhrase] = useState(false);
Expand Down Expand Up @@ -180,6 +184,12 @@ export function SyncSettings() {
seedPhrase,
serverUrl: selectedServer
});

// Call the onSync callback after successful sync
if (onSync) {
await onSync();
}

notifications.show({
title: 'Success',
message: 'Notes synced successfully',
Expand Down

0 comments on commit a2a502c

Please sign in to comment.