mirror of
https://github.com/JonasunderscoreJones/PI-server-rack.git
synced 2025-10-22 17:29:17 +02:00
pushed some non functioning code
This commit is contained in:
parent
8d85068b48
commit
c60e0db035
14 changed files with 2364 additions and 11 deletions
2166
desktop/Cargo.lock
generated
Normal file
2166
desktop/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,17 +1,25 @@
|
|||
[package]
|
||||
name = "desktop"
|
||||
version = "0.1.0"
|
||||
authors = "Jonas_Jones"
|
||||
#authors = ["Jonas_Jones"]
|
||||
edition = "2021"
|
||||
description = "The desktop module of the PI-server-rack project."
|
||||
documentation = "https://github.com/JonasJones/PI-server-rack"
|
||||
readme = "README.md"
|
||||
homepage = "https://jonasjones.me/PI-server-rack"
|
||||
repository = "https://github.com/J-onasJones/PI-server-rack"
|
||||
license = "MIT OR Apache-2.0"
|
||||
keywords = ["server", "raspberry pi"]
|
||||
categories = ["config"]
|
||||
#description = "The desktop module of the PI-server-rack project."
|
||||
#documentation = "https://github.com/JonasJones/PI-server-rack"
|
||||
#readme = "README.md"
|
||||
#homepage = "https://jonasjones.me/PI-server-rack"
|
||||
#repository = "https://github.com/J-onasJones/PI-server-rack"
|
||||
#license = "MIT OR Apache-2.0"
|
||||
#keywords = ["server", "raspberry pi"]
|
||||
#categories = ["config"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
eframe = "0.19.0"
|
||||
try-catch = "0.2.2"
|
||||
serde = "1.0.144"
|
||||
serde_json = "1.0.85"
|
||||
serde_derive = "1.0.144"
|
||||
config = "0.13.2"
|
||||
log = "0.4.17"
|
||||
dirs = "4.0.0"
|
38
desktop/src/confighandler/mod.rs
Normal file
38
desktop/src/confighandler/mod.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use std::{fs::File, io::Read};
|
||||
use try_catch::catch;
|
||||
use serde_json::from_str;
|
||||
use defaultconfigs::Mainconfig;
|
||||
|
||||
use crate::defaultconfigs::{self, CONFIG_PATH};
|
||||
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
|
||||
pub(crate) fn init() {
|
||||
catch! {
|
||||
try {
|
||||
load()
|
||||
} catch _error {
|
||||
create()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn load() {
|
||||
// Load the config file
|
||||
let mut file = File::open(CONFIG_PATH).unwrap();
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents).unwrap();
|
||||
let config: Mainconfig = from_str(&contents).unwrap();
|
||||
println!("{:?}", config);
|
||||
}
|
||||
|
||||
fn create() {
|
||||
// Create the config file
|
||||
|
||||
}
|
||||
|
||||
fn save() {
|
||||
// Save the config file
|
||||
|
||||
}
|
19
desktop/src/defaultconfigs/mod.rs
Normal file
19
desktop/src/defaultconfigs/mod.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use std::path::{PathBuf};
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use dirs::config_dir;
|
||||
|
||||
const SYSTEM_CONFIG_PATH: Option<PathBuf> = config_dir();
|
||||
const RELATIVE_CONFIG_PATH: &str = "/pi-server-rack/config.json";
|
||||
|
||||
pub(crate) const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
pub(crate) const CONFIG_PATH: PathBuf= SYSTEM_CONFIG_PATH.push(RELATIVE_CONFIG_PATH); //TODO: not die from fucking rust paths
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub(crate) struct Mainconfig {
|
||||
lang : String,
|
||||
configpath : String,
|
||||
customwindowframe : bool,
|
||||
|
||||
}
|
3
desktop/src/langhandler.rs
Normal file
3
desktop/src/langhandler.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
fn load() {
|
||||
// Load the language file
|
||||
}
|
|
@ -1,3 +1,18 @@
|
|||
//import ui
|
||||
mod ui;
|
||||
pub(crate) mod confighandler;
|
||||
pub(crate) mod defaultconfigs;
|
||||
|
||||
use defaultconfigs::VERSION;
|
||||
|
||||
use log::{info};
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
info!(target: "[THREAD-MAIN]", "Welcome to PI-Server-Rack v{} !", VERSION);
|
||||
//initialize config
|
||||
confighandler::init();
|
||||
|
||||
|
||||
//initialiaze ui
|
||||
ui::mainloop();
|
||||
}
|
53
desktop/src/ui/mod.rs
Normal file
53
desktop/src/ui/mod.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
pub(crate) mod tabs;
|
||||
|
||||
extern crate eframe;
|
||||
use eframe::egui;
|
||||
|
||||
pub(crate) fn mainloop() {
|
||||
let options = eframe::NativeOptions::default();
|
||||
eframe::run_native(
|
||||
"Confirm exit",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(RootWindow::default())),
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct RootWindow {
|
||||
allowed_to_close: bool,
|
||||
show_confirmation_dialog: bool,
|
||||
}
|
||||
|
||||
impl eframe::App for RootWindow {
|
||||
fn on_close_event(&mut self) -> bool {
|
||||
self.show_confirmation_dialog = true;
|
||||
self.allowed_to_close
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Try to close the window");
|
||||
});
|
||||
|
||||
if self.show_confirmation_dialog {
|
||||
// Show confirmation dialog:
|
||||
egui::Window::new("Do you want to quit?")
|
||||
.collapsible(false)
|
||||
.resizable(false)
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Cancel").clicked() {
|
||||
self.show_confirmation_dialog = false;
|
||||
}
|
||||
|
||||
if ui.button("Yes!").clicked() {
|
||||
self.allowed_to_close = true;
|
||||
frame.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
2
desktop/src/ui/tabs/mod.rs
Normal file
2
desktop/src/ui/tabs/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub(crate) mod overview;
|
||||
pub(crate) mod settings;
|
0
desktop/src/ui/tabs/overview.rs
Normal file
0
desktop/src/ui/tabs/overview.rs
Normal file
0
desktop/src/ui/tabs/settings.rs
Normal file
0
desktop/src/ui/tabs/settings.rs
Normal file
Loading…
Add table
Add a link
Reference in a new issue