diff --git a/src-tauri/src/constants.rs b/src-tauri/src/constants.rs new file mode 100644 index 0000000..9682a28 --- /dev/null +++ b/src-tauri/src/constants.rs @@ -0,0 +1,2 @@ +pub const APP_NAME: &str = "stort"; +pub const APP_TITLE: &str = "Stort"; diff --git a/src-tauri/src/fs.rs b/src-tauri/src/fs.rs index 0fb858d..5bdb2ff 100644 --- a/src-tauri/src/fs.rs +++ b/src-tauri/src/fs.rs @@ -104,3 +104,8 @@ pub fn delete_file(file_path: &std::path::Path) -> std::io::Result<()> { )) } } + +pub fn create_directory(directory_path: &std::path::Path) -> std::io::Result<()> { + // attempt to create the directory + std::fs::create_dir_all(directory_path) +} diff --git a/src-tauri/src/initialize.rs b/src-tauri/src/initialize.rs new file mode 100644 index 0000000..d15b0d4 --- /dev/null +++ b/src-tauri/src/initialize.rs @@ -0,0 +1,11 @@ +pub fn initialize_directories() { + // getting the directories will also create them if they dont exist + // get the app data directory + crate::paths::get_app_data_dir().expect("Failed to get or create app data directory"); + + // get the app cache directory + crate::paths::get_app_data_dir().expect("Failed to get or create app data directory"); + + // get the app config directory + crate::paths::get_app_data_dir().expect("Failed to get or create app data directory"); +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1f72919..b970f78 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,3 +1,6 @@ +pub mod constants; pub mod fs; +pub mod initialize; pub mod paths; +pub mod tauri; pub mod wallpaper; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index b256508..ddc6bfb 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -2,11 +2,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] fn main() { - tauri::Builder::default() - .invoke_handler(tauri::generate_handler![ - app::wallpaper::process_wallpaper_image, - app::wallpaper::delete_old_wallpaper_image, - ]) - .run(tauri::generate_context!()) - .expect("error while running tauri application"); + app::initialize::initialize_directories(); + app::tauri::run_tauri_app(); } diff --git a/src-tauri/src/paths.rs b/src-tauri/src/paths.rs index de8b5a6..d3887a5 100644 --- a/src-tauri/src/paths.rs +++ b/src-tauri/src/paths.rs @@ -2,7 +2,7 @@ pub fn get_app_data_dir() -> Result { // attempt to get the app data directory match tauri::api::path::data_dir() { Some(data_dir) => { - let app_data_dir = data_dir.join("stort/"); + let app_data_dir = data_dir.join(crate::constants::APP_NAME); // ensure the directory exists if !app_data_dir.exists() { // attempt to create the directory @@ -18,3 +18,45 @@ pub fn get_app_data_dir() -> Result { None => Err("Failed to get app data directory".to_string()), } } + +pub fn get_app_cache_dir() -> Result { + // attempt to get the app cache directory + match tauri::api::path::cache_dir() { + Some(cache_dir) => { + let app_cache_dir = cache_dir.join(crate::constants::APP_NAME); + // ensure the directory exists + if !app_cache_dir.exists() { + // attempt to create the directory + std::fs::create_dir_all(&app_cache_dir).map_err(|e| { + format!( + "Failed to create app cache directory {:?}: {}", + app_cache_dir, e + ) + })?; + } + Ok(app_cache_dir) + } + None => Err("Failed to get app cache directory".to_string()), + } +} + +pub fn get_app_config_dir() -> Result { + // attempt to get the app config directory + match tauri::api::path::config_dir() { + Some(config_dir) => { + let app_config_dir = config_dir.join(crate::constants::APP_NAME); + // ensure the directory exists + if !app_config_dir.exists() { + // attempt to create the directory + std::fs::create_dir_all(&app_config_dir).map_err(|e| { + format!( + "Failed to create app config directory {:?}: {}", + app_config_dir, e + ) + })?; + } + Ok(app_config_dir) + } + None => Err("Failed to get app config directory".to_string()), + } +} diff --git a/src-tauri/src/tauri.rs b/src-tauri/src/tauri.rs new file mode 100644 index 0000000..af3674c --- /dev/null +++ b/src-tauri/src/tauri.rs @@ -0,0 +1,9 @@ +pub fn run_tauri_app() { + tauri::Builder::default() + .invoke_handler(tauri::generate_handler![ + crate::wallpaper::process_wallpaper_image, + crate::wallpaper::delete_old_wallpaper_image, + ]) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); +} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 84b1c9d..17f94f4 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -22,7 +22,8 @@ "**/*", "/**/*", "$CONFIG/stort/", - "$CONFIG/stort/**" + "$CONFIG/stort/**", + "$HOME/.local/share/stort/*" ] }, "notification": { @@ -38,9 +39,7 @@ "all": true, "asset": true, "assetScope": [ - "**", - "**/*", - "/**/*" + "$APPDATA/*" ] }, "window": { @@ -62,7 +61,7 @@ "icons/icon.icns", "icons/icon.ico" ], - "identifier": "com.vomitblood.stort", + "identifier": "stort", "longDescription": "Launcher for Steam Deck", "resources": [], "shortDescription": "Launcher for Steam Deck", diff --git a/src/components/FooterBar.tsx b/src/components/FooterBar.tsx deleted file mode 100644 index c226a16..0000000 --- a/src/components/FooterBar.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { Settings } from "@mui/icons-material"; -import { Box, Stack } from "@mui/material"; -import { useRouter } from "next/router"; -import { WindowButtons } from "./HeaderBar/WindowButtons"; - -export const FooterBar = () => { - return ( - - - hello this is the left side - - - - - - - - - ); -}; diff --git a/src/components/FooterBar/FooterBar.tsx b/src/components/FooterBar/FooterBar.tsx index e69de29..dc3bd00 100644 --- a/src/components/FooterBar/FooterBar.tsx +++ b/src/components/FooterBar/FooterBar.tsx @@ -0,0 +1,56 @@ +import { Settings } from "@mui/icons-material"; +import { Box, Stack } from "@mui/material"; +import { WindowButtons } from "../HeaderBar/WindowButtons"; + +export const FooterBar = () => { + return ( + + + hello this is the left side + + + + + + + + + ); +}; diff --git a/src/components/Generic/Initialization.tsx b/src/components/Generic/Initialization.tsx deleted file mode 100644 index b274cea..0000000 --- a/src/components/Generic/Initialization.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { createDir, exists } from "@tauri-apps/api/fs"; -import { useEffect } from "react"; -import { useSettings } from "../../contexts/SettingsContext"; -import Paths from "../../lib/path"; - -export const Initialization = () => { - const { settings, settingsLoading } = useSettings(); - - useEffect(() => { - const initializePaths = async () => { - try { - await Paths.initialize(); - } catch (error) { - console.error(`Failed to initialize paths: ${error}`); - } - }; - - const createDirectories = async () => { - const configDirectoryExists = await exists(Paths.getPath("configDirectory")); - if (!configDirectoryExists) await createDir(Paths.getPath("configDirectory")); - }; - - const fullscreen = async () => { - const { appWindow } = await import("@tauri-apps/api/window"); - await appWindow.setFullscreen(true); - }; - - initializePaths().then(() => createDirectories()); - // TODO: race condition here, need to wait for settings to load - if (settings.window.start_fullscreen) fullscreen(); - }, [settingsLoading]); - - return null; -}; diff --git a/src/components/Generic/Layout.tsx b/src/components/Generic/Layout.tsx index 43bd94c..9985a34 100644 --- a/src/components/Generic/Layout.tsx +++ b/src/components/Generic/Layout.tsx @@ -1,9 +1,9 @@ import { Box, Button } from "@mui/material"; import { convertFileSrc } from "@tauri-apps/api/tauri"; -import { useState } from "react"; -import { FooterBar } from "../FooterBar"; -import { HeaderBar } from "../HeaderBar/HeaderBar"; +import { useEffect, useState } from "react"; import { useSettings } from "../../contexts/SettingsContext"; +import { FooterBar } from "../FooterBar/FooterBar"; +import { HeaderBar } from "../HeaderBar/HeaderBar"; export const Layout = () => { const { settings } = useSettings(); @@ -11,15 +11,21 @@ export const Layout = () => { const [imageUrl, setImageUrl] = useState(null); const setBackground = async () => { - const assetUrl = convertFileSrc("/home/vomitblood/Downloads/toothless-dance.gif"); + const assetUrl = convertFileSrc("/home/vomitblood/.local/share/stort/wallpaper.jpeg"); setImageUrl(assetUrl); }; + // useEffect(() => { + // if (settings.background.background_image_path) { + // setBackground(settings.background.background_image_path); + // } + // }, [settings.background.background_image_path]); + return ( { +