tauri_winutils/
workspace.rs1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3use crate::layout::LayoutType;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Workspace {
7 pub id: String,
8 pub name: String,
9 pub layout: LayoutType,
10 pub windows: Vec<String>,
11 pub focused_window: Option<String>,
12}
13
14impl Workspace {
15 pub fn new(name: String, layout: LayoutType) -> Self {
16 Self {
17 id: Uuid::new_v4().to_string(),
18 name,
19 layout,
20 windows: Vec::new(),
21 focused_window: None,
22 }
23 }
24
25 pub fn add_window(&mut self, window_id: String) {
26 if !self.windows.contains(&window_id) {
27 self.windows.push(window_id.clone());
28 self.focused_window = Some(window_id);
29 }
30 }
31
32 pub fn remove_window(&mut self, window_id: &str) {
33 self.windows.retain(|id| id != window_id);
34
35 if self.focused_window.as_ref() == Some(&window_id.to_string()) {
36 self.focused_window = self.windows.last().cloned();
37 }
38 }
39
40 pub fn focus_window(&mut self, window_id: &str) {
41 if self.windows.contains(&window_id.to_string()) {
42 self.focused_window = Some(window_id.to_string());
43 }
44 }
45
46 pub fn get_windows(&self) -> &[String] {
47 &self.windows
48 }
49
50 pub fn set_layout(&mut self, layout: LayoutType) {
51 self.layout = layout;
52 }
53}