From bd95426bfe36d8f53bcda268694aae7e9eaf1de0 Mon Sep 17 00:00:00 2001 From: gynt Date: Mon, 16 Dec 2024 23:50:11 +0100 Subject: [PATCH 1/2] initial dialog, needs shell.open correct regex to handle explorer files and urls --- resources/lang/sources/en.yaml | 2 + src-tauri/tauri.conf.json | 2 +- src/components/top-bar/top-bar.tsx | 5 ++ .../troubleshooting-button.tsx | 18 +++++++ .../troubleshooting-window.tsx | 47 +++++++++++++++++++ src/function/troubleshooting/state.ts | 25 ++++++++++ 6 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/components/top-bar/troubleshooting/troubleshooting-button.tsx create mode 100644 src/components/troubleshooting/troubleshooting-window.tsx create mode 100644 src/function/troubleshooting/state.ts diff --git a/resources/lang/sources/en.yaml b/resources/lang/sources/en.yaml index a8688160..0bb3a5b6 100644 --- a/resources/lang/sources/en.yaml +++ b/resources/lang/sources/en.yaml @@ -236,6 +236,8 @@ titlebar.alt.close: "Close" titlebar.alt.icon: "Icon" titlebar.alt.maximize: "Maximize" titlebar.alt.minimize: "Minimize" +troubleshooting.button: "Troubleshooting" +troubleshooting.title: "Troubleshooting" ucp.download.cancelled: "User cancelled the download." ucp.download.download: "Downloading new framework version." ucp.download.downloaded: "Downloaded new framework version: {{version}}. Saving to game folder." diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 2773c8c0..7ba4804c 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -52,7 +52,7 @@ ] }, "shell": { - "open": "^[A-Z]:[/\\\\]+.*" + "open": "^((mailto:\\w+)\\|(tel:\\w+)\\|(https?://\\w+)\\|([A-Z]:)).+" }, "protocol": { "asset": true, diff --git a/src/components/top-bar/top-bar.tsx b/src/components/top-bar/top-bar.tsx index b6dccbe4..e48a3c1a 100644 --- a/src/components/top-bar/top-bar.tsx +++ b/src/components/top-bar/top-bar.tsx @@ -6,6 +6,7 @@ import CreditsButton from './credits/credits-button'; import { ReloadButton } from './restart/reload-button'; import LanguageSelect from './language-select/language-select'; import { NewsButton } from './news/news-button'; +import { TroubleShootingButton } from './troubleshooting/troubleshooting-button'; // eslint-disable-next-line import/prefer-default-export export function TopBar() { @@ -19,7 +20,11 @@ export function TopBar() { + + + + ); diff --git a/src/components/top-bar/troubleshooting/troubleshooting-button.tsx b/src/components/top-bar/troubleshooting/troubleshooting-button.tsx new file mode 100644 index 00000000..acaa8fcf --- /dev/null +++ b/src/components/top-bar/troubleshooting/troubleshooting-button.tsx @@ -0,0 +1,18 @@ +import Message from '../../general/message'; +import { setOverlayContent } from '../../overlay/overlay'; +import { Troubleshooting } from '../../troubleshooting/troubleshooting-window'; + +// eslint-disable-next-line import/prefer-default-export +export function TroubleShootingButton() { + return ( + + ); +} diff --git a/src/components/troubleshooting/troubleshooting-window.tsx b/src/components/troubleshooting/troubleshooting-window.tsx new file mode 100644 index 00000000..e12f7fd9 --- /dev/null +++ b/src/components/troubleshooting/troubleshooting-window.tsx @@ -0,0 +1,47 @@ +import { atom, useAtomValue } from 'jotai'; +import { TROUBLESHOOTING_MD_CONTENT_ATOM } from '../../function/troubleshooting/state'; +import Message from '../general/message'; +import { SaferMarkdown } from '../markdown/safer-markdown'; +import { OverlayContentProps } from '../overlay/overlay'; + +export const TROUBLESHOOTING_MD_ATOM = atom((get) => { + const { isSuccess, data } = get(TROUBLESHOOTING_MD_CONTENT_ATOM); + + if (!isSuccess) { + return ( + + Cannot display Troubleshooting document at this time + + ); + } + + return {data}; +}); + +export function Troubleshooting(props: OverlayContentProps) { + const { closeFunc } = props; + const md = useAtomValue(TROUBLESHOOTING_MD_ATOM); + return ( +
+

+ +

+
+
{md}
+
+ +
+ ); +} diff --git a/src/function/troubleshooting/state.ts b/src/function/troubleshooting/state.ts new file mode 100644 index 00000000..614a68e5 --- /dev/null +++ b/src/function/troubleshooting/state.ts @@ -0,0 +1,25 @@ +import { atomWithQuery } from 'jotai-tanstack-query'; +import { ResponseType } from '@tauri-apps/api/http'; +import { fetch } from '../../tauri/tauri-http'; + +// https://raw.githubusercontent.com/UnofficialCrusaderPatch/UnofficialCrusaderPatch/refs/heads/main/TROUBLESHOOTING.md +// eslint-disable-next-line import/prefer-default-export +export const TROUBLESHOOTING_MD_CONTENT_ATOM = atomWithQuery(() => ({ + queryKey: ['troubleshooting'], + queryFn: async () => { + const request = await fetch( + 'https://raw.githubusercontent.com/UnofficialCrusaderPatch/UnofficialCrusaderPatch/refs/heads/main/TROUBLESHOOTING.md', + { + responseType: ResponseType.Text, + method: 'GET', + }, + ); + + if (!request.ok) { + return 'Failed to fetch Troubleshooting document'; + } + + return request.data; + }, + staleTime: Infinity, +})); From 4fbabc30ebc37204b976af7163a2e38f22e15079 Mon Sep 17 00:00:00 2001 From: gynt Date: Wed, 18 Dec 2024 10:03:24 +0100 Subject: [PATCH 2/2] fixed shell.open in tauri.conf.json such that it opens links and file folders --- src-tauri/tauri.conf.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 7ba4804c..1a82ead7 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -52,7 +52,7 @@ ] }, "shell": { - "open": "^((mailto:\\w+)\\|(tel:\\w+)\\|(https?://\\w+)\\|([A-Z]:)).+" + "open": "^((mailto:\\w+)|(tel:\\w+)|(https?://\\w+)|([A-Z]:)).+" }, "protocol": { "asset": true,