Skip to content

Commit

Permalink
Fix bad link logic when opening asset uris directly (resolves #601)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanH committed Jul 29, 2024
1 parent c981b0b commit 0bb7e9c
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,16 @@ Vue.mixin({
this.$root.$children[0].$refs[this.$localData.tabData.activeTabKey][0].$refs.modal.open(to)
},
$openLink(url, auxClick = false) {
// Open a link. Could be intra-app, external, or an assets:// uri
//
const re_local = new RegExp(`(${app_domain}|app:\/\/\\.(index)?)`)
const re_local_index = new RegExp(`(${app_domain}|app:\/\/\\.\/)index\\.html\\??`)
// const re_local_asset = new RegExp(`(http:\/\/127.0.0.1:${port}\/|assets:\/\/)`)

// Normalize implied proto://./index.html links back to proto://./
const url_str = url.replace(re_local_index, '$1')
const urlObject = new URL(url_str)

if (urlObject.protocol == "assets:" && !/\.(html|pdf)$/i.test(url)) {
this.$openModal(Resources.resolveAssetsProtocol(url))
return
}

// Else, tests
let to = (/mspaintadventures/.test(urlObject.href) && !!urlObject.search) ? urlObject.href : urlObject.pathname
to = to.replace(/.*mspaintadventures.com\/(\w*\.php)?\?s=(\w*)&p=(\w*)/, "/mspa/$3")
.replace(/.*mspaintadventures.com\/\?s=(\w*)/, "/mspa/$1")

function _openExternal(to_) {
if (!isWebApp) {
shell.openExternal(to_)
Expand All @@ -162,6 +155,22 @@ Vue.mixin({
}
}

// If asset, open in modal or externally as appropriate
if (urlObject.protocol == "assets:") {
const to_ = Resources.resolveAssetsProtocol(url)
if (!/\.(html|pdf)$/i.test(url)) {
this.$openModal(to_)
} else {
_openExternal(to_)
}
return
}

// Else, tests on a real link
let to = (/mspaintadventures/.test(urlObject.href) && !!urlObject.search) ? urlObject.href : urlObject.pathname
to = to.replace(/.*mspaintadventures.com\/(\w*\.php)?\?s=(\w*)&p=(\w*)/, "/mspa/$3")
.replace(/.*mspaintadventures.com\/\?s=(\w*)/, "/mspa/$1")

if (!re_local.test(urlObject.origin)) {
// Link is external
if (urlObject.href.includes('steampowered.com/app')) {
Expand Down

0 comments on commit 0bb7e9c

Please sign in to comment.