improve url handler

This commit is contained in:
srgooglo 2023-11-15 19:14:57 +01:00
parent cd7e830f38
commit 3725921cc8

View File

@ -131,15 +131,27 @@ class ElectronApp {
const urlStarter = `${protocolRegistryNamespace}://` const urlStarter = `${protocolRegistryNamespace}://`
if (url.startsWith(urlStarter)) { if (url.startsWith(urlStarter)) {
const [action, value] = url.split(urlStarter)[1].split("%3E") const urlValue = url.split(urlStarter)[1]
switch (action) { const explicitAction = urlValue.split("%3E")
case "install": {
return this.sendToRender("installation:invoked", value) if (explicitAction) {
const [action, value] = explicitAction
switch (action) {
case "install": {
return this.sendToRender("installation:invoked", value)
}
default: {
return this.sendToRender("new:message", {
message: "Unrecognized URL action",
})
}
} }
} else {
default: // by default if no action is specified, assume is a install action
break; return this.sendToRender("installation:invoked", urlValue)
} }
} }
} }
@ -206,12 +218,12 @@ class ElectronApp {
}) })
if (isDev) { if (isDev) {
if (app.isDefaultProtocolClient("rsbundle")) { if (app.isDefaultProtocolClient(protocolRegistryNamespace)) {
app.removeAsDefaultProtocolClient("rsbundle") app.removeAsDefaultProtocolClient(protocolRegistryNamespace)
} }
ProtocolRegistry.register({ ProtocolRegistry.register({
protocol: "rsbundle", protocol: protocolRegistryNamespace,
command: `"${process.execPath}" "${path.resolve( command: `"${process.execPath}" "${path.resolve(
process.argv[1] process.argv[1]
)}" $_URL_`, )}" $_URL_`,
@ -220,8 +232,8 @@ class ElectronApp {
terminal: false, terminal: false,
}) })
} else { } else {
if (!app.isDefaultProtocolClient("rsbundle")) { if (!app.isDefaultProtocolClient(protocolRegistryNamespace)) {
app.setAsDefaultProtocolClient("rsbundle") app.setAsDefaultProtocolClient(protocolRegistryNamespace)
} }
} }