Fix backend errors

This commit is contained in:
Ben C 2024-08-09 12:46:26 -04:00
parent 5c3e1842c8
commit 30cf1c1828
No known key found for this signature in database
27 changed files with 1601 additions and 2984 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@ result
scripts/
owmods.tar.zst
owmods_gui/frontend/stats.html
owmods_gui/backend/gen
# Logs
*.log

3388
Cargo.lock generated

File diff suppressed because it is too large Load Diff

6
flake.lock generated
View File

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1721373214,
"narHash": "sha256-crpGeGQGFlnCsMyCE5eheyjzo3xo03o1FXJ2sAbm7No=",
"lastModified": 1723151389,
"narHash": "sha256-9AVY0ReCmSGXHrlx78+1RrqcDgVSRhHUKDVV1LLBy28=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "af9c15bc7a314c226d7d5d85e159f7a73e8d9fae",
"rev": "13fe00cb6c75461901f072ae62b5805baef9f8b2",
"type": "github"
},
"original": {

View File

@ -16,7 +16,7 @@ pkgs.mkShell {
gtk3
libsoup
librsvg
cargo-tauri
(pkgs.callPackage ./tauri-cli.nix {})
typeshare
];
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";

52
nix/tauri-cli.nix Normal file
View File

@ -0,0 +1,52 @@
{
lib,
stdenv,
rustPlatform,
fetchFromGitHub,
openssl,
pkg-config,
glibc,
libsoup,
cairo,
gtk3,
webkitgtk,
darwin,
}:
# Temp because nix moment!
let
inherit (darwin.apple_sdk.frameworks) CoreServices Security SystemConfiguration;
in
rustPlatform.buildRustPackage rec {
pname = "tauri";
version = "2.0.0-rc.2";
src = fetchFromGitHub {
owner = "tauri-apps";
repo = pname;
rev = "tauri-v${version}";
hash = "sha256-V3Lck5RzEAxXRHPAy0M2elRk9geF8qHWoi01N6wcHc4=";
};
# Manually specify the sourceRoot since this crate depends on other crates in the workspace. Relevant info at
# https://discourse.nixos.org/t/difficulty-using-buildrustpackage-with-a-src-containing-multiple-cargo-workspaces/10202
sourceRoot = "${src.name}/tooling/cli";
cargoHash = "sha256-fGnre+vPzWtpp9NLLQtb/Feh06pBQipkCQ2kFCDTC+Y=";
buildInputs =
[openssl]
++ lib.optionals stdenv.isLinux [glibc libsoup cairo gtk3 webkitgtk]
++ lib.optionals stdenv.isDarwin [CoreServices Security SystemConfiguration];
nativeBuildInputs = [pkg-config];
meta = with lib; {
description = "Build smaller, faster, and more secure desktop applications with a web frontend";
mainProgram = "cargo-tauri";
homepage = "https://tauri.app/";
license = with licenses; [
asl20
mit
];
maintainers = with maintainers; [dit7ya happysalada];
};
}

View File

@ -9,13 +9,13 @@ license = "GPL-3.0-or-later"
edition = "2021"
[build-dependencies]
tauri-build = { version = "2.0.0-alpha.8", features = [] }
tauri-build = { version = "2.0.0-rc.2", features = [] }
[dependencies]
owmods_core = { version = "0.12.0", path = "../../owmods_core" }
owmods_core = { version = "0.14.2", path = "../../owmods_core" }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "2.0.0-alpha", features = [] }
tauri = { version = "2.0.0-rc.2", features = [] }
anyhow = "1.0.75"
tokio = { version = "1.32.0", features = ["sync", "macros"] }
log = { version = "0.4.20", features = ["std", "serde"] }
@ -27,13 +27,12 @@ regex = "1.9.3"
time = { version = "0.3.25", features = ["macros", "local-offset"] }
tauri-plugin-deep-link = "0.1.2"
opener = "0.6.1"
tauri-plugin-window = "2.0.0-alpha.1"
tauri-plugin-dialog = "2.0.0-alpha.1"
tauri-plugin-updater = "2.0.0-alpha.1"
tauri-plugin-os = "2.0.0-alpha.1"
tauri-plugin-app = "2.0.0-alpha.1"
tauri-plugin-shell = "2.0.0-alpha.1"
tauri-plugin-clipboard-manager = "2.0.0-beta.0"
tauri-plugin-dialog = "2.0.0-rc.0"
tauri-plugin-updater = "2.0.0-rc.0"
tauri-plugin-os = "2.0.0-rc.0"
tauri-plugin-shell = "2.0.0-rc.0"
tauri-plugin-process = "2.0.0-rc.0"
tauri-plugin-clipboard-manager = "2.0.0-rc.0"
[features]
default = ["custom-protocol"]

