From fa80a56516bd18261cbb594f416fe067d8eca4d5 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 27 Jun 2022 17:01:15 +0200 Subject: [PATCH] Add button to enable protocol handler in settings --- components/app.js | 11 ++++++++++- components/settings-form.js | 30 ++++++++++++++++++++++++++++++ style.css | 8 ++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/components/app.js b/components/app.js index 9105441..6418dbf 100644 --- a/components/app.js +++ b/components/app.js @@ -1697,7 +1697,15 @@ export default class App extends Component { } handleOpenSettingsClick() { - this.openDialog("settings"); + let showProtocolHandler = false; + for (let [id, client] of this.clients) { + if (client.caps.enabled.has("soju.im/bouncer-networks")) { + showProtocolHandler = true; + break; + } + } + + this.openDialog("settings", { showProtocolHandler }); } handleSettingsChange(settings) { @@ -1880,6 +1888,7 @@ export default class App extends Component { <${Dialog} title="Settings" onDismiss=${this.dismissDialog}> <${SettingsForm} settings=${this.state.settings} + showProtocolHandler=${dialogData.showProtocolHandler} onChange=${this.handleSettingsChange} onDisconnect=${() => this.disconnectAll()} onClose=${() => this.dismissDialog()} diff --git a/components/settings-form.js b/components/settings-form.js index 70fdf9a..415bd5a 100644 --- a/components/settings-form.js +++ b/components/settings-form.js @@ -26,7 +26,35 @@ export default class SettingsForm extends Component { this.props.onClose(); } + registerProtocol() { + let url = window.location.origin + window.location.pathname + "?open=%s"; + try { + navigator.registerProtocolHandler("irc", url); + navigator.registerProtocolHandler("ircs", url); + } catch (err) { + console.error("Failed to register protocol handler: ", err); + } + } + render() { + let protocolHandler = null; + if (this.props.showProtocolHandler) { + protocolHandler = html` +
+
+ Set gamja as your default IRC client for this browser. + IRC links will be automatically opened here. +
+
+ +
+
+

+ `; + } + return html`


+ ${protocolHandler} + diff --git a/style.css b/style.css index 340348a..626cfb9 100644 --- a/style.css +++ b/style.css @@ -533,6 +533,14 @@ details summary[role="button"] { overflow: auto; /* hack to clear floating elements */ } +.dialog .protocol-handler { + display: flex; + flex-direction: row; +} +.dialog .protocol-handler .left { + flex-grow: 1; +} + kbd { background-color: #f0f0f0; border: 1px solid #bfbfbf;