Skip to content

Commit

Permalink
[GUI] Add timestamps to log tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
Bwc9876 committed Aug 5, 2023
1 parent 5e04b52 commit e4bc3ba
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions owmods_gui/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,28 @@ tauri-build = { version = "1.4.0", features = [] }
owmods_core = { version = "0.10.1", path = "../../owmods_core" }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.4.1", features = ["app-all", "dialog-ask", "dialog-confirm", "dialog-message", "dialog-open", "dialog-save", "os-all", "shell-open", "updater", "window-set-focus", "window-set-title"] }
tauri = { version = "1.4.1", features = [
"app-all",
"dialog-ask",
"dialog-confirm",
"dialog-message",
"dialog-open",
"dialog-save",
"os-all",
"shell-open",
"updater",
"window-set-focus",
"window-set-title",
] }
anyhow = "1.0.72"
tokio = { version = "1.29.1", features = ["sync", "macros"] }
log = { version = "0.4.19", features = ["std", "serde"] }
typeshare = "1.0.1"
notify = { version = "6.0.1", default-features = false, features = ["macos_kqueue"] }
notify = { version = "6.0.1", default-features = false, features = [
"macos_kqueue",
] }
regex = "1.9.1"
time = { version = "0.3.25", features = ["macros"] }
time = { version = "0.3.25", features = ["macros", "local-offset"] }
tauri-plugin-deep-link = "0.1.1"
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
opener = "0.6.1"
Expand Down
8 changes: 8 additions & 0 deletions owmods_gui/backend/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use owmods_core::{
};
use serde::{Deserialize, Serialize};
use tauri::{api::dialog, AppHandle, Window, WindowBuilder};
use time::{macros::format_description, OffsetDateTime};
use typeshare::typeshare;

use crate::LogPort;
Expand All @@ -24,14 +25,21 @@ pub struct GameMessage {
pub port: LogPort,
pub message: SocketMessage,
pub amount: u32,
pub timestamp: String,
}

impl GameMessage {
pub fn new(port: LogPort, message: SocketMessage) -> Self {
let now = OffsetDateTime::now_local().unwrap_or(OffsetDateTime::now_utc());
Self {
port,
message,
amount: 1,
timestamp: now
.format(format_description!(
"[hour repr:12]:[minute]:[second] [period] (UTC[offset_hour sign:mandatory])"
))
.unwrap_or("Unknown".to_string()),
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions owmods_gui/backend/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ impl Logger {

pub fn write_log_to_file(&self, log_type: Level, message: &str) -> Result<()> {
let mut writer = self.writer.lock().unwrap();
let now = OffsetDateTime::now_utc()
let now = OffsetDateTime::now_local().unwrap_or(OffsetDateTime::now_utc());
let now = now
.format(format_description!("[hour]:[minute]:[second]"))
.unwrap();
.unwrap_or("Failed to get time".to_string());
let message = format!("[{}][{}] {}", now, log_type, message);
println!("{}", message);
writeln!(writer, "{}", message)?;
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 @@ -75,7 +75,7 @@ const LogRow = memo(function LogRow(props: LogRowProps) {
<ODTooltip
title={`${logLine?.message.senderName ?? "Unknown"}::${
logLine?.message.senderType ?? "Unknown"
}`}
}\n${logLine?.timestamp ?? ""}`}
>
<Typography textOverflow="ellipsis" width="100%" overflow="hidden">
{logLine?.message.senderName ?? "Unknown"}
Expand Down
1 change: 1 addition & 0 deletions owmods_gui/frontend/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export interface GameMessage {
port: LogPort;
message: SocketMessage;
amount: number;
timestamp: string;
}

export enum Language {
Expand Down

0 comments on commit e4bc3ba

Please sign in to comment.