Skip to content

Commit

Permalink
Fix link handling bug unique to the final electron build (resolves #601)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanH committed Aug 24, 2024
1 parent e4ffe2e commit 85ccd80
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ if (!window.isWebApp) {
const Store = require('electron-store')
store = new Store()

log = require('electron-log');
log.transports.console.format = '[{level}] {text}';
log = require('electron-log')
log.transports.console.format = '[{level}] {text}'

var {port, appVersion} = ipcRenderer.sendSync('STARTUP_GET_INFO')

Expand All @@ -56,6 +56,9 @@ Number.prototype.pad = function(size) {
return this.toString().padStart(size || 2, '0')
}

function regExpEscape(literal_string) {
return literal_string.replace(/[-[\]{}()*+!<=:?.\/\\^$|#\s,]/g, '\\$&')
}

const app_domain = window.location.host // (window.isWebApp ? window.webAppDomain : 'localhost:8080')

Expand All @@ -74,19 +77,19 @@ Vue.use(localData) // Initializes and loads when Vue installs it
promises_loading.push((async function() {
const { FontAwesomeIcon } = await importFontAwesomeIconObj
Vue.component('fa-icon', FontAwesomeIcon)
})());
})())

// Mixin asynccomputed
promises_loading.push((async function() {
const AsyncComputed = await importAsyncComputed
Vue.use(AsyncComputed)
})());
})())

// Mixin mod mixins
promises_loading.push((async function() {
const mixins = await Mods.getMixinsAsync()
mixins.forEach((m) => Vue.mixin(m))
})());
})())

Vue.mixin(Memoization.mixin)

Expand Down Expand Up @@ -123,7 +126,7 @@ Vue.mixin({
if (vizNums) resolvedUrl = `/${vizNums.s}/${vizNums.p}`
} else if (this.$localData.settings.mspaMode) {
if (base == 'mspa') {
let p_padded = route.params.p.padStart(6, '0')
const p_padded = route.params.p.padStart(6, '0')
if (p_padded in this.$archive.mspa.story) resolvedUrl = `/mspa/${p_padded}`
} else if (this.$isVizBase(base)) {
// Route /homestuck/# to /mspa/#
Expand All @@ -139,8 +142,8 @@ Vue.mixin({
$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 = new RegExp(`^(${regExpEscape(app_domain)}|app:\/\/\\.(index)?)`)
const re_local_index = new RegExp(`^(${regExpEscape(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://./
Expand All @@ -151,7 +154,7 @@ Vue.mixin({
if (!window.isWebApp) {
shell.openExternal(to_)
} else {
window.open(Resources.resolveURL(to_), '_blank').focus();
window.open(Resources.resolveURL(to_), '_blank').focus()
}
}

Expand Down Expand Up @@ -190,7 +193,7 @@ Vue.mixin({
},
$getResourceURL(url) {
const resource_url = Resources.getResourceURL(url)
if (isWebApp) {
if (window.isWebApp) {
// simulate webRequest redirection here
return Resources.resolveURL(url)
} else {
Expand Down Expand Up @@ -286,7 +289,7 @@ Vue.mixin({
else if ('006369' <= thisPageId && thisPageId <= '006468') nextLimit = '006469' // Roxy+Dirk

// A6A5A1x2 COMBO
else if ('007688' <= thisPageId && thisPageId <='007825') {
else if ('007688' <= thisPageId && thisPageId <= '007825') {
// Sets the next page an extra step ahead to account for the x2 shittery
const isLeftPage = !(thisPageId % 2)
const page = this.$archive.mspa.story[thisPageId]
Expand Down Expand Up @@ -438,7 +441,7 @@ Vue.mixin({
else if (ref == 'one-year-older') date = this.$archive.mspa.story['007162'].timestamp // Just after Caliborn: Enter, before openbound 1
else if (ref == 'cherubim') date = this.$archive.mspa.story['007882'].timestamp // After Interfishin, right when Caliborn/Calliope expodump begins

else date = new Date(this.$archive.music.albums[ref].date).getTime()/1000
else date = new Date(this.$archive.music.albums[ref].date).getTime() / 1000
this.$logger.debug(ref, this.$archive.mspa.story['006716'].timestamp)
return date > this.$archive.mspa.story[this.$newReaderCurrent].timestamp
} else return false
Expand Down Expand Up @@ -481,7 +484,7 @@ Promise.all(promises_loading).then(_ => {
'$localData.settings.devMode'(to, from){
if (log.transports) {
const is_dev = to
log.transports.console.level = (is_dev ? "silly" : "info");
log.transports.console.level = (is_dev ? "silly" : "info")
this.$logger.silly("Verbose log message for devs")
this.$logger.info("Log message for everybody")
}
Expand All @@ -491,7 +494,6 @@ Promise.all(promises_loading).then(_ => {
}).$mount('#app')
})


// Even though we cancel the auxclick, reallly *really* cancel mouse navigation.
window.addEventListener("mouseup", (e) => {
if (e.button === 3 || e.button === 4){
Expand Down

0 comments on commit 85ccd80

Please sign in to comment.