-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add dark mode and serialization
- Loading branch information
Showing
12 changed files
with
189 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::error::{ | ||
self, | ||
configuration_error::{AppConfIoError, ConfigurationErrorKind}, | ||
ConfigurationError, Error, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
use snafu::ResultExt; | ||
use std::{fs, path::Path}; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub(crate) struct AppSetting { | ||
theme: String, | ||
} | ||
|
||
impl Default for AppSetting { | ||
fn default() -> Self { | ||
Self { | ||
theme: String::from("dark"), | ||
} | ||
} | ||
} | ||
|
||
pub(super) fn read_app_setting<P: AsRef<Path>>(path: P) -> Result<AppSetting, error::Error> { | ||
let content_raw = fs::read(path) | ||
.context(AppConfIoError {}) | ||
.context(ConfigurationError { | ||
scenario: "read file", | ||
})?; | ||
|
||
let content_str = String::from_utf8(content_raw).map_err(|err| Error::Configuration { | ||
scenario: "read as utf8", | ||
source: ConfigurationErrorKind::AppSettingFmt { | ||
msg: format!("{err}"), | ||
}, | ||
})?; | ||
|
||
let conf: AppSetting = | ||
serde_json::from_str(content_str.as_str()).map_err(|err| Error::Configuration { | ||
scenario: "deserialize with serde_json", | ||
source: ConfigurationErrorKind::AppSettingFmt { | ||
msg: format!("{err}"), | ||
}, | ||
})?; | ||
|
||
Ok(conf) | ||
} | ||
|
||
pub(super) fn write_app_setting<P: AsRef<Path>>( | ||
path: P, | ||
conf: AppSetting, | ||
) -> Result<(), error::Error> { | ||
let str = serde_json::to_string(&conf).map_err(|err| Error::Configuration { | ||
scenario: "serialized as string", | ||
source: ConfigurationErrorKind::AppSettingFmt { | ||
msg: format!("{err}"), | ||
}, | ||
})?; | ||
|
||
fs::write(path, str) | ||
.context(AppConfIoError {}) | ||
.context(ConfigurationError { | ||
scenario: "write to disk", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use crate::app_conf; | ||
|
||
#[tauri::command] | ||
pub async fn set_app_setting(setting: app_conf::AppSetting) -> () { | ||
log::trace!("set_app_setting, {:?}", setting); | ||
|
||
app_conf::save_app_setting(setting); | ||
} | ||
|
||
#[tauri::command] | ||
pub async fn get_app_setting() -> app_conf::AppSetting { | ||
app_conf::get_app_setting() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod processor; | ||
pub mod ca; | ||
pub mod global_proxy; | ||
pub mod global_proxy; | ||
pub mod app_setting; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,33 @@ | ||
use tauri::{LogicalSize, Size, Window}; | ||
use std::process::Command; | ||
|
||
use tauri::{CustomMenuItem, LogicalSize, Menu, Size, Submenu, Window, WindowMenuEvent}; | ||
|
||
use crate::app_conf::{self}; | ||
|
||
pub fn initial_window(win: Window) -> () { | ||
win.set_size(Size::Logical(LogicalSize { | ||
width: 1200.0, | ||
height: 800.0, | ||
})) | ||
.unwrap(); | ||
|
||
win.center().unwrap(); | ||
} | ||
|
||
pub fn initial_menu() -> Menu { | ||
Menu::new() | ||
.add_submenu(Submenu::new("proxyman", Menu::new())) | ||
.add_submenu(Submenu::new( | ||
"帮助", | ||
Menu::new().add_item(CustomMenuItem::new("openlog", "打开日志文件")), | ||
)) | ||
} | ||
|
||
win | ||
.set_size(Size::Logical(LogicalSize { | ||
width: 1200.0, | ||
height: 800.0, | ||
})) | ||
.unwrap(); | ||
} | ||
pub fn register_menu_events(event: WindowMenuEvent) { | ||
match event.menu_item_id() { | ||
"openlog" => { | ||
Command::new("open").arg(app_conf::app_dir().as_os_str()).output().unwrap(); | ||
}, | ||
_ => {} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters