Skip to content

Commit 6bf29c2

Browse files
committed
Merge branch 'develop' of https://github.com/tryboxx/SnippetsLibrary into develop
2 parents 727eb2f + f45eb2f commit 6bf29c2

File tree

7 files changed

+125
-11
lines changed

7 files changed

+125
-11
lines changed

SnippetsLibrary.xcodeproj/project.pbxproj

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
B8B6DE7E26EE4BB500E49C57 /* SnippetsParserService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B6DE7D26EE4BB500E49C57 /* SnippetsParserService.swift */; };
6060
B8B6DE8126EE546800E49C57 /* DependencyContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B6DE8026EE546800E49C57 /* DependencyContainer.swift */; };
6161
B8B6DE8326EE608500E49C57 /* SnippetPlist.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B6DE8226EE608500E49C57 /* SnippetPlist.swift */; };
62-
B8C8755826FCF16E00DE4474 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B88D4A3526F4E34900164BF5 /* GoogleService-Info.plist */; };
62+
B8C8755926FD2AB600DE4474 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B88D4A3526F4E34900164BF5 /* GoogleService-Info.plist */; };
63+
B8CE1CAB26FD4193004AD5D5 /* DisabledCommandGroupButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8CE1CAA26FD4193004AD5D5 /* DisabledCommandGroupButton.swift */; };
64+
B8CE1CAE26FD431E004AD5D5 /* URLFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8CE1CAD26FD431E004AD5D5 /* URLFactory.swift */; };
65+
B8CE1CB026FD43B5004AD5D5 /* URLType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8CE1CAF26FD43B5004AD5D5 /* URLType.swift */; };
6366
B8EB5AD526F005CC00BE3EF6 /* CustomCodeTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8EB5AD426F005CC00BE3EF6 /* CustomCodeTheme.swift */; };
6467
B8EB5AD926F0061A00BE3EF6 /* SnippetFileCardViewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8EB5AD826F0061A00BE3EF6 /* SnippetFileCardViewState.swift */; };
6568
B8EB5ADB26F0076C00BE3EF6 /* PlistCodingKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8EB5ADA26F0076C00BE3EF6 /* PlistCodingKeys.swift */; };
@@ -147,6 +150,9 @@
147150
B8B6DE7D26EE4BB500E49C57 /* SnippetsParserService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetsParserService.swift; sourceTree = "<group>"; };
148151
B8B6DE8026EE546800E49C57 /* DependencyContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyContainer.swift; sourceTree = "<group>"; };
149152
B8B6DE8226EE608500E49C57 /* SnippetPlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetPlist.swift; sourceTree = "<group>"; };
153+
B8CE1CAA26FD4193004AD5D5 /* DisabledCommandGroupButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisabledCommandGroupButton.swift; sourceTree = "<group>"; };
154+
B8CE1CAD26FD431E004AD5D5 /* URLFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLFactory.swift; sourceTree = "<group>"; };
155+
B8CE1CAF26FD43B5004AD5D5 /* URLType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLType.swift; sourceTree = "<group>"; };
150156
B8EB5AD426F005CC00BE3EF6 /* CustomCodeTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCodeTheme.swift; sourceTree = "<group>"; };
151157
B8EB5AD826F0061A00BE3EF6 /* SnippetFileCardViewState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetFileCardViewState.swift; sourceTree = "<group>"; };
152158
B8EB5ADA26F0076C00BE3EF6 /* PlistCodingKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlistCodingKeys.swift; sourceTree = "<group>"; };
@@ -304,6 +310,7 @@
304310
B82561DD26E822A80040A67E /* RecentSnippetCardView.swift */,
305311
B82561F626E8C9840040A67E /* SearchBar.swift */,
306312
B8F95B0626EEAEB200335D77 /* SnippetDropCellView.swift */,
313+
B8CE1CAA26FD4193004AD5D5 /* DisabledCommandGroupButton.swift */,
307314
);
308315
path = Views;
309316
sourceTree = "<group>";
@@ -422,6 +429,7 @@
422429
B8B6DE7C26EE4B9400E49C57 /* Services */ = {
423430
isa = PBXGroup;
424431
children = (
432+
B8CE1CAC26FD430D004AD5D5 /* URLFactory */,
425433
B88D7A5F26F797DE00B114F6 /* UserDefaults */,
426434
B856D65226F2A27300F60D09 /* Firebase */,
427435
B8EB5AE926F00B6F00BE3EF6 /* SnippetParser */,
@@ -437,6 +445,14 @@
437445
path = Dependencies;
438446
sourceTree = "<group>";
439447
};
448+
B8CE1CAC26FD430D004AD5D5 /* URLFactory */ = {
449+
isa = PBXGroup;
450+
children = (
451+
B8CE1CAD26FD431E004AD5D5 /* URLFactory.swift */,
452+
);
453+
path = URLFactory;
454+
sourceTree = "<group>";
455+
};
440456
B8EB5AD726F0061000BE3EF6 /* Enums */ = {
441457
isa = PBXGroup;
442458
children = (
@@ -450,6 +466,7 @@
450466
B88BB45726F564C200747631 /* UserActivityLevel.swift */,
451467
B88BB45926F564D100747631 /* UserActivityLogType.swift */,
452468
B8190DF726FA388500E3994C /* SnippetType.swift */,
469+
B8CE1CAF26FD43B5004AD5D5 /* URLType.swift */,
453470
);
454471
path = Enums;
455472
sourceTree = "<group>";
@@ -612,7 +629,7 @@
612629
isa = PBXResourcesBuildPhase;
613630
buildActionMask = 2147483647;
614631
files = (
615-
B8C8755826FCF16E00DE4474 /* GoogleService-Info.plist in Resources */,
632+
B8C8755926FD2AB600DE4474 /* GoogleService-Info.plist in Resources */,
616633
B82561BB26E81D580040A67E /* Preview Assets.xcassets in Resources */,
617634
B82561B826E81D580040A67E /* Assets.xcassets in Resources */,
618635
);
@@ -701,19 +718,22 @@
701718
B84BFEA926F57018007E5109 /* System.swift in Sources */,
702719
B8B6DE7B26ED9A3300E49C57 /* SnippetDetailsViewModel.swift in Sources */,
703720
B84BFEA626F56A6A007E5109 /* CrashlyticsService.swift in Sources */,
721+
B8CE1CB026FD43B5004AD5D5 /* URLType.swift in Sources */,
704722
B82561D626E821F20040A67E /* StartViewRecentSnippetsView.swift in Sources */,
705723
B82561D126E821770040A67E /* ActiveAppView.swift in Sources */,
706724
B88BB45A26F564D100747631 /* UserActivityLogType.swift in Sources */,
707725
B82561DC26E822840040A67E /* View+Visibility.swift in Sources */,
708726
B856D65526F2A29600F60D09 /* DatabaseService.swift in Sources */,
709727
B8EB5AD526F005CC00BE3EF6 /* CustomCodeTheme.swift in Sources */,
728+
B8CE1CAE26FD431E004AD5D5 /* URLFactory.swift in Sources */,
710729
B8B6DE8126EE546800E49C57 /* DependencyContainer.swift in Sources */,
711730
B8EB5AE826F00B4300BE3EF6 /* SnippetsParserServiceError.swift in Sources */,
712731
B8EB5AE426F00A7000BE3EF6 /* SnippetPlatform.swift in Sources */,
713732
B8B6DE7E26EE4BB500E49C57 /* SnippetsParserService.swift in Sources */,
714733
B82561B426E81D570040A67E /* SnippetsLibraryApp.swift in Sources */,
715734
B88BB45626F55DDB00747631 /* LogsService.swift in Sources */,
716735
B88D7A6326F7A5C000B114F6 /* SnippetPlist+Dictonary.swift in Sources */,
736+
B8CE1CAB26FD4193004AD5D5 /* DisabledCommandGroupButton.swift in Sources */,
717737
B85D1A9D26FA8EA50053FF3C /* SnippetsLibraryListSectionView.swift in Sources */,
718738
B82561E626E8C5490040A67E /* Mocks.swift in Sources */,
719739
);

SnippetsLibrary/Application/AppDelegate.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
1212

1313
func applicationDidFinishLaunching(_ notification: Notification) {
1414
FirebaseApp.configure()
15-
DIContainer.crashlyticsService.logNonFatalError(.unableToCreateSnippet)
1615
return
1716
}
1817

SnippetsLibrary/Application/SnippetsLibraryApp.swift

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import SwiftUI
1010
@main
1111
struct SnippetsLibraryApp: App {
1212

13-
private enum Constants {
14-
static let userGuidesUrlString = "https://github.com/tryboxx/SnippetsLibrary/blob/main/README.md"
15-
}
16-
1713
// MARK: - Stored Properties
1814

1915
@Environment(\.scenePhase) var scenePhase
@@ -23,6 +19,7 @@ struct SnippetsLibraryApp: App {
2319

2420
@State private var activeAppView: ActiveAppView? = nil
2521
@State private var activeAppSheet: AppSheet? = nil
22+
@State private var shouldBeDisabled = false
2623

2724
// MARK: - Views
2825

@@ -31,6 +28,9 @@ struct SnippetsLibraryApp: App {
3128
showActiveAppView()
3229
}
3330
.windowStyle(HiddenTitleBarWindowStyle())
31+
.onChange(of: activeAppView) {
32+
shouldBeDisabled = ($0 == .snippetsLibrary(nil))
33+
}
3434
.commands {
3535
CommandGroup(replacing: .newItem) {
3636
Button("Add New Code Snippet...") {
@@ -48,7 +48,10 @@ struct SnippetsLibraryApp: App {
4848
activeAppView = .importSnippet
4949
}
5050

51-
Button("Open Snippets Library...") {
51+
DisabledCommandGroupButton(
52+
text: "Open Snippets Library...",
53+
shouldBeDisabled: $shouldBeDisabled
54+
) {
5255
activeAppView = .snippetsLibrary(nil)
5356
}
5457
}
@@ -59,10 +62,17 @@ struct SnippetsLibraryApp: App {
5962
}
6063

6164
Button("Show User Guides") {
62-
guard let url = URL(string: Constants.userGuidesUrlString) else { return }
63-
64-
openURL(url)
65+
openURL(url: DIContainer.urlFactory.getURL(withType: .userGuides))
66+
}
67+
}
68+
69+
CommandGroup(replacing: .windowList) {
70+
Button("Developer Documentation") {
71+
openURL(url: DIContainer.urlFactory.getURL(withType: .docs))
6572
}
73+
.keyboardShortcut(
74+
"0",
75+
modifiers: [.command, .shift])
6676
}
6777
}
6878
}
@@ -114,4 +124,9 @@ struct SnippetsLibraryApp: App {
114124
service?.perform(withItems: ["Please describe your problem here..."])
115125
}
116126

127+
private func openURL(url: URL?) {
128+
guard let safeURL = url else { return }
129+
openURL(safeURL)
130+
}
131+
117132
}

SnippetsLibrary/Dependencies/DependencyContainer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ final class DependencyContainer {
1414
// MARK: - Services
1515

1616
lazy var snippetsParserService: SnippetsParserService = SnippetsParserServiceImpl()
17+
lazy var urlFactory: URLFactory = URLFactoryImpl()
1718

1819
lazy var databaseService: DatabaseService = DatabaseServiceImpl(
1920
logsService: logsService,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// URLFactory.swift
3+
// SnippetsLibrary
4+
//
5+
// Created by Krzysztof Łowiec on 23/09/2021.
6+
//
7+
8+
import Foundation
9+
10+
protocol URLFactory {
11+
func getURL(withType type: URLType) -> URL?
12+
}
13+
14+
final class URLFactoryImpl: URLFactory {
15+
16+
private enum Constants {
17+
static let userGuidesUrlString = "https://github.com/tryboxx/SnippetsLibrary/blob/main/README.md"
18+
static let developerDocumentationUrlString = "https://github.com/tryboxx/SnippetsLibrary/wiki"
19+
}
20+
21+
// MARK: - Methods
22+
23+
internal func getURL(withType type: URLType) -> URL? {
24+
switch type {
25+
case .userGuides:
26+
return URL(string: Constants.userGuidesUrlString)
27+
case .docs:
28+
return URL(string: Constants.developerDocumentationUrlString)
29+
}
30+
}
31+
32+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// URLType.swift
3+
// SnippetsLibrary
4+
//
5+
// Created by Krzysztof Łowiec on 23/09/2021.
6+
//
7+
8+
import Foundation
9+
10+
enum URLType {
11+
case userGuides
12+
case docs
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// DisabledCommandGroupButton.swift
3+
// SnippetsLibrary
4+
//
5+
// Created by Krzysztof Łowiec on 23/09/2021.
6+
//
7+
8+
import SwiftUI
9+
10+
struct DisabledCommandGroupButton: View {
11+
12+
// MARK: - Stored Properties
13+
14+
let text: String
15+
@Binding private(set) var shouldBeDisabled: Bool
16+
let onTap: () -> Void
17+
18+
// MARK: - Views
19+
20+
var body: some View {
21+
Button(
22+
text,
23+
action: onTap
24+
)
25+
.disabled(shouldBeDisabled)
26+
}
27+
28+
}
29+
30+
struct DisabledCommandGroupButton_Previews: PreviewProvider {
31+
static var previews: some View {
32+
DisabledCommandGroupButton(text: "", shouldBeDisabled: .constant(false)) {}
33+
}
34+
}

0 commit comments

Comments
 (0)