docs, password config, help, about

render -> draw, file explorer, writer is RefCell
This commit is contained in:
stjet
2025-01-01 09:38:11 +00:00
parent acdb59d668
commit 03f1d649e0
34 changed files with 542 additions and 152 deletions

62
src/essential/about.rs Normal file
View File

@@ -0,0 +1,62 @@
use std::vec::Vec;
use std::boxed::Box;
use std::fs::read_to_string;
use crate::window_manager::{ DrawInstructions, WindowLike, WindowLikeType };
use crate::messages::{ WindowMessage, WindowMessageResponse };
use crate::framebuffer::Dimensions;
use crate::themes::ThemeInfo;
use crate::components::Component;
use crate::components::paragraph::Paragraph;
pub struct About {
dimensions: Dimensions,
components: Vec<Box<dyn Component<()> + Send>>,
}
impl WindowLike for About {
fn handle_message(&mut self, message: WindowMessage) -> WindowMessageResponse {
match message {
WindowMessage::Init(dimensions) => {
self.dimensions = dimensions;
self.components.push(Box::new(Paragraph::new("help".to_string(), [2, 2], [self.dimensions[0] - 4, self.dimensions[1] - 4], read_to_string("docs/system/README.md").unwrap_or("docs/system/README.md not found".to_string()), ())));
WindowMessageResponse::JustRedraw
},
WindowMessage::KeyPress(key_press) => {
if self.components[0].handle_message(WindowMessage::KeyPress(key_press)).is_some() {
WindowMessageResponse::JustRedraw
} else {
WindowMessageResponse::DoNothing
}
},
_ => WindowMessageResponse::DoNothing
}
}
fn draw(&self, theme_info: &ThemeInfo) -> Vec<DrawInstructions> {
self.components[0].draw(theme_info)
}
//properties
fn title(&self) -> String {
"About".to_string()
}
fn subtype(&self) -> WindowLikeType {
WindowLikeType::Window
}
fn ideal_dimensions(&self, _dimensions: Dimensions) -> Dimensions {
[500, 600]
}
}
impl About {
pub fn new() -> Self {
Self {
dimensions: [0, 0],
components: Vec::new(),
}
}
}

View File

