-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77dba2d
commit be6c837
Showing
17 changed files
with
392 additions
and
991 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
import SwiftUI | ||
import LaunchAtLogin | ||
|
||
// TODO: Remove the view menu | ||
|
||
/** | ||
NOTES: | ||
- The "com.apple.security.files.user-selected.read-only" entitlement is required by the "Open" menu in the "Color Palettes" pane. | ||
TODO when targeting macOS 13: | ||
- Upload non-App Store version. | ||
TODO shortcut action ideas; | ||
- Convert color | ||
- Toggle color panel | ||
|
@@ -23,7 +17,7 @@ struct AppMain: App { | |
@StateObject private var pasteboardObserver = NSPasteboard.SimpleObservable(.general, onlyWhileAppIsActive: true) | ||
|
||
init() { | ||
migrate() | ||
setUpConfig() | ||
} | ||
|
||
var body: some Scene { | ||
|
@@ -85,67 +79,25 @@ struct AppMain: App { | |
} | ||
} | ||
|
||
private func migrate() { | ||
LaunchAtLogin.migrateIfNeeded() | ||
|
||
// TODO: Remove in 2023. | ||
SSApp.runOnce(identifier: "migrateShownColorFormats") { | ||
guard !SSApp.isFirstLaunch else { | ||
return | ||
} | ||
|
||
Defaults.migrate(.shownColorFormats, to: .v5) | ||
Defaults.migrate(.colorFormatToCopyAfterPicking, to: .v5) | ||
} | ||
|
||
// TODO: Remove in 2023. | ||
SSApp.runOnce(identifier: "migrateToPreferredColorFormatSetting") { | ||
guard !SSApp.isFirstLaunch else { | ||
return | ||
} | ||
|
||
if Defaults[.colorFormatToCopyAfterPicking] != .none { | ||
Defaults[.copyColorAfterPicking] = true | ||
} | ||
|
||
switch Defaults[.colorFormatToCopyAfterPicking] { | ||
case .none: | ||
break | ||
case .hex: | ||
Defaults[.preferredColorFormat] = .hex | ||
case .hsl: | ||
Defaults[.preferredColorFormat] = .hsl | ||
case .rgb: | ||
Defaults[.preferredColorFormat] = .rgb | ||
case .lch: | ||
Defaults[.preferredColorFormat] = .lch | ||
} | ||
} | ||
|
||
// Preserve the old behavior for existing users. | ||
SSApp.runOnce(identifier: "setDefaultsForMenuBarItemClickActionSetting") { | ||
guard !SSApp.isFirstLaunch else { | ||
return | ||
} | ||
|
||
Defaults[.menuBarItemClickAction] = .toggleWindow | ||
private func setUpConfig() { | ||
#if !DEBUG | ||
SentrySDK.start { | ||
$0.dsn = "https://[email protected]/6139060" | ||
$0.enableSwizzling = false | ||
$0.enableAppHangTracking = false // https://github.com/getsentry/sentry-cocoa/issues/2643 | ||
} | ||
#endif | ||
} | ||
} | ||
|
||
@MainActor | ||
private final class AppDelegate: NSObject, NSApplicationDelegate { | ||
func applicationDidFinishLaunching(_ notification: Notification) { | ||
if #available(macOS 13, *) { | ||
SSApp.swiftUIMainWindow?.close() | ||
} | ||
SSApp.swiftUIMainWindow?.close() | ||
} | ||
|
||
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { | ||
if #available(macOS 13, *) { | ||
AppState.shared.handleAppReopen() | ||
} | ||
|
||
AppState.shared.handleAppReopen() | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,16 +129,13 @@ final class AppState: ObservableObject { | |
} | ||
} | ||
|
||
init() { | ||
setUpConfig() | ||
|
||
private init() { | ||
DispatchQueue.main.async { [self] in | ||
didLaunch() | ||
} | ||
} | ||
|
||
private func didLaunch() { | ||
fixStuff() | ||
setUpEvents() | ||
handleMenuBarIcon() | ||
showWelcomeScreenIfNeeded() | ||
|
@@ -155,30 +152,8 @@ final class AppState: ObservableObject { | |
#endif | ||
} | ||
|
||
private func setUpConfig() { | ||
#if !DEBUG | ||
SentrySDK.start { | ||
$0.dsn = "https://[email protected]/6139060" | ||
$0.enableSwizzling = false | ||
} | ||
#endif | ||
} | ||
|
||
private func fixStuff() { | ||
if #available(macOS 13, *) { | ||
SSApp.swiftUIMainWindow?.close() | ||
} else { | ||
// Make the invisible native SwitUI window not block access to the desktop. (macOS 12.0) | ||
// https://github.com/feedback-assistant/reports/issues/253 | ||
SSApp.swiftUIMainWindow?.ignoresMouseEvents = true | ||
|
||
// Make the invisible native SwiftUI window not show up in mission control when in menu bar mode. (macOS 11.6) | ||
SSApp.swiftUIMainWindow?.collectionBehavior = .stationary | ||
} | ||
} | ||
|
||
private func requestReview() { | ||
SSApp.requestReviewAfterBeingCalledThisManyTimes([10, 100, 200, 1000]) | ||
SSApp.requestReviewAfterBeingCalledThisManyTimes([8, 100, 200, 1000]) | ||
} | ||
|
||
private func addToRecentlyPickedColor(_ color: NSColor) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.