Skip to content

Commit 68f0912

Browse files
Make links in server announcements open in shell
1 parent 7974313 commit 68f0912

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: app/components/LoginModal.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const CONTROL_ID_NEW_PASSWORD = "newPassword";
2727
const CONTROL_ID_CONFIRM_PASSWORD = "confirmPassword";
2828
const CONTROL_ID_EMAIL = "email";
2929

30+
const replaceLinksWithShellOpen = (html: string) => {
31+
return html.replace(/<a href="([^"]+)">([^<]+)<\/a>/g, (match, href, text) => {
32+
return `<a href="#" onclick="window.__TAURI__.shell.open('${href}'); return false;">${text}</a>`;
33+
});
34+
};
35+
3036
const getUpsellImage = (server?: ServerEntry) => {
3137
if (server?.endpoint) {
3238
// HACK: add the counter to the url as a parameter to prevent caching across reloads
@@ -66,7 +72,9 @@ function AnnouncementsPanel({ server }: { server?: ServerEntry }) {
6672
);
6773
setError(false);
6874
const parsed: string = await parse(announcements);
69-
setAnnouncements(parsed);
75+
const sanitized: string = DOMPurify.sanitize(parsed);
76+
const linksReplaced: string = replaceLinksWithShellOpen(sanitized);
77+
setAnnouncements(linksReplaced);
7078
setShowAnnouncements(true);
7179
} catch (e) {
7280
console.warn(e);
@@ -92,7 +100,7 @@ function AnnouncementsPanel({ server }: { server?: ServerEntry }) {
92100
alt="Upsell"
93101
/>
94102
<div className="announcements">
95-
{error ? ERROR_TEXT : <div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(announcements) }} />}
103+
{error ? ERROR_TEXT : <div dangerouslySetInnerHTML={{ __html: announcements }} />}
96104
</div>
97105
</div>
98106
);

Diff for: src-tauri/tauri.conf.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"visible": false
2424
}
2525
],
26+
"withGlobalTauri": true,
2627
"security": {
2728
"csp": null
2829
}

0 commit comments

Comments
 (0)