@@ -21,13 +21,13 @@ impl WindowLike for DesktopBackground {
match message {
WindowMessage::Init(dimensions) => {
self.dimensions = dimensions;
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
},
WindowMessage::Shortcut(shortcut) => {
match shortcut {
ShortcutType::SwitchWorkspace(workspace) => {
self.current_workspace = workspace;
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
},
_ => WindowMessageResponse::DoNothing,
}

89
src/essential/help.rs Normal file
View File

@@ -0,0 +1,89 @@
use std::vec::Vec;
use std::boxed::Box;
use std::fs::{ read_to_string, read_dir };
use std::path::PathBuf;
use crate::window_manager::{ DrawInstructions, WindowLike, WindowLikeType };
use crate::messages::{ WindowMessage, WindowMessageResponse };
use crate::framebuffer::Dimensions;
use crate::themes::ThemeInfo;
use crate::components::paragraph::Paragraph;
use crate::components::Component;
pub struct Help {
dimensions: Dimensions,
file_index: usize,
files: Vec<PathBuf>,
paragraph: Option<Box<Paragraph<()>>>,
}
impl WindowLike for Help {
fn handle_message(&mut self, message: WindowMessage) -> WindowMessageResponse {
match message {
WindowMessage::Init(dimensions) => {
self.dimensions = dimensions;
self.paragraph = Some(Box::new(Paragraph::new("help".to_string(), [2, 22], [self.dimensions[0] - 4, self.dimensions[1] - 24], "Press the 'h' and 'l' keys to read the different help pages".to_string(), ())));
WindowMessageResponse::JustRedraw
},
WindowMessage::KeyPress(key_press) => {
if key_press.key == 'h' || key_press.key == 'l' {
if key_press.key == 'h' {
if self.file_index == 0 {
self.file_index = self.files.len() - 1;
} else {
self.file_index -= 1;
}
} else {
if self.file_index == self.files.len() - 1 {
self.file_index = 0;
} else {
self.file_index += 1;
}
}
self.paragraph.as_mut().unwrap().new_text(read_to_string(self.files[self.file_index].clone()).unwrap());
WindowMessageResponse::JustRedraw
} else if self.paragraph.as_mut().unwrap().handle_message(WindowMessage::KeyPress(key_press)).is_some() {
WindowMessageResponse::JustRedraw
} else {
WindowMessageResponse::DoNothing
}
},
_ => WindowMessageResponse::DoNothing
}
}
fn draw(&self, theme_info: &ThemeInfo) -> Vec<DrawInstructions> {
let mut instructions = vec![DrawInstructions::Text([2, 2], vec!["times-new-romono".to_string()], self.files[self.file_index].clone().file_name().unwrap().to_string_lossy().to_string(), theme_info.text, theme_info.background, Some(0), None)];
instructions.extend(self.paragraph.as_ref().unwrap().draw(theme_info));
instructions
}
//properties
fn title(&self) -> String {
"About".to_string()
}
fn subtype(&self) -> WindowLikeType {
WindowLikeType::Window
}
fn ideal_dimensions(&self, _dimensions: Dimensions) -> Dimensions {
[500, 600]
}
}
impl Help {
pub fn new() -> Self {
let mut files = vec![PathBuf::from("docs/system/shortcuts.md")];
for entry in read_dir("docs/window-likes").unwrap() {
files.push(entry.unwrap().path());
}
Self {
dimensions: [0, 0],
file_index: 0,
files,
paragraph: None,
}
}
}

View File

@@ -7,7 +7,9 @@ use crate::messages::{ WindowMessage, WindowMessageResponse, WindowManagerReques
use crate::window_manager::{ DrawInstructions, WindowLike, WindowLikeType };
use blake2::{ Blake2b512, Digest };
const PASSWORD_HASH: [u8; 64] = [220, 88, 183, 188, 240, 27, 107, 181, 58, 191, 198, 170, 114, 38, 7, 148, 6, 179, 75, 128, 231, 171, 172, 220, 85, 38, 36, 113, 116, 146, 70, 197, 163, 179, 158, 192, 130, 53, 247, 48, 47, 209, 95, 96, 179, 211, 4, 122, 254, 127, 21, 165, 139, 199, 151, 226, 216, 176, 123, 41, 194, 221, 58, 69];
include!(concat!(env!("OUT_DIR"), "/password.rs"));
//const PASSWORD_HASH: [u8; 64] = [220, 88, 183, 188, 240, 27, 107, 181, 58, 191, 198, 170, 114, 38, 7, 148, 6, 179, 75, 128, 231, 171, 172, 220, 85, 38, 36, 113, 116, 146, 70, 197, 163, 179, 158, 192, 130, 53, 247, 48, 47, 209, 95, 96, 179, 211, 4, 122, 254, 127, 21, 165, 139, 199, 151, 226, 216, 176, 123, 41, 194, 221, 58, 69];
pub struct LockScreen {
dimensions: Dimensions,
@@ -19,28 +21,28 @@ impl WindowLike for LockScreen {
match message {
WindowMessage::Init(dimensions) => {
self.dimensions = dimensions;
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
},
WindowMessage::KeyPress(key_press) => {
if key_press.key == '𐘂' { //the enter key
//check password
let mut hasher = Blake2b512::new();
hasher.update(self.input_password.as_bytes());
hasher.update((self.input_password.clone() + "salt?sorrycryptographers").as_bytes());
if hasher.finalize() == PASSWORD_HASH.into() {
WindowMessageResponse::Request(WindowManagerRequest::Unlock)
} else {
self.input_password = String::new();
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
}
} else if key_press.key == '𐘁' { //backspace
let p_len = self.input_password.len();
if p_len != 0 {
self.input_password = self.input_password[..p_len - 1].to_string();
}
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
} else {
self.input_password += &key_press.key.to_string();
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
}
},
_ => WindowMessageResponse::DoNothing,

View File

@@ -4,3 +4,6 @@ pub mod lock_screen;
pub mod workspace_indicator;
pub mod start_menu;
pub mod about;
pub mod help;

View File

@@ -1,5 +1,3 @@
#![allow(warnings)]
use std::vec;
use std::vec::Vec;
use std::boxed::Box;
@@ -10,9 +8,6 @@ use crate::framebuffer::Dimensions;
use crate::themes::ThemeInfo;
use crate::components::Component;
use crate::components::highlight_button::HighlightButton;
use crate::ipc::listen;
//todo: move to essential
static CATEGORIES: [&'static str; 9] = ["About", "Utils", "Games", "Editing", "Files", "System", "Misc", "Help", "Logout"];
@@ -39,7 +34,7 @@ impl WindowLike for StartMenu {
self.dimensions = dimensions;
self.y_each = (self.dimensions[1] - 1) / CATEGORIES.len();
self.add_category_components();
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
},
WindowMessage::KeyPress(key_press) => {
//up and down
@@ -62,7 +57,7 @@ impl WindowLike for StartMenu {
self.old_focus = self.current_focus.to_string();
self.current_focus = self.components[current_focus_index].name().to_string();
self.components[current_focus_index].handle_message(WindowMessage::Focus);
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
} else if key_press.key == '𐘂' { //the enter key
let focus_index = self.get_focus_index();
if let Some(focus_index) = focus_index {
@@ -79,7 +74,7 @@ impl WindowLike for StartMenu {
self.old_focus = self.current_focus.clone();
self.current_focus = self.components[current_focus_index + n_index].name().to_string();
self.components[current_focus_index + n_index].handle_message(WindowMessage::Focus);
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
} else {
WindowMessageResponse::DoNothing
}
@@ -135,11 +130,14 @@ impl StartMenu {
StartMenuMessage::CategoryClick(name) => {
if name == "Logout" {
WindowMessageResponse::Request(WindowManagerRequest::Lock)
} else if name == "About" || name == "Help" {
//todo above: also do the same for Help
WindowMessageResponse::Request(WindowManagerRequest::OpenWindow(name.to_string()))
} else {
self.current_focus = "Back".to_string();
self.components = vec![
Box::new(HighlightButton::new(
"Back".to_string(), [42, 1], [self.dimensions[0] - 42 - 1, self.y_each], "Back", StartMenuMessage::Back, StartMenuMessage::ChangeAcknowledge, true
"Back".to_string(), [42, 1], [self.dimensions[0] - 42 - 1, self.y_each], "Back".to_string(), StartMenuMessage::Back, StartMenuMessage::ChangeAcknowledge, true
))
];
//add window buttons
@@ -157,10 +155,10 @@ impl StartMenu {
for a in 0..to_add.len() {
let w_name = to_add[a];
self.components.push(Box::new(HighlightButton::new(
w_name.to_string(), [42, (a + 1) * self.y_each], [self.dimensions[0] - 42 - 1, self.y_each], w_name, StartMenuMessage::WindowClick(w_name), StartMenuMessage::ChangeAcknowledge, false
w_name.to_string(), [42, (a + 1) * self.y_each], [self.dimensions[0] - 42 - 1, self.y_each], w_name.to_string(), StartMenuMessage::WindowClick(w_name), StartMenuMessage::ChangeAcknowledge, false
)));
}
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
}
},
StartMenuMessage::WindowClick(name) => {
@@ -169,15 +167,15 @@ impl StartMenu {
},
StartMenuMessage::Back => {
self.add_category_components();
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
},
StartMenuMessage::ChangeAcknowledge => {
//
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
},
}
} else {
//maybe should be JustRerender?
//maybe should be JustRedraw?
WindowMessageResponse::DoNothing
}
}
@@ -188,7 +186,7 @@ impl StartMenu {
for c in 0..CATEGORIES.len() {
let name = CATEGORIES[c];
self.components.push(Box::new(HighlightButton::new(
name.to_string(), [42, self.y_each * c + 1], [self.dimensions[0] - 42 - 1, self.y_each], name, StartMenuMessage::CategoryClick(name), StartMenuMessage::ChangeAcknowledge, c == 0
name.to_string(), [42, self.y_each * c + 1], [self.dimensions[0] - 42 - 1, self.y_each], name.to_string(), StartMenuMessage::CategoryClick(name), StartMenuMessage::ChangeAcknowledge, c == 0
)));
}
}
@@ -198,7 +196,3 @@ impl StartMenu {
}
}
pub fn main() {
listen(StartMenu::new());
}

View File

@@ -7,7 +7,7 @@ use crate::messages::{ WindowMessage, WindowMessageResponse, WindowManagerReques
use crate::framebuffer::Dimensions;
use crate::themes::ThemeInfo;
use crate::components::Component;
use crate::components::toggle_button::{ ToggleButton, ToggleButtonAlignment };
use crate::components::toggle_button::ToggleButton;
const PADDING: usize = 4;
const META_WIDTH: usize = 175; //of the window button
@@ -33,9 +33,9 @@ impl WindowLike for Taskbar {
WindowMessage::Init(dimensions) => {
self.dimensions = dimensions;
self.components = vec![
Box::new(ToggleButton::new("start-button".to_string(), [PADDING, PADDING], [44, self.dimensions[1] - (PADDING * 2)], "Start".to_string(), TaskbarMessage::ShowStartMenu, TaskbarMessage::HideStartMenu, false, Some(ToggleButtonAlignment::Left))),
Box::new(ToggleButton::new("start-button".to_string(), [PADDING, PADDING], [44, self.dimensions[1] - (PADDING * 2)], "Start".to_string(), TaskbarMessage::ShowStartMenu, TaskbarMessage::HideStartMenu, false)),
];
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
},
WindowMessage::Shortcut(shortcut) => {
match shortcut {
@@ -52,7 +52,7 @@ impl WindowLike for Taskbar {
InfoType::WindowsInWorkspace(windows, focused_id) => {
self.windows_in_workspace = windows;
self.focused_id = focused_id;
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
}
_ => WindowMessageResponse::DoNothing,
}
@@ -80,7 +80,7 @@ impl WindowLike for Taskbar {
}
let info = &self.windows_in_workspace[wi];
let name = &info.1;
let mut b = ToggleButton::new(name.to_string() + "-window", [PADDING * 2 + 44 + (META_WIDTH + PADDING) * wi, PADDING], [META_WIDTH, self.dimensions[1] - (PADDING * 2)], name.to_string(), TaskbarMessage::Nothing, TaskbarMessage::Nothing, false, Some(ToggleButtonAlignment::Left));
let mut b = ToggleButton::new(name.to_string() + "-window", [PADDING * 2 + 44 + (META_WIDTH + PADDING) * wi, PADDING], [META_WIDTH, self.dimensions[1] - (PADDING * 2)], name.to_string(), TaskbarMessage::Nothing, TaskbarMessage::Nothing, false);
b.inverted = info.0 == self.focused_id;
instructions.extend(b.draw(theme_info));
}
@@ -119,7 +119,7 @@ impl Taskbar {
_ => WindowMessageResponse::DoNothing,
}
} else {
//maybe should be JustRerender?
//maybe should be JustRedraw?
WindowMessageResponse::DoNothing
}
}

View File

@@ -22,13 +22,13 @@ impl WindowLike for WorkspaceIndicator {
match message {
WindowMessage::Init(dimensions) => {
self.dimensions = dimensions;
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
},
WindowMessage::Shortcut(shortcut) => {
match shortcut {
ShortcutType::SwitchWorkspace(workspace) => {
self.current_workspace = workspace;
WindowMessageResponse::JustRerender
WindowMessageResponse::JustRedraw
},
_ => WindowMessageResponse::DoNothing,
}