diff --git a/owmods_core/src/alerts.rs b/owmods_core/src/alerts.rs index 06db63d3..8b793878 100644 --- a/owmods_core/src/alerts.rs +++ b/owmods_core/src/alerts.rs @@ -1,10 +1,12 @@ use log::debug; use serde::{Deserialize, Serialize}; +use typeshare::typeshare; use crate::mods::{LocalMod, ModWarning}; use anyhow::Result; /// Represents an alert gotten from the database. +#[typeshare] #[derive(Serialize, Deserialize)] pub struct Alert { pub enabled: bool, diff --git a/owmods_gui/backend/src/commands.rs b/owmods_gui/backend/src/commands.rs index 37ab756c..069c75ca 100644 --- a/owmods_gui/backend/src/commands.rs +++ b/owmods_gui/backend/src/commands.rs @@ -2,6 +2,7 @@ use std::fs::File; use std::io::{BufWriter, Write}; use std::path::{Path, PathBuf}; +use owmods_core::alerts::{fetch_alert, Alert}; use owmods_core::config::Config; use owmods_core::constants::OWML_UNIQUE_NAME; use owmods_core::db::{LocalDatabase, RemoteDatabase}; @@ -648,3 +649,9 @@ pub async fn db_has_issues(state: tauri::State<'_, State>) -> Result) -> Result { + let config = state.config.read().await; + fetch_alert(&config.alert_url).await.map_err(e_to_str) +} diff --git a/owmods_gui/backend/src/main.rs b/owmods_gui/backend/src/main.rs index 31840894..618448ec 100644 --- a/owmods_gui/backend/src/main.rs +++ b/owmods_gui/backend/src/main.rs @@ -98,7 +98,8 @@ fn main() -> Result<(), Box> { export_mods, import_mods, fix_mod_deps, - db_has_issues + db_has_issues, + get_alert ]) .run(tauri::generate_context!()) .expect("Error while running tauri application."); diff --git a/owmods_gui/frontend/src/commands.ts b/owmods_gui/frontend/src/commands.ts index 4fd4cf42..50307e5d 100644 --- a/owmods_gui/frontend/src/commands.ts +++ b/owmods_gui/frontend/src/commands.ts @@ -1,6 +1,14 @@ import { LoadState, useTauri } from "@hooks"; import { invoke } from "@tauri-apps/api"; -import { Config, GuiConfig, OWMLConfig, RemoteMod, GameMessage, UnsafeLocalMod } from "@types"; +import { + Config, + GuiConfig, + OWMLConfig, + RemoteMod, + GameMessage, + UnsafeLocalMod, + Alert +} from "@types"; type CommandInfo = [P, R]; type GetCommand = CommandInfo, V>; @@ -61,7 +69,8 @@ const commandInfo = { exportMods: $>("export_mods"), importMods: $>("import_mods"), fixDeps: $>("fix_mod_deps"), - checkDBForIssues: $>("db_has_issues") + checkDBForIssues: $>("db_has_issues"), + getAlert: $>("get_alert") }; type Command = keyof typeof commandInfo; diff --git a/owmods_gui/frontend/src/components/MainApp.tsx b/owmods_gui/frontend/src/components/MainApp.tsx index c51d0dbb..e93b72d0 100644 --- a/owmods_gui/frontend/src/components/MainApp.tsx +++ b/owmods_gui/frontend/src/components/MainApp.tsx @@ -11,6 +11,7 @@ import { commands, hooks } from "@commands"; import { useTheme } from "@hooks"; import { Theme } from "@types"; import CenteredSpinner from "./common/CenteredSpinner"; +import AlertBar from "./alerts/AlertBar"; startConsoleLogListen(); @@ -70,6 +71,7 @@ const App = () => {
+
diff --git a/owmods_gui/frontend/src/components/alerts/AlertBar.tsx b/owmods_gui/frontend/src/components/alerts/AlertBar.tsx new file mode 100644 index 00000000..7c348d15 --- /dev/null +++ b/owmods_gui/frontend/src/components/alerts/AlertBar.tsx @@ -0,0 +1,21 @@ +import { hooks } from "@commands"; +import { memo } from "react"; + +const AlertBar = memo(() => { + const [status, alert, err] = hooks.getAlert("CONFIG_RELOAD"); + + if (status === "Loading") { + return <>; + } else if (status === "Error") { + console.error(err); + return <>; + } else { + if (alert!.enabled) { + return {alert!.message}; + } else { + return <>; + } + } +}); + +export default AlertBar; diff --git a/owmods_gui/frontend/src/components/logs/LogList.tsx b/owmods_gui/frontend/src/components/logs/LogList.tsx index e981384a..7846c78b 100644 --- a/owmods_gui/frontend/src/components/logs/LogList.tsx +++ b/owmods_gui/frontend/src/components/logs/LogList.tsx @@ -15,8 +15,6 @@ const LogList = memo((props: LogListProps) => { const logLen = props.logLines.length; const logSizes = useRef>({}); - console.debug(logSizes); - const reportSize = useCallback((i: number, l: number, size: number) => { logSizes.current[l] = size; listRef.current?.resetAfterIndex(i); diff --git a/owmods_gui/frontend/src/styles/nav.scss b/owmods_gui/frontend/src/styles/nav.scss index 4d673ad1..aca9c073 100644 --- a/owmods_gui/frontend/src/styles/nav.scss +++ b/owmods_gui/frontend/src/styles/nav.scss @@ -55,3 +55,17 @@ details[role="list"] a:hover { details[role="list"] a svg { margin-right: $margin; } + +span.alert-row { + z-index: 100; + position: fixed; + left: 0; + right: 0; + top: 0; + display: block; + text-align: center; + width: 100%; + padding: $margin-sm; + margin-top: 0; + background-color: var(--accent-bg); +} diff --git a/owmods_gui/frontend/src/types.d.ts b/owmods_gui/frontend/src/types.d.ts index bed17920..0451b435 100644 --- a/owmods_gui/frontend/src/types.d.ts +++ b/owmods_gui/frontend/src/types.d.ts @@ -2,6 +2,13 @@ Generated by typeshare 1.2.0 */ +/** Represents an alert gotten from the database. */ +export interface Alert { + enabled: boolean; + severity?: string; + message?: string; +} + /** Represents the core config, contains critical info needed by the core API */ export interface Config { owmlPath: string;