From 321140327ec8540a0dd4b41fa6baf086393524c4 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 7 Nov 2021 17:53:10 +0100 Subject: [PATCH] Add UI to enable protocol handler --- components/app.js | 1 + components/buffer.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ store.js | 1 + 3 files changed, 46 insertions(+) diff --git a/components/app.js b/components/app.js index 3bc5ff8..8fc48d5 100644 --- a/components/app.js +++ b/components/app.js @@ -1571,6 +1571,7 @@ export default class App extends Component { <${Buffer} buffer=${activeBuffer} server=${activeServer} + isBouncer=${isBouncer} onChannelClick=${this.handleChannelClick} onNickClick=${this.handleNickClick}/> diff --git a/components/buffer.js b/components/buffer.js index d08e12e..9c8096a 100644 --- a/components/buffer.js +++ b/components/buffer.js @@ -3,6 +3,7 @@ import linkify from "../lib/linkify.js"; import * as irc from "../lib/irc.js"; import { strip as stripANSI } from "../lib/ansi.js"; import { BufferType, getNickURL, getChannelURL, getMessageURL } from "../state.js"; +import * as store from "../store.js"; import Membership from "./membership.js"; function djb2(s) { @@ -415,6 +416,46 @@ class NotificationNagger extends Component { } } +class ProtocolHandlerNagger extends Component { + state = { nag: true }; + + constructor(props) { + super(props); + + this.handleClick = this.handleClick.bind(this); + + this.state.nag = !store.naggedProtocolHandler.load(); + } + + handleClick(event) { + event.preventDefault(); + + 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); + } + + store.naggedProtocolHandler.put(true); + this.setState({ nag: false }); + } + + render() { + if (!navigator.registerProtocolHandler || !this.state.nag) { + return null; + } + return html` +
+ <${Timestamp}/> + ${" "} + To open IRC links here, enable the IRC link handler +
+ `; + } +} + class DateSeparator extends Component { constructor(props) { super(props); @@ -462,6 +503,9 @@ export default class Buffer extends Component { if (buf.type == BufferType.SERVER) { children.push(html`<${NotificationNagger}/>`); } + if (buf.type == BufferType.SERVER && this.props.isBouncer && !server.isupport.has("BOUNCER_NETID")) { + children.push(html`<${ProtocolHandlerNagger}/>`); + } let onChannelClick = this.props.onChannelClick; let onNickClick = this.props.onNickClick; diff --git a/store.js b/store.js index 733a264..c03d8ca 100644 --- a/store.js +++ b/store.js @@ -23,6 +23,7 @@ class Item { } export const autoconnect = new Item("autoconnect"); +export const naggedProtocolHandler = new Item("naggedProtocolHandler"); const rawReceipts = new Item("receipts");