Merge remote-tracking branch 'origin/v1' into chore/merge-v1-into-v2

This commit is contained in:
FabianLars
2024-04-15 18:23:45 +02:00
65 changed files with 1075 additions and 371 deletions
@@ -0,0 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/
gen/schemas
@@ -0,0 +1,24 @@
[package]
name = "app_settings_manager"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { workspace = true }
[dependencies]
tauri = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tauri-plugin-store = { path = "../../../" }
[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
prod = ["tauri/custom-protocol"]
@@ -0,0 +1,7 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
tauri_build::build()
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

@@ -0,0 +1,5 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
pub mod settings;
@@ -0,0 +1,33 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use tauri_plugin_store::Store;
#[derive(Debug, Clone)]
pub struct AppSettings {
pub launch_at_login: bool,
pub theme: String,
}
impl AppSettings {
pub fn load_from_store<R: tauri::Runtime>(
store: &Store<R>,
) -> Result<Self, Box<dyn std::error::Error>> {
let launch_at_login = store
.get("appSettings.launchAtLogin")
.and_then(|v| v.as_bool())
.unwrap_or(false);
let theme = store
.get("appSettings.theme")
.and_then(|v| v.as_str())
.map(|s| s.to_string())
.unwrap_or_else(|| "dark".to_string());
Ok(AppSettings {
launch_at_login,
theme,
})
}
}
@@ -0,0 +1,44 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri_plugin_store::StoreBuilder;
mod app;
use app::settings::AppSettings;
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
// Init store and load it from disk
let mut store = StoreBuilder::new("settings.json").build(app.handle().clone());
// If there are no saved settings yet, this will return an error so we ignore the return value.
let _ = store.load();
let app_settings = AppSettings::load_from_store(&store);
match app_settings {
Ok(app_settings) => {
let theme = app_settings.theme;
let launch_at_login = app_settings.launch_at_login;
println!("theme {}", theme);
println!("launch_at_login {}", launch_at_login);
Ok(())
}
Err(err) => {
eprintln!("Error loading settings: {}", err);
// Handle the error case if needed
Err(err) // Convert the error to a Box<dyn Error> and return Err(err) here
}
}
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
@@ -0,0 +1,33 @@
{
"productName": "app",
"version": "0.1.0",
"identifier": "com.tauri.app-settings-manager",
"build": {
"frontendDist": "../dist"
},
"app": {
"windows": [
{
"title": "app",
"width": 800,
"height": 600,
"resizable": true,
"fullscreen": false
}
],
"security": {
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: http://tauri.localhost 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'"
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}