Skip to content

Commit

Permalink
refactor: Adopt new Scene.handlesExternalEvents extension in Intera…
Browse files Browse the repository at this point in the history
…ct (#10)
  • Loading branch information
jbmorley authored Feb 21, 2024
1 parent cf8f385 commit a98424e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
14 changes: 7 additions & 7 deletions Thoughts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

/* Begin PBXBuildFile section */
D80E08A12B675AAC0023DD4F /* ComposeWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = D80E08A02B675AAC0023DD4F /* ComposeWindow.swift */; };
D80E08A42B675AE20023DD4F /* Scene.swift in Sources */ = {isa = PBXBuildFile; fileRef = D80E08A32B675AE20023DD4F /* Scene.swift */; };
D80E08A62B6761370023DD4F /* Document.swift in Sources */ = {isa = PBXBuildFile; fileRef = D80E08A52B6761370023DD4F /* Document.swift */; };
D83C2F882B857B8C00CE60F7 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = D83C2F872B857B8C00CE60F7 /* URL.swift */; };
D850C2D42B69D85400338546 /* KeyedDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = D850C2D32B69D85400338546 /* KeyedDefaults.swift */; };
D850C2D62B69D8D500338546 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D850C2D52B69D8D500338546 /* ContentView.swift */; };
D852AF022B6027CA00B77A3D /* ThoughtsApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D852AF012B6027CA00B77A3D /* ThoughtsApp.swift */; };
Expand Down Expand Up @@ -49,8 +49,8 @@
/* Begin PBXFileReference section */
D80E089E2B674E900023DD4F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
D80E08A02B675AAC0023DD4F /* ComposeWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeWindow.swift; sourceTree = "<group>"; };
D80E08A32B675AE20023DD4F /* Scene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scene.swift; sourceTree = "<group>"; };
D80E08A52B6761370023DD4F /* Document.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Document.swift; sourceTree = "<group>"; };
D83C2F872B857B8C00CE60F7 /* URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = "<group>"; };
D850C2D32B69D85400338546 /* KeyedDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyedDefaults.swift; sourceTree = "<group>"; };
D850C2D52B69D8D500338546 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
D852AEFE2B6027CA00B77A3D /* Thoughts.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Thoughts.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -113,7 +113,7 @@
isa = PBXGroup;
children = (
D850C2D32B69D85400338546 /* KeyedDefaults.swift */,
D80E08A32B675AE20023DD4F /* Scene.swift */,
D83C2F872B857B8C00CE60F7 /* URL.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -141,16 +141,16 @@
D852AF002B6027CA00B77A3D /* Thoughts */ = {
isa = PBXGroup;
children = (
D852AF0A2B6027CC00B77A3D /* Thoughts.entitlements */,
D8F8D7232B68C77900464A37 /* ThoughtsRelease.entitlements */,
D80E089E2B674E900023DD4F /* Info.plist */,
D852AF632B604AF500B77A3D /* ApplicationModel.swift */,
D852AF012B6027CA00B77A3D /* ThoughtsApp.swift */,
D852AF052B6027CC00B77A3D /* Assets.xcassets */,
D80E08A22B675AD40023DD4F /* Extensions */,
D80E089E2B674E900023DD4F /* Info.plist */,
D8F06D522B6733440039AEF4 /* Licenses */,
D80E089F2B67572E0023DD4F /* Model */,
D852AF072B6027CC00B77A3D /* Preview Content */,
D852AF0A2B6027CC00B77A3D /* Thoughts.entitlements */,
D852AF012B6027CA00B77A3D /* ThoughtsApp.swift */,
D8F06D4F2B6731C00039AEF4 /* Views */,
);
path = Thoughts;
Expand Down Expand Up @@ -345,10 +345,10 @@
D852AF642B604AF500B77A3D /* ApplicationModel.swift in Sources */,
D850C2D62B69D8D500338546 /* ContentView.swift in Sources */,
D852AF692B604B3E00B77A3D /* MainMenu.swift in Sources */,
D83C2F882B857B8C00CE60F7 /* URL.swift in Sources */,
D850C2D42B69D85400338546 /* KeyedDefaults.swift in Sources */,
D852AF662B604B1200B77A3D /* ComposeView.swift in Sources */,
D8F06D512B6731CE0039AEF4 /* SettingsView.swift in Sources */,
D80E08A42B675AE20023DD4F /* Scene.swift in Sources */,
D80E08A62B6761370023DD4F /* Document.swift in Sources */,
D852AF022B6027CA00B77A3D /* ThoughtsApp.swift in Sources */,
D80E08A12B675AAC0023DD4F /* ComposeWindow.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ import SwiftUI
import Diligence
import Interact

extension Scene {
extension URL {

public func handlesExternalEvents(matching conditions: Set<URL>) -> some Scene {
return handlesExternalEvents(matching: Set(conditions.map { $0.absoluteString }))
}
static let about = URL(string: "x-thoughts://about")!
static let compose = URL(string: "x-thoughts://compose")!

}
6 changes: 2 additions & 4 deletions Thoughts/ThoughtsApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import Interact
@main
struct ThoughtsApp: App {

static let aboutURL = URL(string: "x-thoughts://about")!
static let composeURL = URL(string: "x-thoughts://compose")!

var applicationModel = ApplicationModel()

Expand All @@ -41,7 +39,7 @@ struct ThoughtsApp: App {

ComposeWindow()
.environmentObject(applicationModel)
.handlesExternalEvents(matching: [Self.composeURL])
.handlesExternalEvents(matching: [.compose])
.defaultSize(width: 800, height: 600)

Settings {
Expand All @@ -66,7 +64,7 @@ struct ThoughtsApp: App {
License("Material Icons", author: "Google", filename: "material-icons-license")
License("Thoughts", author: "Jason Morley", filename: "thoughts-license")
}
.handlesExternalEvents(matching: [Self.aboutURL])
.handlesExternalEvents(matching: [.about])

}
}
4 changes: 2 additions & 2 deletions Thoughts/Views/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ struct MainMenu: View {
var body: some View {
Button("New...") {
applicationModel.new()
openURL(ThoughtsApp.composeURL)
openURL(.compose)
}
Divider()
Button {
openURL(ThoughtsApp.aboutURL)
openURL(.about)
} label: {
Text("About...")
}
Expand Down

0 comments on commit a98424e

Please sign in to comment.