Skip to content

Commit

Permalink
fix: better patch
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Oct 7, 2024
1 parent 8e67180 commit e010b39
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src-tauri/patches/tauri-plugin-shell+2.0.1.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
diff --git a/src/init-iife.js b/src/init-iife.js
index 3c91c81..4600fc4 100644
index 3c91c81..0adeb19 100644
--- a/src/init-iife.js
+++ b/src/init-iife.js
@@ -1 +1,7 @@
@@ -1 +1,16 @@
-!function(){"use strict";async function e(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}function t(){document.querySelector("body")?.addEventListener("click",(function(t){let n=t.target;for(;n;){if(n.matches("a")){const r=n;""!==r.href&&["http://","https://","mailto:","tel:"].some((e=>r.href.startsWith(e)))&&"_blank"===r.target&&(e("plugin:shell|open",{path:r.href}),t.preventDefault());break}n=n.parentElement}}))}"function"==typeof SuppressedError&&SuppressedError,"complete"===document.readyState||"interactive"===document.readyState?t():window.addEventListener("DOMContentLoaded",t,!0)}();
+const discordReg = /https?:\/\/(?:[a-z]+\.)?(?:discord\.com|discordapp\.com)(?:\/.*)?/g
+
+function sameOrigin(a, b) {
+ const uA = new URL(a)
+ const uB = new URL(b)
+ return uA.origin === uB.origin;
+ const uA = new URL(stripDiscordSubdomain(a))
+ const uB = new URL(stripDiscordSubdomain(b))
+ return uA.origin === uB.origin
+}
+
+function stripDiscordSubdomain(link) {
+ // If this isn't a discord link, just return the link
+ if (!link.match(discordReg)) return link
+
+ return link.replace(/canary\.|ptb\.|www\./g, '')
+}
+
+!function(){"use strict";async function e(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}function t(){document.querySelector("body")?.addEventListener("click",(function(t){let n=t.target;for(;n;){if(n.matches("a")){const r=n;""!==r.href&&["http://","https://","mailto:","tel:"].some((e=>r.href.startsWith(e)))&&"_blank"===r.target&&!sameOrigin(r.href, window.location.href)&&(e("plugin:shell|open",{path:r.href}),t.preventDefault());break}n=n.parentElement}}),true)}"function"==typeof SuppressedError&&SuppressedError,"complete"===document.readyState||"interactive"===document.readyState?t():window.addEventListener("DOMContentLoaded",t,!0)}();

0 comments on commit e010b39

Please sign in to comment.