Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2af41c4

Browse files
committed
Join labs from https invite links
Parse https invite links (luma.frida.re/l/<code>) alongside the luma:// scheme and route them to the join queue. On iOS deliver universal links via NSUserActivity and open a project from the welcome screen so the queue is consumed. Add the associated-domains entitlement on iOS and macOS.
1 parent 05544eb commit 2af41c4

6 files changed

Lines changed: 60 additions & 12 deletions

File tree

Luma/Luma-iOS.entitlements

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
<dict>
55
<key>aps-environment</key>
66
<string>production</string>
7+
<key>com.apple.developer.associated-domains</key>
8+
<array>
9+
<string>applinks:luma.frida.re</string>
10+
</array>
711
</dict>
812
</plist>

Luma/Luma-macOS.entitlements

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<dict>
55
<key>com.apple.developer.aps-environment</key>
66
<string>production</string>
7+
<key>com.apple.developer.associated-domains</key>
8+
<array>
9+
<string>applinks:luma.frida.re</string>
10+
</array>
711
<key>com.apple.security.cs.allow-jit</key>
812
<true/>
913
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>

Luma/LumaApp.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,14 @@ func sharedGitHubAuth() -> GitHubAuth { sharedWelcomeModel.gitHubAuth }
143143
}
144144

145145
private func handle(url: URL) {
146-
guard url.scheme == "luma", url.host == "join" else {
146+
if let labID = BackendConfig.labID(fromInviteLink: url) {
147+
CollaborationJoinQueue.shared.enqueue(labID: labID)
147148
return
148149
}
149150

150-
guard let labID = labID(from: url) else {
151+
guard url.scheme == "luma", url.host == "join",
152+
let labID = labID(from: url)
153+
else {
151154
return
152155
}
153156

@@ -218,8 +221,13 @@ func sharedGitHubAuth() -> GitHubAuth { sharedWelcomeModel.gitHubAuth }
218221
}
219222

220223
static func handle(url: URL) {
221-
guard url.scheme == "luma", url.host == "join" else { return }
222-
guard let labID = labID(from: url) else { return }
224+
if let labID = BackendConfig.labID(fromInviteLink: url) {
225+
CollaborationJoinQueue.shared.enqueue(labID: labID)
226+
return
227+
}
228+
guard url.scheme == "luma", url.host == "join",
229+
let labID = labID(from: url)
230+
else { return }
223231
CollaborationJoinQueue.shared.enqueue(labID: labID)
224232
}
225233

Luma/PhoneRootView.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ struct PhoneRootView: View {
4848
await welcome.bootstrap()
4949
}
5050
.onOpenURL(perform: handleIncomingURL)
51+
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in
52+
if let url = activity.webpageURL {
53+
handleIncomingURL(url)
54+
}
55+
}
5156
.fileImporter(
5257
isPresented: $isShowingOpenPicker,
5358
allowedContentTypes: [UTType(exportedAs: Self.lumaUTI)]
@@ -92,10 +97,24 @@ struct PhoneRootView: View {
9297
LumaAppDelegate.handle(url: url)
9398
return
9499
}
100+
if let labID = BackendConfig.labID(fromInviteLink: url) {
101+
joinLab(labID: labID)
102+
return
103+
}
95104
guard url.isFileURL else { return }
96105
importExternal(url)
97106
}
98107

108+
@MainActor
109+
private func joinLab(labID: String) {
110+
CollaborationJoinQueue.shared.enqueue(labID: labID)
111+
guard dbURL == nil else { return }
112+
let url = Self.untitledURL(named: "Shared Lab")
113+
try? FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
114+
dbURL = url
115+
LumaAppState.shared.lastDocumentPath = url.path
116+
}
117+
99118
@MainActor
100119
private func importExternal(_ sourceURL: URL) {
101120
if sourceURL.path == dbURL?.path { return }

LumaGtk/Sources/LumaGtk/App.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,7 @@ final class LumaApplication {
344344
}
345345

346346
fileprivate func handleCollaborationURL(_ urlString: String) {
347-
guard let url = URL(string: urlString),
348-
url.scheme == "luma",
349-
url.host == "join",
350-
let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
351-
let labID = components.queryItems?.first(where: { $0.name == "lab" })?.value,
352-
!labID.isEmpty
353-
else { return }
347+
guard let url = URL(string: urlString), let labID = labID(fromURL: url) else { return }
354348
if let existing = openDocuments.values.first {
355349
existing.engine.startCollaboration(joiningLab: labID)
356350
return
@@ -359,6 +353,18 @@ final class LumaApplication {
359353
openNewUntitledWindow()
360354
}
361355

356+
private func labID(fromURL url: URL) -> String? {
357+
if let labID = BackendConfig.labID(fromInviteLink: url) {
358+
return labID
359+
}
360+
guard url.scheme == "luma", url.host == "join",
361+
let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
362+
let labID = components.queryItems?.first(where: { $0.name == "lab" })?.value,
363+
!labID.isEmpty
364+
else { return nil }
365+
return labID
366+
}
367+
362368
fileprivate func handleSaveAsPath(window: MainWindow, _ path: String) {
363369
var destination = URL(fileURLWithPath: path)
364370
if destination.pathExtension != LumaDocumentLoader.fileExtension {
@@ -782,7 +788,7 @@ private let lumaOpenFilesThunk: @convention(c) (
782788
MainActor.assumeIsolated {
783789
let ptr = UnsafeMutableRawPointer(bitPattern: raw)!
784790
let app = Unmanaged<LumaApplication>.fromOpaque(ptr).takeUnretainedValue()
785-
if str.hasPrefix("luma://") {
791+
if str.hasPrefix("luma://") || str.hasPrefix(BackendConfig.inviteLinkBase) {
786792
app.handleCollaborationURL(str)
787793
} else {
788794
app.openWindow(forFile: URL(fileURLWithPath: str))

Sources/LumaCore/BackendConfig.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ public enum BackendConfig {
55
public static let inviteLinkBase = "https://luma.frida.re/l/"
66
public static let pushEnrollURL = "https://luma.frida.re/push-enroll"
77

8+
public static func labID(fromInviteLink url: URL) -> String? {
9+
guard url.absoluteString.hasPrefix(inviteLinkBase) else { return nil }
10+
let code = url.absoluteString.dropFirst(inviteLinkBase.count)
11+
.prefix { $0 != "/" && $0 != "?" && $0 != "#" }
12+
return code.isEmpty ? nil : String(code)
13+
}
14+
815
public static let certificate: String = {
916
guard let url = Bundle.module.url(forResource: "LumaPortal", withExtension: "pem") else {
1017
fatalError("LumaPortal.pem not found in LumaCore resources")

0 commit comments

Comments
 (0)