add preferences and macOS packaging
This commit is contained in:
@@ -4,10 +4,39 @@ use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::schema::{projects, sessions};
|
||||
use crate::schema::{preferences, projects, sessions};
|
||||
|
||||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
|
||||
|
||||
#[derive(Clone, Debug, Identifiable, Queryable, Selectable)]
|
||||
#[diesel(table_name = preferences)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct AppPreferences {
|
||||
pub id: i32,
|
||||
pub selected_model: String,
|
||||
pub dflash_enabled: bool,
|
||||
pub idle_timeout_minutes: i32,
|
||||
}
|
||||
|
||||
impl Default for AppPreferences {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
id: 1,
|
||||
selected_model: "deepseek-v4-flash".into(),
|
||||
dflash_enabled: false,
|
||||
idle_timeout_minutes: 10,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(AsChangeset)]
|
||||
#[diesel(table_name = preferences)]
|
||||
struct PreferenceChanges<'a> {
|
||||
selected_model: &'a str,
|
||||
dflash_enabled: bool,
|
||||
idle_timeout_minutes: i32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Identifiable, Queryable, Selectable)]
|
||||
#[diesel(table_name = projects)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
@@ -95,6 +124,31 @@ impl Database {
|
||||
.collect())
|
||||
}
|
||||
|
||||
pub fn load_preferences(&mut self) -> Result<AppPreferences, String> {
|
||||
preferences::table
|
||||
.find(1)
|
||||
.select(AppPreferences::as_select())
|
||||
.first(&mut self.connection)
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
pub fn update_preferences(
|
||||
&mut self,
|
||||
selected_model: &str,
|
||||
dflash_enabled: bool,
|
||||
idle_timeout_minutes: i32,
|
||||
) -> Result<AppPreferences, String> {
|
||||
diesel::update(preferences::table.find(1))
|
||||
.set(PreferenceChanges {
|
||||
selected_model,
|
||||
dflash_enabled,
|
||||
idle_timeout_minutes,
|
||||
})
|
||||
.returning(AppPreferences::as_returning())
|
||||
.get_result(&mut self.connection)
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
pub fn create_project(&mut self, name: &str, path: &str) -> Result<Project, String> {
|
||||
diesel::insert_into(projects::table)
|
||||
.values(NewProject { name, path })
|
||||
@@ -144,6 +198,18 @@ mod tests {
|
||||
let path = std::env::temp_dir().join(format!("ds4-server-{id}.sqlite3"));
|
||||
let mut database = Database::open(&path).unwrap();
|
||||
|
||||
let preferences = database.load_preferences().unwrap();
|
||||
assert_eq!(preferences.selected_model, "deepseek-v4-flash");
|
||||
assert!(!preferences.dflash_enabled);
|
||||
assert_eq!(preferences.idle_timeout_minutes, 10);
|
||||
assert!(database.update_preferences("glm-5.2", true, 30).is_err());
|
||||
assert!(
|
||||
database
|
||||
.update_preferences("deepseek-v4-flash", false, 0)
|
||||
.is_err()
|
||||
);
|
||||
database.update_preferences("glm-5.2", false, 30).unwrap();
|
||||
|
||||
let project = database.create_project("DS4", "/tmp/ds4").unwrap();
|
||||
let first = database
|
||||
.create_session(project.id, "First session")
|
||||
@@ -158,6 +224,12 @@ mod tests {
|
||||
database.delete_project(project.id).unwrap();
|
||||
assert!(database.load_projects().unwrap().is_empty());
|
||||
drop(database);
|
||||
|
||||
let mut reopened = Database::open(&path).unwrap();
|
||||
let preferences = reopened.load_preferences().unwrap();
|
||||
assert_eq!(preferences.selected_model, "glm-5.2");
|
||||
assert_eq!(preferences.idle_timeout_minutes, 30);
|
||||
drop(reopened);
|
||||
fs::remove_file(path).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
421
src/main.rs
421
src/main.rs
@@ -1,13 +1,15 @@
|
||||
mod database;
|
||||
mod schema;
|
||||
|
||||
use database::{Database, ProjectWithSessions, Session};
|
||||
use iced::theme::Palette;
|
||||
use database::{AppPreferences, Database, ProjectWithSessions, Session};
|
||||
use iced::theme::{Palette, palette};
|
||||
use iced::widget::{
|
||||
Space, Svg, button, column, container, opaque, row, scrollable, stack, svg, text, text_input,
|
||||
Space, Svg, button, checkbox, column, container, opaque, pick_list, row, scrollable, stack,
|
||||
svg, text, text_input,
|
||||
};
|
||||
use iced::{Alignment, Color, Element, Length, Size, Task, Theme};
|
||||
use iced::{Alignment, Color, Element, Length, Size, Subscription, Task, Theme, keyboard};
|
||||
use rfd::AsyncFileDialog;
|
||||
use std::fmt;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@@ -16,7 +18,7 @@ const ICON_FOLDER: &[u8] = include_bytes!("../assets/icons/folder.svg");
|
||||
const ICON_FOLDER_PLUS: &[u8] = include_bytes!("../assets/icons/folder-plus.svg");
|
||||
const ICON_NEW_SESSION: &[u8] = include_bytes!("../assets/icons/new-session.svg");
|
||||
const ICON_CHAT: &[u8] = include_bytes!("../assets/icons/chat.svg");
|
||||
const ICON_SEARCH: &[u8] = include_bytes!("../assets/icons/search.svg");
|
||||
const ICON_SETTINGS: &[u8] = include_bytes!("../assets/icons/settings.svg");
|
||||
const ICON_TRASH: &[u8] = include_bytes!("../assets/icons/trash.svg");
|
||||
const ICON_MORE: &[u8] = include_bytes!("../assets/icons/more.svg");
|
||||
const ICON_PAPERCLIP: &[u8] = include_bytes!("../assets/icons/paperclip.svg");
|
||||
@@ -24,20 +26,71 @@ const ICON_SEND: &[u8] = include_bytes!("../assets/icons/send.svg");
|
||||
const ICON_MODEL: &[u8] = include_bytes!("../assets/icons/model.svg");
|
||||
const ICON_SPARK: &[u8] = include_bytes!("../assets/icons/spark.svg");
|
||||
|
||||
const MODEL_CHOICES: [ModelChoice; 3] = [
|
||||
ModelChoice::DeepSeekV4Flash,
|
||||
ModelChoice::DeepSeekV4Pro,
|
||||
ModelChoice::Glm52,
|
||||
];
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
enum ModelChoice {
|
||||
#[default]
|
||||
DeepSeekV4Flash,
|
||||
DeepSeekV4Pro,
|
||||
Glm52,
|
||||
}
|
||||
|
||||
impl ModelChoice {
|
||||
fn id(self) -> &'static str {
|
||||
match self {
|
||||
Self::DeepSeekV4Flash => "deepseek-v4-flash",
|
||||
Self::DeepSeekV4Pro => "deepseek-v4-pro",
|
||||
Self::Glm52 => "glm-5.2",
|
||||
}
|
||||
}
|
||||
|
||||
fn from_id(id: &str) -> Option<Self> {
|
||||
MODEL_CHOICES.into_iter().find(|model| model.id() == id)
|
||||
}
|
||||
|
||||
fn supports_dflash(self) -> bool {
|
||||
self == Self::DeepSeekV4Flash
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ModelChoice {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter.write_str(match self {
|
||||
Self::DeepSeekV4Flash => "DeepSeek V4 Flash",
|
||||
Self::DeepSeekV4Pro => "DeepSeek V4 Pro",
|
||||
Self::Glm52 => "GLM 5.2",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct PreferenceDraft {
|
||||
model: ModelChoice,
|
||||
dflash_enabled: bool,
|
||||
idle_timeout_minutes: String,
|
||||
}
|
||||
|
||||
impl PreferenceDraft {
|
||||
fn from_saved(preferences: &AppPreferences) -> Result<Self, String> {
|
||||
let model = ModelChoice::from_id(&preferences.selected_model)
|
||||
.ok_or_else(|| format!("Unsupported model: {}", preferences.selected_model))?;
|
||||
Ok(Self {
|
||||
model,
|
||||
dflash_enabled: model.supports_dflash() && preferences.dflash_enabled,
|
||||
idle_timeout_minutes: preferences.idle_timeout_minutes.to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> iced::Result {
|
||||
iced::application("DS4Server", App::update, App::view)
|
||||
.theme(|_| {
|
||||
Theme::custom(
|
||||
"DS4Server".into(),
|
||||
Palette {
|
||||
background: Color::from_rgb8(29, 29, 31),
|
||||
text: Color::from_rgb8(235, 235, 235),
|
||||
primary: Color::from_rgb8(85, 118, 255),
|
||||
success: Color::from_rgb8(72, 176, 112),
|
||||
danger: Color::from_rgb8(220, 80, 86),
|
||||
},
|
||||
)
|
||||
})
|
||||
.subscription(App::subscription)
|
||||
.theme(|_| app_theme())
|
||||
.window(iced::window::Settings {
|
||||
size: Size::new(1120.0, 720.0),
|
||||
min_size: Some(Size::new(760.0, 480.0)),
|
||||
@@ -49,17 +102,26 @@ fn main() -> iced::Result {
|
||||
struct App {
|
||||
database: Option<Database>,
|
||||
projects: Vec<ProjectWithSessions>,
|
||||
preferences: AppPreferences,
|
||||
preference_draft: PreferenceDraft,
|
||||
preferences_open: bool,
|
||||
preference_error: Option<String>,
|
||||
selected_project: Option<i32>,
|
||||
selected_session: Option<i32>,
|
||||
choosing_folder: bool,
|
||||
pending_project_path: Option<PathBuf>,
|
||||
project_name_input: String,
|
||||
session_title_input: String,
|
||||
error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
OpenPreferences,
|
||||
DismissPanel,
|
||||
PreferenceModelChanged(ModelChoice),
|
||||
PreferenceDflashChanged(bool),
|
||||
PreferenceTimeoutChanged(String),
|
||||
SavePreferences,
|
||||
ChooseProjectFolder,
|
||||
ProjectFolderPicked(Option<PathBuf>),
|
||||
ProjectNameChanged(String),
|
||||
@@ -67,7 +129,6 @@ enum Message {
|
||||
CancelProject,
|
||||
SelectProject(i32),
|
||||
DeleteProject(i32),
|
||||
SessionTitleChanged(String),
|
||||
CreateSession,
|
||||
SelectSession(i32, i32),
|
||||
DeleteSession(i32),
|
||||
@@ -77,40 +138,83 @@ impl App {
|
||||
fn load() -> Self {
|
||||
let path = application_support_path().join("data.sqlite3");
|
||||
match Database::open(&path) {
|
||||
Ok(mut database) => match database.load_projects() {
|
||||
Ok(projects) => Self {
|
||||
database: Some(database),
|
||||
projects,
|
||||
selected_project: None,
|
||||
selected_session: None,
|
||||
choosing_folder: false,
|
||||
pending_project_path: None,
|
||||
project_name_input: String::new(),
|
||||
session_title_input: String::new(),
|
||||
error: None,
|
||||
},
|
||||
Err(error) => Self::failed(error),
|
||||
Ok(mut database) => match (database.load_projects(), database.load_preferences()) {
|
||||
(Ok(projects), Ok(preferences)) => {
|
||||
let preference_draft = match PreferenceDraft::from_saved(&preferences) {
|
||||
Ok(draft) => draft,
|
||||
Err(error) => return Self::failed(error),
|
||||
};
|
||||
Self {
|
||||
database: Some(database),
|
||||
projects,
|
||||
preferences,
|
||||
preference_draft,
|
||||
preferences_open: false,
|
||||
preference_error: None,
|
||||
selected_project: None,
|
||||
selected_session: None,
|
||||
choosing_folder: false,
|
||||
pending_project_path: None,
|
||||
project_name_input: String::new(),
|
||||
error: None,
|
||||
}
|
||||
}
|
||||
(Err(error), _) | (_, Err(error)) => Self::failed(error),
|
||||
},
|
||||
Err(error) => Self::failed(error),
|
||||
}
|
||||
}
|
||||
|
||||
fn failed(error: String) -> Self {
|
||||
let preferences = AppPreferences::default();
|
||||
let preference_draft = PreferenceDraft::from_saved(&preferences)
|
||||
.expect("default preferences must use a supported model");
|
||||
Self {
|
||||
database: None,
|
||||
projects: Vec::new(),
|
||||
preferences,
|
||||
preference_draft,
|
||||
preferences_open: false,
|
||||
preference_error: None,
|
||||
selected_project: None,
|
||||
selected_session: None,
|
||||
choosing_folder: false,
|
||||
pending_project_path: None,
|
||||
project_name_input: String::new(),
|
||||
session_title_input: String::new(),
|
||||
error: Some(format!("Could not open the project database: {error}")),
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Task<Message> {
|
||||
match message {
|
||||
Message::OpenPreferences => self.open_preferences(),
|
||||
Message::DismissPanel => {
|
||||
if self.preferences_open {
|
||||
self.preferences_open = false;
|
||||
self.preference_error = None;
|
||||
} else if self.pending_project_path.is_some() {
|
||||
self.pending_project_path = None;
|
||||
self.project_name_input.clear();
|
||||
self.error = None;
|
||||
}
|
||||
}
|
||||
Message::PreferenceModelChanged(model) => {
|
||||
self.preference_draft.model = model;
|
||||
if !model.supports_dflash() {
|
||||
self.preference_draft.dflash_enabled = false;
|
||||
}
|
||||
self.preference_error = None;
|
||||
}
|
||||
Message::PreferenceDflashChanged(enabled) => {
|
||||
self.preference_draft.dflash_enabled =
|
||||
self.preference_draft.model.supports_dflash() && enabled;
|
||||
self.preference_error = None;
|
||||
}
|
||||
Message::PreferenceTimeoutChanged(value) => {
|
||||
self.preference_draft.idle_timeout_minutes = value;
|
||||
self.preference_error = None;
|
||||
}
|
||||
Message::SavePreferences => self.save_preferences(),
|
||||
Message::ChooseProjectFolder => {
|
||||
self.choosing_folder = true;
|
||||
return Task::perform(
|
||||
@@ -156,7 +260,6 @@ impl App {
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::SessionTitleChanged(value) => self.session_title_input = value,
|
||||
Message::CreateSession => self.create_session(),
|
||||
Message::SelectSession(project_id, session_id) => {
|
||||
self.selected_project = Some(project_id);
|
||||
@@ -180,6 +283,57 @@ impl App {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
keyboard::on_key_press(shortcut)
|
||||
}
|
||||
|
||||
fn open_preferences(&mut self) {
|
||||
if self.database.is_none() || self.pending_project_path.is_some() || self.choosing_folder {
|
||||
return;
|
||||
}
|
||||
match PreferenceDraft::from_saved(&self.preferences) {
|
||||
Ok(draft) => {
|
||||
self.preference_draft = draft;
|
||||
self.preference_error = None;
|
||||
self.preferences_open = true;
|
||||
}
|
||||
Err(error) => self.error = Some(error),
|
||||
}
|
||||
}
|
||||
|
||||
fn save_preferences(&mut self) {
|
||||
let Ok(idle_timeout_minutes) = self
|
||||
.preference_draft
|
||||
.idle_timeout_minutes
|
||||
.trim()
|
||||
.parse::<i32>()
|
||||
else {
|
||||
self.preference_error = Some("Idle timeout must be a whole number.".into());
|
||||
return;
|
||||
};
|
||||
if !(1..=1440).contains(&idle_timeout_minutes) {
|
||||
self.preference_error = Some("Idle timeout must be between 1 and 1440 minutes.".into());
|
||||
return;
|
||||
}
|
||||
|
||||
let model = self.preference_draft.model;
|
||||
let dflash_enabled = model.supports_dflash() && self.preference_draft.dflash_enabled;
|
||||
let Some(database) = &mut self.database else {
|
||||
return;
|
||||
};
|
||||
match database.update_preferences(model.id(), dflash_enabled, idle_timeout_minutes) {
|
||||
Ok(preferences) => {
|
||||
self.preferences = preferences;
|
||||
self.preference_draft = PreferenceDraft::from_saved(&self.preferences)
|
||||
.expect("the saved model was selected from the supported catalog");
|
||||
self.preferences_open = false;
|
||||
self.preference_error = None;
|
||||
self.error = None;
|
||||
}
|
||||
Err(error) => self.preference_error = Some(error),
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_project(&mut self, path: PathBuf) {
|
||||
let Ok(path) = fs::canonicalize(path) else {
|
||||
self.error = Some("The selected folder is no longer available.".into());
|
||||
@@ -246,10 +400,7 @@ impl App {
|
||||
.selected_project()
|
||||
.map(|project| project.sessions.len() + 1)
|
||||
.unwrap_or(1);
|
||||
let title = match self.session_title_input.trim() {
|
||||
"" => format!("Session {default_number}"),
|
||||
title => title.to_owned(),
|
||||
};
|
||||
let title = format!("Session {default_number}");
|
||||
let Some(database) = &mut self.database else {
|
||||
return;
|
||||
};
|
||||
@@ -257,7 +408,6 @@ impl App {
|
||||
match database.create_session(project_id, &title) {
|
||||
Ok(session) => {
|
||||
self.selected_session = Some(session.id);
|
||||
self.session_title_input.clear();
|
||||
self.error = None;
|
||||
self.reload_projects();
|
||||
}
|
||||
@@ -290,7 +440,9 @@ impl App {
|
||||
let content: Element<'_, Message> = shell.into();
|
||||
let mut layers = vec![content];
|
||||
|
||||
if let Some(path) = &self.pending_project_path {
|
||||
if self.preferences_open {
|
||||
layers.push(self.preferences_panel());
|
||||
} else if let Some(path) = &self.pending_project_path {
|
||||
layers.push(self.project_dialog(path));
|
||||
}
|
||||
|
||||
@@ -311,6 +463,21 @@ impl App {
|
||||
} else {
|
||||
button(new_session_content).width(Length::Fill)
|
||||
};
|
||||
let preference_content = row![
|
||||
icon(ICON_SETTINGS, 17),
|
||||
text("Preferences").size(14),
|
||||
Space::with_width(Length::Fill),
|
||||
text("⌘,").size(12),
|
||||
]
|
||||
.spacing(9)
|
||||
.align_y(Alignment::Center);
|
||||
let preferences = if self.database.is_some() {
|
||||
button(preference_content)
|
||||
.width(Length::Fill)
|
||||
.on_press(Message::OpenPreferences)
|
||||
} else {
|
||||
button(preference_content).width(Length::Fill)
|
||||
};
|
||||
let add_project_content = row![icon(ICON_FOLDER_PLUS, 17), text("Add project…").size(14),]
|
||||
.spacing(9)
|
||||
.align_y(Alignment::Center);
|
||||
@@ -321,14 +488,17 @@ impl App {
|
||||
.width(Length::Fill)
|
||||
.on_press(Message::ChooseProjectFolder)
|
||||
};
|
||||
let mut projects = column![
|
||||
let header = column![
|
||||
row![
|
||||
text("DS4Server").size(20),
|
||||
Space::with_width(Length::Fill),
|
||||
icon(ICON_SEARCH, 18),
|
||||
text("Local").size(12),
|
||||
]
|
||||
.align_y(Alignment::Center),
|
||||
new_session.style(button::text),
|
||||
]
|
||||
.spacing(10);
|
||||
let mut projects = column![
|
||||
row![
|
||||
text("PROJECTS").size(11),
|
||||
Space::with_width(Length::Fill),
|
||||
@@ -386,12 +556,19 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
container(scrollable(projects).height(Length::Fill))
|
||||
.width(276)
|
||||
.height(Length::Fill)
|
||||
.padding(16)
|
||||
.style(sidebar_style)
|
||||
.into()
|
||||
container(
|
||||
column![
|
||||
header,
|
||||
scrollable(projects).height(Length::Fill),
|
||||
preferences.style(button::text),
|
||||
]
|
||||
.spacing(10),
|
||||
)
|
||||
.width(276)
|
||||
.height(Length::Fill)
|
||||
.padding(16)
|
||||
.style(sidebar_style)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn detail(&self) -> Element<'_, Message> {
|
||||
@@ -432,14 +609,6 @@ impl App {
|
||||
text(selected_title).size(18),
|
||||
icon(ICON_MORE, 18),
|
||||
Space::with_width(Length::Fill),
|
||||
text_input("Session title", &self.session_title_input)
|
||||
.on_input(Message::SessionTitleChanged)
|
||||
.on_submit(Message::CreateSession)
|
||||
.width(190)
|
||||
.padding(8),
|
||||
button("New session")
|
||||
.on_press(Message::CreateSession)
|
||||
.style(button::primary),
|
||||
]
|
||||
.spacing(10)
|
||||
.align_y(Alignment::Center);
|
||||
@@ -461,7 +630,12 @@ impl App {
|
||||
icon(ICON_PAPERCLIP, 19),
|
||||
Space::with_width(Length::Fill),
|
||||
icon(ICON_MODEL, 16),
|
||||
text("Local model").size(12),
|
||||
text(
|
||||
ModelChoice::from_id(&self.preferences.selected_model)
|
||||
.unwrap_or_default()
|
||||
.to_string(),
|
||||
)
|
||||
.size(12),
|
||||
button(icon(ICON_SEND, 18)),
|
||||
]
|
||||
.align_y(Alignment::Center),
|
||||
@@ -505,6 +679,87 @@ impl App {
|
||||
.into()
|
||||
}
|
||||
|
||||
fn preferences_panel(&self) -> Element<'_, Message> {
|
||||
let dflash_toggle: Option<fn(bool) -> Message> = self
|
||||
.preference_draft
|
||||
.model
|
||||
.supports_dflash()
|
||||
.then_some(Message::PreferenceDflashChanged);
|
||||
let dflash = checkbox(
|
||||
"Enable DFlash for this model",
|
||||
self.preference_draft.dflash_enabled,
|
||||
)
|
||||
.on_toggle_maybe(dflash_toggle);
|
||||
|
||||
let mut content = column![
|
||||
row![
|
||||
icon(ICON_SETTINGS, 22),
|
||||
text("Preferences").size(24),
|
||||
Space::with_width(Length::Fill),
|
||||
text("⌘,").size(12),
|
||||
]
|
||||
.spacing(10)
|
||||
.align_y(Alignment::Center),
|
||||
Space::with_height(6),
|
||||
text("MODEL").size(11),
|
||||
pick_list(
|
||||
&MODEL_CHOICES[..],
|
||||
Some(self.preference_draft.model),
|
||||
Message::PreferenceModelChanged,
|
||||
)
|
||||
.width(Length::Fill),
|
||||
dflash,
|
||||
text(if self.preference_draft.model.supports_dflash() {
|
||||
"DFlash is downloaded and used only when enabled."
|
||||
} else {
|
||||
"DFlash is not available for the selected model."
|
||||
})
|
||||
.size(12),
|
||||
Space::with_height(8),
|
||||
text("INACTIVITY").size(11),
|
||||
row![
|
||||
text_input("10", &self.preference_draft.idle_timeout_minutes)
|
||||
.on_input(Message::PreferenceTimeoutChanged)
|
||||
.width(90)
|
||||
.padding(9),
|
||||
text("minutes before unloading the model").size(13),
|
||||
]
|
||||
.spacing(10)
|
||||
.align_y(Alignment::Center),
|
||||
text("Enter a whole number from 1 to 1440.").size(12),
|
||||
]
|
||||
.spacing(10);
|
||||
|
||||
if let Some(error) = &self.preference_error {
|
||||
content = content.push(text(error).style(iced::widget::text::danger));
|
||||
}
|
||||
content = content.push(
|
||||
row![
|
||||
Space::with_width(Length::Fill),
|
||||
button("Cancel")
|
||||
.on_press(Message::DismissPanel)
|
||||
.style(button::secondary),
|
||||
button("Save")
|
||||
.on_press(Message::SavePreferences)
|
||||
.style(button::primary),
|
||||
]
|
||||
.spacing(8),
|
||||
);
|
||||
|
||||
let panel = container(content)
|
||||
.padding(24)
|
||||
.width(520)
|
||||
.style(container::rounded_box);
|
||||
opaque(
|
||||
container(panel)
|
||||
.center_x(Length::Fill)
|
||||
.center_y(Length::Fill)
|
||||
.style(|_| {
|
||||
container::Style::default().background(Color::from_rgba8(0, 0, 0, 0.68))
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
fn project_dialog<'a>(&'a self, path: &'a Path) -> Element<'a, Message> {
|
||||
let dialog = container(
|
||||
column![
|
||||
@@ -556,6 +811,33 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
fn shortcut(key: keyboard::Key, modifiers: keyboard::Modifiers) -> Option<Message> {
|
||||
match key.as_ref() {
|
||||
keyboard::Key::Character(",") if modifiers.command() => Some(Message::OpenPreferences),
|
||||
keyboard::Key::Named(keyboard::key::Named::Escape) => Some(Message::DismissPanel),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn app_theme() -> Theme {
|
||||
let palette = Palette {
|
||||
background: Color::from_rgb8(29, 29, 31),
|
||||
text: Color::from_rgb8(235, 235, 235),
|
||||
primary: Color::from_rgb8(85, 118, 255),
|
||||
success: Color::from_rgb8(72, 176, 112),
|
||||
danger: Color::from_rgb8(220, 80, 86),
|
||||
};
|
||||
Theme::custom_with_fn("DS4Server".into(), palette, |palette| {
|
||||
let mut extended = palette::Extended::generate(palette);
|
||||
extended.background.weak = palette::Pair::new(Color::from_rgb8(38, 38, 40), palette.text);
|
||||
extended.background.strong = palette::Pair::new(Color::from_rgb8(58, 58, 61), palette.text);
|
||||
extended.secondary.base = palette::Pair::new(Color::from_rgb8(47, 47, 50), palette.text);
|
||||
extended.secondary.weak = palette::Pair::new(Color::from_rgb8(41, 41, 44), palette.text);
|
||||
extended.secondary.strong = palette::Pair::new(Color::from_rgb8(57, 57, 60), palette.text);
|
||||
extended
|
||||
})
|
||||
}
|
||||
|
||||
fn sidebar_style(_: &Theme) -> container::Style {
|
||||
container::Style::default().background(Color::from_rgb8(23, 23, 25))
|
||||
}
|
||||
@@ -577,3 +859,28 @@ fn application_support_path() -> PathBuf {
|
||||
.join("Application Support")
|
||||
.join(APP_ID)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn preferences_shortcut_and_dflash_support_are_explicit() {
|
||||
let message = shortcut(
|
||||
keyboard::Key::Character(",".into()),
|
||||
keyboard::Modifiers::COMMAND,
|
||||
);
|
||||
assert!(matches!(message, Some(Message::OpenPreferences)));
|
||||
assert!(ModelChoice::DeepSeekV4Flash.supports_dflash());
|
||||
assert!(!ModelChoice::DeepSeekV4Pro.supports_dflash());
|
||||
assert!(!ModelChoice::Glm52.supports_dflash());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raised_surfaces_stay_dark() {
|
||||
let theme = app_theme();
|
||||
let palette = theme.extended_palette();
|
||||
assert_eq!(palette.background.weak.color, Color::from_rgb8(38, 38, 40));
|
||||
assert_eq!(palette.secondary.base.color, Color::from_rgb8(47, 47, 50));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,15 @@ diesel::table! {
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
preferences (id) {
|
||||
id -> Integer,
|
||||
selected_model -> Text,
|
||||
dflash_enabled -> Bool,
|
||||
idle_timeout_minutes -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
sessions (id) {
|
||||
id -> Integer,
|
||||
@@ -15,4 +24,4 @@ diesel::table! {
|
||||
}
|
||||
|
||||
diesel::joinable!(sessions -> projects (project_id));
|
||||
diesel::allow_tables_to_appear_in_same_query!(projects, sessions);
|
||||
diesel::allow_tables_to_appear_in_same_query!(preferences, projects, sessions);
|
||||
|
||||
Reference in New Issue
Block a user