View File

@ -0,0 +1,22 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "main-capabilities",
"local": true,
"windows": [
"main",
"logs",
"game-*"
],
"permissions": [
"core:window:allow-set-title",
"core:window:allow-set-focus",
"core:window:allow-show",
"core:window:allow-close",
"core:window:allow-destroy",
"core:webview:allow-internal-toggle-devtools",
"core:app:allow-version",
"core:event:default",
"dialog:default",
"shell:allow-open"
]
}

View File

@ -32,22 +32,18 @@ use owmods_core::{
validate::fix_deps,
};
use serde::Serialize;
use tauri::{async_runtime, AppHandle, FileDropEvent, Manager, WindowEvent};
use tauri::{async_runtime, AppHandle, DragDropEvent, Manager, WindowEvent};
use tauri_plugin_dialog::{DialogExt, MessageDialogKind};
use tokio::{sync::mpsc, try_join};
use tokio::{select, sync::mpsc, try_join};
use typeshare::typeshare;
use crate::events::{CustomEventEmitter, CustomEventEmitterAll, Event};
use crate::game::LogData;
use crate::RemoteDatabaseOption;
use crate::{
error::{Error, Result},
events::CustomEventListener,
};
use crate::{
events::{CustomEventEmitter, CustomEventEmitterAll, CustomEventTriggerGlobal, Event},
events::{CustomEventEmitter, CustomEventEmitterAll, Event},
protocol::PROTOCOL_LISTENER_AMOUNT,
};
use crate::{events::CustomEventListener, game::LogData};
use crate::{
game::{make_log_window, show_warnings, GameMessage},
gui_config::GuiConfig,
@ -215,9 +211,7 @@ pub async fn refresh_remote_db(handle: tauri::AppHandle, state: tauri::State<'_,
};
if first_load {
handle
.typed_emit_all(&Event::RemoteInitialized(()))
.ok();
handle.typed_emit_all(&Event::RemoteInitialized(())).ok();
}
handle.typed_emit_all(&Event::RemoteRefresh(())).ok();
@ -926,9 +920,9 @@ pub async fn db_has_issues(state: tauri::State<'_, State>, window: tauri::Window
.blocking_show();
if answer {
let handle = window.app_handle();
mark_mod_busy(OWML_UNIQUE_NAME, true, true, &state, &handle).await;
mark_mod_busy(OWML_UNIQUE_NAME, true, true, &state, handle).await;
download_and_install_owml(&config, remote_owml.unwrap(), false).await?;
mark_mod_busy(OWML_UNIQUE_NAME, false, true, &state, &handle).await;
mark_mod_busy(OWML_UNIQUE_NAME, false, true, &state, handle).await;
let event = Event::RequestReload("LOCAL".to_string());
handle.typed_emit_all(&event).unwrap();
} else {
@ -1076,9 +1070,9 @@ pub async fn has_disabled_deps(unique_name: &str, state: tauri::State<'_, State>
pub async fn register_drop_handler(window: tauri::Window) -> Result {
let handle = window.app_handle().clone();
window.on_window_event(move |e| {
if let WindowEvent::FileDrop(e) = e {
if let WindowEvent::DragDrop(e) = e {
match e {
FileDropEvent::Dropped { paths, position: _ } => {
DragDropEvent::Drop { paths, position: _ } => {
if let Some(f) = paths.first() {
if f.extension().map(|e| e == "zip").unwrap_or(false) {
handle.typed_emit_all(&Event::DragLeave(())).ok();
@ -1091,14 +1085,14 @@ pub async fn register_drop_handler(window: tauri::Window) -> Result {
}
}
}
FileDropEvent::Hovered { paths, position: _ } => {
DragDropEvent::Enter { paths, position: _ } => {
if let Some(f) = paths.first() {
if f.extension().map(|e| e == "zip").unwrap_or(false) {
handle.typed_emit_all(&Event::DragEnter(())).ok();
}
}
}
FileDropEvent::Cancelled => {
DragDropEvent::Leave => {
handle.typed_emit_all(&Event::DragLeave(())).ok();
}
_ => {}

View File

@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use owmods_core::protocol::ProtocolPayload;
use serde::{Deserialize, Serialize};
use tauri::{AppHandle, Manager, Window};
use tauri::{AppHandle, Emitter, Listener, Window};
use typeshare::typeshare;
use crate::{game::GameMessage, LogPort};
@ -64,10 +64,6 @@ pub trait CustomEventEmitter {
fn typed_emit(&self, event: &Event) -> Result<()>;
}
pub trait CustomEventTriggerGlobal {
fn typed_trigger_global(&self, event: &Event) -> Result<()>;
}
pub trait CustomEventEmitterAll {
fn typed_emit_all(&self, event: &Event) -> Result<()>;
}
@ -82,24 +78,15 @@ impl CustomEventEmitterAll for AppHandle {
}
}
// impl CustomEventTriggerGlobal for AppHandle {
// fn typed_trigger_global(&self, event: &Event) -> Result<()> {
// self.trigger(INVOKE_URI, Some(serde_json::to_string(event).unwrap()));
// Ok(())
// }
// }
impl CustomEventListener for AppHandle {
fn typed_listen<F: Fn(Event) + Send + Sync + 'static>(&self, f: F) {
self.clone()
.listen_global(INVOKE_URI, move |e: tauri::Event| {
let event = e
.payload();
let event = serde_json::from_str::<Event>(event).ok();
if let Some(event) = event {
f(event);
}
});
self.clone().listen_any(INVOKE_URI, move |e: tauri::Event| {
let event = e.payload();
let event = serde_json::from_str::<Event>(event).ok();
if let Some(event) = event {
f(event);
}
});
}
}

View File

@ -7,7 +7,7 @@ use anyhow::Result;
use log::{error, info};
use notify::{Event, EventKind, RecursiveMode, Watcher};
use owmods_core::config::Config;
use tauri::{AppHandle, Manager};
use tauri::{AppHandle, Listener, Manager};
use crate::{
events::{CustomEventEmitterAll, Event as CustomEvent},
@ -62,7 +62,7 @@ pub fn setup_fs_watch(handle: AppHandle) -> Result<()> {
let e_handle = handle.clone();
handle.listen_global("owmods://events/invoke", move |e| {
handle.listen_any("owmods://events/invoke", move |e| {
let payload = serde_json::from_str::<CustomEvent>(e.payload());
if let Ok(payload) = payload {

View File

@ -15,7 +15,7 @@ use owmods_core::{
socket::{SocketMessage, SocketMessageType},
};
use serde::{Deserialize, Serialize};
use tauri::{AppHandle, Window, WindowBuilder};
use tauri::{AppHandle, WebviewWindow, WebviewWindowBuilder, Window};
use tauri_plugin_dialog::{DialogExt, MessageDialogKind};
use time::{macros::format_description, OffsetDateTime};
use typeshare::typeshare;
@ -284,15 +284,15 @@ impl Drop for LogData {
}
}
pub async fn make_log_window(handle: &AppHandle) -> Result<Window> {
pub async fn make_log_window(handle: &AppHandle) -> Result<WebviewWindow> {
let epoch = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis();
let log_window = WindowBuilder::new(
let log_window = WebviewWindowBuilder::new(
handle,
format!("game-{epoch}"),
tauri::WindowUrl::App("/logs/index.html".parse()?),
tauri::WebviewUrl::App("/logs/index.html".parse()?),
);
let window = log_window
.center()

View File

@ -153,11 +153,9 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(())
})
.plugin(tauri_plugin_app::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_window::init())
.invoke_handler(tauri::generate_handler![
initial_setup,
refresh_local_db,

View File

@ -2,94 +2,34 @@
"build": {
"beforeBuildCommand": "cd frontend && npm run build",
"beforeDevCommand": "cd frontend && npm run dev",
"devPath": "http://localhost:5173",
"distDir": "../dist"
},
"package": {
"productName": "Outer Wilds Mod Manager"
"devUrl": "http://localhost:5173",
"frontendDist": "../dist"
},
"productName": "Outer Wilds Mod Manager",
"identifier": "com.bwc9876.owmods-gui",
"plugins": {
"shell": {
"open": "^(^https:(www\\.)?//github.com/)|(^https://(www\\.)?discord.gg/wusTQYbYTc$)|(^https://(www\\.)?outerwildsmods.com/)|(^https://(www\\.)?patreon.com/)|(^https://(www\\.)?paypal.me/)"
"open": "(^https://(www\\.)?(github.com|outerwildsmods.com|paypal.me|patreon.com|buymeacoffee.com|cash.app|ko-fi.com)/)|(^https://(www\\.)?discord.gg/wusTQYbYTc$)"
},
"updater": {
"active": true,
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDkzRURBNzdENEVCREU1NDYKUldSRzViMU9mYWZ0azRoODZIdmVGWUZxVTNQRUVXU2hOTllqcGM4N2RRNjFEN2N3cnhXbW45V0sK",
"windows": {
"installMode": "basicUi"
},
"active": true,
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDkzRURBNzdENEVCREU1NDYKUldSRzViMU9mYWZ0azRoODZIdmVGWUZxVTNQRUVXU2hOTllqcGM4N2RRNjFEN2N3cnhXbW45V0sK",
"windows": {
"installMode": "basicUi"
},
"endpoints": [
"https://github.com/Bwc9876/ow-mod-man/releases/latest/download/latest.json",
"https://github.com/ow-mods/ow-mod-man/releases/latest/download/latest.json"
]
}
},
"tauri": {
"bundle": {
"active": true,
"category": "Game",
"copyright": "",
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.bwc9876.owmods-gui",
"longDescription": "A manager for Outer Wilds mods",
"macOS": {
"license": "../../LICENSE"
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"nsis": {
"headerImage": "installer-images/nsis/Header.bmp",
"installMode": "both",
"installerIcon": "icons/icon.ico",
<<<<<<< HEAD
"license": "../../LICENSE"
=======
"license": "../../LICENSE",
"sidebarImage": "installer-images/nsis/Sidebar.bmp"
>>>>>>> dev
},
"timestampUrl": "",
"wix": {
"bannerPath": "installer-images/wix/TopBanner.png",
"dialogImagePath": "installer-images/wix/Background.png",
"license": "../../LICENSE"
}
}
},
"app": {
"security": {
<<<<<<< HEAD
"csp": "default-src 'self'; img-src 'self' https://ow-mods.github.io; style-src 'self' 'unsafe-inline'; font-src 'self' data:; connect-src ipc: https://ipc.localhost",
"csp": "default-src 'self'; img-src 'self' https://ow-mods.github.io; style-src 'self' 'unsafe-inline'; font-src 'self' data:",
"dangerousDisableAssetCspModification": [
"style-src",
"font-src"
]
=======
"csp": "default-src 'self'; img-src 'self' https://ow-mods.github.io; style-src 'self' 'unsafe-inline'; font-src 'self' data:",
"dangerousDisableAssetCspModification": ["style-src", "font-src"]
},
"updater": {
"active": true,
"dialog": true,
"endpoints": [
"https://github.com/Bwc9876/ow-mod-man/releases/latest/download/latest.json",
"https://github.com/ow-mods/ow-mod-man/releases/latest/download/latest.json"
],
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDkzRURBNzdENEVCREU1NDYKUldSRzViMU9mYWZ0azRoODZIdmVGWUZxVTNQRUVXU2hOTllqcGM4N2RRNjFEN2N3cnhXbW45V0sK",
"windows": {
"installMode": "basicUi"
}
>>>>>>> dev
},
"windows": [
{
@ -102,5 +42,39 @@
"width": 850
}
]
},
"bundle": {
"active": true,
"category": "Game",
"copyright": "",
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"longDescription": "A manager for Outer Wilds mods",
"licenseFile": "../../LICENSE",
"macOS": {},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"nsis": {
"headerImage": "installer-images/nsis/Header.bmp",
"installMode": "both",
"installerIcon": "icons/icon.ico",
"sidebarImage": "installer-images/nsis/Sidebar.bmp"
},
"timestampUrl": "",
"wix": {
"bannerPath": "installer-images/wix/TopBanner.png",
"dialogImagePath": "installer-images/wix/Background.png"
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,8 @@
"lint": "tsc --noEmit && eslint --cache . --fix",
"lint-dry": "tsc --noEmit && eslint .",
"prettify": "prettier --write . --ignore-unknown",
"prettier-check": "prettier --check . --ignore-unknown"
"prettier-check": "prettier --check . --ignore-unknown",
"tauri": "tauri"
},
"dependencies": {
"@emotion/react": "11.13.0",
@ -25,18 +26,19 @@
"@mui/icons-material": "5.16.6",
"@mui/lab": "5.0.0-alpha.173",
"@mui/material": "5.16.6",
"@tauri-apps/api": "2.0.0-beta.0",
"@tauri-apps/plugin-app": "2.0.0-alpha.1",
"@tauri-apps/plugin-clipboard-manager": "2.0.0-beta.0",
"@tauri-apps/plugin-dialog": "2.0.0-beta.0",
"@tauri-apps/plugin-os": "2.0.0-beta.0",
"@tauri-apps/plugin-shell": "2.0.0-beta.0",
"@tauri-apps/api": "2.0.0-rc.0",
"@tauri-apps/plugin-clipboard-manager": "2.0.0-rc.0",
"@tauri-apps/plugin-dialog": "2.0.0-rc.0",
"@tauri-apps/plugin-os": "2.0.0-rc.0",
"@tauri-apps/plugin-process": "2.0.0-rc.0",
"@tauri-apps/plugin-shell": "2.0.0-rc.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-error-boundary": "4.0.13",
"react-virtuoso": "4.9.0"
},
"devDependencies": {
"@tauri-apps/cli": "^2.0.0-rc.2",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@typescript-eslint/eslint-plugin": "7.18.0",

View File

@ -107,7 +107,7 @@ const makeInvoke = (key: Command, forceNoDisplayErr?: boolean) => {
>;
if (!(forceNoDisplayErr ?? false) && (displayErr ?? true)) {
promise.catch((e) => {
dialog.message(e, { type: "error", title: `Error (${name})` });
dialog.message(e, { kind: "error", title: `Error (${name})` });
});
}
return promise;

View File

@ -1,11 +1,11 @@
import { useState, useCallback, useEffect, memo, useRef } from "react";
import { commands, hooks } from "@commands";
import BaseApp from "@components/common/BaseApp";
import { TranslationMap } from "@components/common/TranslationContext";
import { useGetTranslation } from "@hooks";
import * as dialog from "@tauri-apps/plugin-dialog";
import { getCurrent } from "@tauri-apps/api/window";
import { SocketMessageType } from "@types";
import { useState, useCallback, useEffect, memo, useRef } from "react";
import * as window from "@tauri-apps/api/window";
import LogHeader from "./LogHeader";
import { Container, useTheme } from "@mui/material";
import LogTable from "./LogTable";
@ -15,7 +15,7 @@ import { simpleOnError } from "../../errorHandling";
export type LogFilter = keyof typeof SocketMessageType | "Any";
export type LogLines = number[];
const thisWindow = getCurrent();
const thisWindow = window.getCurrentWindow();
const getFilterToPass = (activeFilter: LogFilter) => {
if (activeFilter === "Any") {
@ -58,7 +58,7 @@ const InnerLogApp = memo(function InnerLogApp({ port }: { port: number }) {
listen("logFatal", (msg) => {
if (msg.port !== port) return;
dialog.message(`[${msg.message.senderName ?? "Unknown"}]: ${msg.message.message}`, {
type: "error",
kind: "error",
title: getTranslation("FATAL_ERROR")
});
});

View File

@ -1,12 +1,13 @@
import { ReactNode, Suspense, lazy, memo, useCallback, useEffect, useMemo, useState } from "react";
import { Box } from "@mui/material";
import TopBar from "./top-bar/TopBar";
import { ReactNode, Suspense, lazy, memo, useCallback, useEffect, useMemo, useState } from "react";
import { TabContext } from "@mui/lab";
import AppTabs, { ModsTab } from "./top-bar/AppTabs";
import LocalModsPage from "./mods/local/LocalModsPage";
import { TranslationKey, TranslationMap } from "@components/common/TranslationContext";
import { commands, hooks } from "@commands";
import { getCurrent } from "@tauri-apps/api/window";
import { getCurrentWindow } from "@tauri-apps/api/window";
import * as process from "@tauri-apps/plugin-process";
import AppAlert from "./AppAlert";
import BaseApp from "@components/common/BaseApp";
import OwmlModal from "./OwmlModal";
@ -15,7 +16,6 @@ import { simpleOnError } from "../../errorHandling";
import { useErrorBoundary } from "react-error-boundary";
import FileDrop from "./FileDrop";
import { Event } from "@types";
import { process } from "@tauri-apps/api";
const RemoteModsPage = lazy(() => import("./mods/remote/RemoteModsPage"));
const UpdateModsPage = lazy(() => import("./mods/updates/UpdateModsPage"));
@ -112,7 +112,7 @@ const InnerMainApp = memo(function InnerMainApp() {
);
});
const thisWindow = getCurrent();
const thisWindow = getCurrentWindow();
thisWindow.onCloseRequested(() => {
process.exit(0); // Exit the app on this window closing, so the log window doesn't stay open

View File

@ -63,7 +63,7 @@ const OwmlModal = memo(function OwmlModal() {
: "OWML_INSTALL_ERROR"
)}\n\n${e}`,
{
type: "error",
kind: "error",
title: getTranslation("FATAL_ERROR")
}
);

View File

@ -11,7 +11,7 @@ import {
} from "react";
import ModActionIcon from "./ModActionIcon";
import { useGetTranslation } from "@hooks";
import clipboard from "@tauri-apps/plugin-clipboard-manager";
import * as clipboard from "@tauri-apps/plugin-clipboard-manager";
export interface ModActionOverflowProps {
tabId: string;

View File

@ -9,7 +9,7 @@ import {
LocalParkingRounded
} from "@mui/icons-material";
import ModActionIcon from "../ModActionIcon";
import shell from "@tauri-apps/plugin-shell";
import * as shell from "@tauri-apps/plugin-shell";
export interface LocalModDonateIconProps {
uniqueName: string;

View File

@ -3,7 +3,6 @@ import ModRow from "../ModRow";
import { memo, useCallback, useMemo } from "react";
import { useGetTranslation, useUnifiedMod } from "@hooks";
import * as dialog from "@tauri-apps/plugin-dialog";
import * as shell from "@tauri-apps/plugin-shell";
import LocalModActions from "./LocalModActions";
import { LocalMod, RemoteMod, UnsafeLocalMod } from "@types";
@ -118,7 +117,7 @@ const LocalModRow = memo(function LocalModRow(props: LocalModRowProps) {
enableDeps =
autoEnableDeps ||
(await dialog.ask(getTranslation("ENABLE_DEPS_MESSAGE"), {
type: "info",
kind: "info",
title: getTranslation("CONFIRM")
}));
}
@ -130,7 +129,7 @@ const LocalModRow = memo(function LocalModRow(props: LocalModRowProps) {
commands.refreshLocalDb();
for (const modName of warnings) {
dialog.message(getTranslation("PREPATCHER_WARNING", { name: modName }), {
type: "warning",
kind: "warning",
title: getTranslation("PREPATCHER_WARNING_TITLE", {
name: modName
})
@ -149,7 +148,7 @@ const LocalModRow = memo(function LocalModRow(props: LocalModRowProps) {
commands.refreshLocalDb();
for (const modName of warnings) {
dialog.message(getTranslation("PREPATCHER_WARNING", { name: modName }), {
type: "warning",
kind: "warning",
title: getTranslation("PREPATCHER_WARNING_TITLE", { name: modName })
});
}

View File

@ -23,7 +23,7 @@ const StartGameButton = () => {
const skipWarning = (await commands.getGuiConfig()).noWarning;
if (!skipWarning && hasIssues) {
const yes = await dialog.ask(getTranslation("LAUNCH_ANYWAY"), {
type: "warning",
kind: "warning",
title: getTranslation("CONFIRM")
});
if (yes) {

View File

@ -14,12 +14,11 @@ import {
IconButton
} from "@mui/material";
import * as os from "@tauri-apps/plugin-os";
import * as app from "@tauri-apps/plugin-app";
import * as app from "@tauri-apps/api/app";
import * as shell from "@tauri-apps/plugin-shell";
import { memo, useCallback, useEffect, useState } from "react";
import logo from "@assets/images/logo.png?w=256&h=256&format=webp&imagetools";
import ODTooltip from "@components/common/ODTooltip";
import { commands } from "@commands";
export interface ModalProps {
onClick?: () => void;
@ -32,35 +31,21 @@ const About = memo(function About({ onClick }: ModalProps) {
const getTranslation = useGetTranslation();
const [open, setOpen] = useState(false);
const [appVersion, setVersion] = useState("");
const [appPlatform, setPlatform] = useState("");
const [archRaw, setArch] = useState("");
const [appVersion, setVersion] = useState<string | null>(null);
useEffect(() => {
const onErr = (e: string) => {
commands.logError({ err: e.toString() });
};
app.getVersion()
.then(setVersion)
.then((version) => {
setVersion(version);
})
.catch((e) => {
onErr(e);
console.error(`Failed to get app version: ${e}`);
setVersion("Error");
});
os.platform()
.then(setPlatform)
.catch((e) => {
onErr(e);
setPlatform("Error");
});
os.arch()
.then(setArch)
.catch((e) => {
onErr(e);
setArch("Error");
});
}, []);
});
const appPlatform = os.platform();
const arch = os.arch();
const handleClick = useCallback(() => {
setOpen(true);
@ -113,7 +98,7 @@ const About = memo(function About({ onClick }: ModalProps) {
<br />
{getTranslation("PLATFORM", { platform: appPlatform })}
<br />
{getTranslation("ARCHITECTURE", { arch: archRaw })}
{getTranslation("ARCHITECTURE", { arch })}
<br />
{commitHash ?? ""}
</DialogContentText>

View File

@ -23,7 +23,7 @@ import {
} from "@mui/material";
import { ProtocolVerb } from "@types";
import { commands } from "@commands";
import { getCurrent } from "@tauri-apps/api/window";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { OpenFileInput } from "@components/common/FileInput";
import { listen } from "@events";
import { simpleOnError } from "../../../../errorHandling";
@ -69,7 +69,7 @@ const InstallFrom = memo(function InstallFrom({ onClick }: ModalProps) {
if (valid) {
const sourceType = getSourceTypeFromProtocol(protocolPayload.verb);
if (sourceType !== null) {
getCurrent().setFocus().catch(simpleOnError);
getCurrentWindow().setFocus().catch(simpleOnError);
const task = async () => {
await commands.refreshRemoteDb().catch(simpleOnError);
if (sourceType === "UNIQUE_NAME") {

View File

@ -1,11 +1,4 @@
import {
ReactNode,
forwardRef,
useCallback,
useEffect,
useImperativeHandle,
useState
} from "react";
import { ReactNode, forwardRef, useCallback, useImperativeHandle, useState } from "react";
import { Config, GuiConfig, Language, OWMLConfig, Theme } from "@types";
import { useGetTranslation } from "@hooks";
import { commands } from "@commands";
@ -41,11 +34,7 @@ export interface SettingsRowProps {
tooltip?: string;
}
let defaultShowLogServerOption = false;
// Moved to out here due to #98
// Should work 99% of the time but the state is there just in case
os.platform().then((p) => (defaultShowLogServerOption = p === "windows"));
const showLogServerOption = os.platform() === "windows";
const SettingsForm = forwardRef(function SettingsForm(props: SettingsFormProps, ref) {
const [config, setConfig] = useState<Config>(props.initialConfig);
@ -54,12 +43,6 @@ const SettingsForm = forwardRef(function SettingsForm(props: SettingsFormProps,
const getTranslation = useGetTranslation();
const theme = useTheme();
const [showLogServerOption, setShowLogServerOption] = useState(defaultShowLogServerOption);
useEffect(() => {
os.platform().then((p) => setShowLogServerOption(p === "windows"));
}, []);
useImperativeHandle(
ref,
() =>

View File

@ -10,29 +10,24 @@ export default defineConfig({
publicDir: false,
clearScreen: false,
server: {
strictPort: true
strictPort: true,
watch: {
ignored: ["owmods_gui/backend/target/**"]
}
},
envPrefix: [
"VITE_",
"TAURI_PLATFORM",
"TAURI_ARCH",
"TAURI_FAMILY",
"TAURI_PLATFORM_VERSION",
"TAURI_PLATFORM_TYPE",
"TAURI_DEBUG"
],
envPrefix: ["VITE_", "TAURI_ENV_"],
plugins: [react(), imagetools()],
build: {
rollupOptions: {
input: {
main: path.resolve(__dirname, "index.html"),
logs: path.resolve(__dirname, "logs/index.html")
main: path.resolve(__dirname, "./index.html"),
logs: path.resolve(__dirname, "./logs/index.html")
}
},
outDir: "../dist",
target: process.env.TAURI_PLATFORM == "windows" ? "chrome105" : "safari13",
minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
sourcemap: !!process.env.TAURI_DEBUG
target: process.env.TAURI_ENV_PLATFORM == "windows" ? "chrome105" : "safari13",
minify: !process.env.TAURI_ENV_DEBUG ? "esbuild" : false,
sourcemap: !!process.env.TAURI_ENV_DEBUG
},
resolve: {
alias: [