Skip to content

Commit

Permalink
[GUI] Fix log counting not counting towards total
Browse files Browse the repository at this point in the history
  • Loading branch information
Bwc9876 committed Jul 29, 2023
1 parent 398bb96 commit 5ec43b0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions owmods_core/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub async fn launch_game(
open_in_new_window: bool,
port: Option<&u16>,
) -> Result<()> {
if option_env!("NO_GAME").unwrap_or("FALSE") == "TRUE" {
return Ok(());
}

let mut cmd = get_cmd(config, open_in_new_window)?;

cmd.current_dir(PathBuf::from(&config.owml_path));
Expand Down
9 changes: 7 additions & 2 deletions owmods_gui/backend/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,10 @@ pub async fn run_game(
if let Err(why) = res {
error!("Couldn't Emit Game Log: {}", why)
}
let res = window_handle.typed_emit_all(&Event::LogUpdate(port));
if let Err(why) = res {
error!("Couldn't Emit Game Log: {}", why)
}
continue;
}
}
Expand Down Expand Up @@ -791,11 +795,12 @@ pub async fn get_log_lines(
filter_type: Option<SocketMessageType>,
search: &str,
state: tauri::State<'_, State>,
) -> Result<Vec<usize>> {
) -> Result<(Vec<usize>, u32)> {
let logs = state.game_log.read().await;
if let Some((lines, _)) = logs.get(&port) {
let sum = lines.iter().map(|l| l.amount).sum();
let lines = get_logs_indices(lines, filter_type, search)?;
Ok(lines)
Ok((lines, sum))
} else {
Err(Error(anyhow!("Log Server Not Running")))
}
Expand Down
2 changes: 1 addition & 1 deletion owmods_gui/frontend/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const commandInfo = {
filterType?: number | undefined;
search: string;
},
number[]
[number[], number]
>
>("get_log_lines"),
exportMods: $<ActionCommand<{ path: string }>>("export_mods"),
Expand Down
8 changes: 6 additions & 2 deletions owmods_gui/frontend/src/components/logs/LogApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ const LogApp = ({ port }: { port: number }) => {
const [activeFilter, setActiveFilter] = useState<LogFilter>("Any");
const [activeSearch, setActiveSearch] = useState<string>("");
const [logLines, setLogLines] = useState<LogLines>([]);
const [logTotal, setLogTotal] = useState<number>(0);
const getTranslation = useGetTranslation();
const theme = useTheme();

const fetchLogLines = useCallback(() => {
commands
.getLogLines({ port, filterType: getFilterToPass(activeFilter), search: activeSearch })
.then(setLogLines)
.then(([lines, total]) => {
setLogLines(lines);
setLogTotal(total);
})
.catch(() => null);
}, [activeFilter, activeSearch, port]);

Expand Down Expand Up @@ -93,7 +97,7 @@ const LogApp = ({ port }: { port: number }) => {
>
<LogHeader
onClear={onClear}
logsLen={logLines.length}
logsLen={logTotal}
activeSearch={activeSearch}
setActiveSearch={setActiveSearch}
activeFilter={activeFilter}
Expand Down
2 changes: 1 addition & 1 deletion owmods_gui/frontend/src/components/logs/LogRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const LogRow = memo(function LogRow(props: LogRowProps) {
{(logLine?.amount ?? 1) > 1 && (
<Box justifySelf="end">
<Chip
color={logLine?.amount === 65535 ? "error" : "default"}
color={logLine?.amount === 4294967295 ? "error" : "default"}
size="small"
label={`x${logLine?.amount}`}
/>
Expand Down

0 comments on commit 5ec43b0

Please sign in to comment.