feat(windows): hook protocol uris to the urlManager

Fixes #5973
This commit is contained in:
Jonathan Rainville 2022-07-13 11:48:12 -04:00
parent 7b4802db83
commit 0419f8077d
5 changed files with 34 additions and 22 deletions

View File

@ -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.

View File

@ -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)
self.events.emit(SIGNAL_STATUS_URL_REQUESTED, data)
proc userLoggedIn*(self: UrlsManager) =
if self.protocolUriOnStart != "":
self.onUrlActivated(self.protocolUriOnStart)
self.protocolUriOnStart = ""

View File

@ -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)
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()

View File

@ -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)

View File

@ -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