From 0419f8077d449d9835d13dd7d17a71088652a499 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 13 Jul 2022 11:48:12 -0400 Subject: [PATCH] feat(windows): hook protocol uris to the urlManager Fixes #5973 --- src/app/boot/app_controller.nim | 1 + src/app/core/custom_urls/urls_manager.nim | 32 +++++++++++++++++------ src/app/core/main.nim | 9 +++++-- src/nim_status_client.nim | 4 +-- ui/main.qml | 10 ------- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index ccb6642937..adec10018f 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -344,6 +344,7 @@ proc load(self: AppController) = proc userLoggedIn*(self: AppController) = self.generalService.startMessenger() self.load() + self.statusFoundation.userLoggedIn() # Once user is logged in and main module is loaded we need to check if it gets here importing mnemonic or not # and delete mnemonic in the first case. diff --git a/src/app/core/custom_urls/urls_manager.nim b/src/app/core/custom_urls/urls_manager.nim index ec05e656d3..bd4219e3ce 100644 --- a/src/app/core/custom_urls/urls_manager.nim +++ b/src/app/core/custom_urls/urls_manager.nim @@ -33,20 +33,28 @@ const UriFormatCommunityChannelLong = "status-im://community-channel/" QtObject: type UrlsManager* = ref object of QObject events: EventEmitter + protocolUriOnStart: string - proc setup(self: UrlsManager, urlSchemeEvent: StatusEvent) = + proc setup(self: UrlsManager, urlSchemeEvent: StatusEvent, + singleInstance: SingleInstance) = self.QObject.setup - signalConnect(urlSchemeEvent, "urlActivated(QString)", self, "onUrlActivated(QString)", 2) + signalConnect(urlSchemeEvent, "urlActivated(QString)", self, + "onUrlActivated(QString)", 2) + signalConnect(singleInstance, "eventReceived(QString)", self, + "onUrlActivated(QString)", 2) proc delete*(self: UrlsManager) = self.QObject.delete - proc newUrlsManager*(events: EventEmitter, urlSchemeEvent: StatusEvent): UrlsManager = + proc newUrlsManager*(events: EventEmitter, urlSchemeEvent: StatusEvent, + singleInstance: SingleInstance, protocolUriOnStart: string): UrlsManager = new(result) - result.setup(urlSchemeEvent) - result.events = events + result.setup(urlSchemeEvent, singleInstance) + result.events = events + result.protocolUriOnStart = protocolUriOnStart - proc prepareGroupChatDetails(self: UrlsManager, urlQuery: string, data: var StatusUrlArgs) = + proc prepareGroupChatDetails(self: UrlsManager, urlQuery: string, + data: var StatusUrlArgs) = var urlParams = rsplit(urlQuery, "/u/") if(urlParams.len > 0): data.groupName = urlParams[0] @@ -55,8 +63,11 @@ QtObject: else: info "wrong url format for group chat" - proc onUrlActivated*(self: UrlsManager, url: string) {.slot.} = + proc onUrlActivated*(self: UrlsManager, urlRaw: string) {.slot.} = var data = StatusUrlArgs() + let url = urlRaw.multiReplace((" ", "")) + .multiReplace(("\r\n", "")) + .multiReplace(("\n", "")) # Open `url` in the app's browser if url.startsWith(UriFormatBrowserShort): @@ -129,4 +140,9 @@ QtObject: info "Unsupported deep link structure: ", url return - self.events.emit(SIGNAL_STATUS_URL_REQUESTED, data) \ No newline at end of file + self.events.emit(SIGNAL_STATUS_URL_REQUESTED, data) + + proc userLoggedIn*(self: UrlsManager) = + if self.protocolUriOnStart != "": + self.onUrlActivated(self.protocolUriOnStart) + self.protocolUriOnStart = "" \ No newline at end of file diff --git a/src/app/core/main.nim b/src/app/core/main.nim index a032439c26..aea7282bb1 100644 --- a/src/app/core/main.nim +++ b/src/app/core/main.nim @@ -30,5 +30,10 @@ proc delete*(self: StatusFoundation) = self.signalsManager.delete() self.urlsManager.delete() -proc initUrlSchemeManager*(self: StatusFoundation, urlSchemeEvent: StatusEvent) = - self.urlsManager = newUrlsManager(self.events, urlSchemeEvent) \ No newline at end of file +proc initUrlSchemeManager*(self: StatusFoundation, urlSchemeEvent: StatusEvent, + singleInstance: SingleInstance, protocolUriOnStart: string) = + self.urlsManager = newUrlsManager(self.events, urlSchemeEvent, singleInstance, + protocolUriOnStart) + +proc userLoggedIn*(self: StatusFoundation) = + self.urlsManager.userLoggedIn() \ No newline at end of file diff --git a/src/nim_status_client.nim b/src/nim_status_client.nim index 409fca557a..b4a934be86 100644 --- a/src/nim_status_client.nim +++ b/src/nim_status_client.nim @@ -23,7 +23,7 @@ proc determineFleetsPath(): string = proc determineOpenUri(): string = if OPENURI.len > 0: - result = $(%* { "uri": OPENURI }) + result = OPENURI proc determineStatusAppIconPath(): string = if defined(production): @@ -109,7 +109,7 @@ proc mainProc() = let osThemeEvent = newStatusOSThemeEventObject(singletonInstance.engine) let urlSchemeEvent = newStatusUrlSchemeEventObject() - statusFoundation.initUrlSchemeManager(urlSchemeEvent) + statusFoundation.initUrlSchemeManager(urlSchemeEvent, singleInstance, openUri) if not defined(macosx): app.icon(app.applicationDirPath & statusAppIconPath) diff --git a/ui/main.qml b/ui/main.qml index ebf40f271a..87fe12ce8f 100644 --- a/ui/main.qml +++ b/ui/main.qml @@ -185,16 +185,6 @@ StatusWindow { applicationWindow.raise() applicationWindow.requestActivate() } - - function onEventReceived(eventStr) { - let event = JSON.parse(eventStr) - if (event.hasOwnProperty("uri")) { - // Not Refactored Yet -// chatsModel.handleProtocolUri(event.uri) - } else { - console.warn("Unknown event received: " + eventStr) - } - } } // The easiest way to get current system theme (is it light or dark) without using