Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 8, 2022
1 parent dfc206e commit 13ff751
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 79 deletions.
36 changes: 18 additions & 18 deletions Color Picker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
E3A3B11D25904E7B001B4D0C /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A3B11C25904E7B001B4D0C /* App.swift */; };
E3A3B12125904E7D001B4D0C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E3A3B12025904E7D001B4D0C /* Assets.xcassets */; };
E3DFA8C92662514800D2623E /* Events.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3DFA8C82662514800D2623E /* Events.swift */; };
E3E14062259A0D97004FC89F /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = E3E14061259A0D97004FC89F /* Defaults */; };
E3E7D79B27218903009D71F4 /* Intents.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E3E7D79A27218903009D71F4 /* Intents.framework */; platformFilter = maccatalyst; };
E3E7D79E27218903009D71F4 /* IntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3E7D79D27218903009D71F4 /* IntentHandler.swift */; };
E3E7D7A227218903009D71F4 /* IntentsExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = E3E7D79927218903009D71F4 /* IntentsExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
E3E7D7A927218959009D71F4 /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = E3E7D7A827218959009D71F4 /* Intents.intentdefinition */; };
E3E7D7AA27218959009D71F4 /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = E3E7D7A827218959009D71F4 /* Intents.intentdefinition */; };
E3E7D7AC27218C03009D71F4 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38D4332263AB24E00701B82 /* Utilities.swift */; };
E3E7D7AE27218C8A009D71F4 /* Regex in Frameworks */ = {isa = PBXBuildFile; productRef = E3E7D7AD27218C8A009D71F4 /* Regex */; };
E3E9F9AD2642B75100AE6450 /* AppCenterCrashes in Frameworks */ = {isa = PBXBuildFile; productRef = E3E9F9AC2642B75100AE6450 /* AppCenterCrashes */; };
E3F4BC872788A5780075DC52 /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = E3F4BC862788A5780075DC52 /* Sentry */; };
E3F4BC892788A64F0075DC52 /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = E3F4BC882788A64F0075DC52 /* Defaults */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -85,11 +85,11 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E3F4BC872788A5780075DC52 /* Sentry in Frameworks */,
E394DAAE263E95D900F5B042 /* LaunchAtLogin in Frameworks */,
E3E9F9AD2642B75100AE6450 /* AppCenterCrashes in Frameworks */,
E394DAB2263E965500F5B042 /* KeyboardShortcuts in Frameworks */,
E394DAAB263D73AD00F5B042 /* Regex in Frameworks */,
E3E14062259A0D97004FC89F /* Defaults in Frameworks */,
E3F4BC892788A64F0075DC52 /* Defaults in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -193,11 +193,11 @@
);
name = "Color Picker";
packageProductDependencies = (
E3E14061259A0D97004FC89F /* Defaults */,
E394DAAA263D73AD00F5B042 /* Regex */,
E394DAAD263E95D900F5B042 /* LaunchAtLogin */,
E394DAB1263E965500F5B042 /* KeyboardShortcuts */,
E3E9F9AC2642B75100AE6450 /* AppCenterCrashes */,
E3F4BC862788A5780075DC52 /* Sentry */,
E3F4BC882788A64F0075DC52 /* Defaults */,
);
productName = "Color Picker";
productReference = E3A3B11925904E7B001B4D0C /* Color Picker.app */;
Expand Down Expand Up @@ -254,7 +254,7 @@
E394DAA9263D73AD00F5B042 /* XCRemoteSwiftPackageReference "Regex" */,
E394DAAC263E95D900F5B042 /* XCRemoteSwiftPackageReference "LaunchAtLogin" */,
E394DAB0263E965500F5B042 /* XCRemoteSwiftPackageReference "KeyboardShortcuts" */,
E3E9F9AB2642B75100AE6450 /* XCRemoteSwiftPackageReference "appcenter-sdk-apple" */,
E3F4BC852788A5780075DC52 /* XCRemoteSwiftPackageReference "sentry-cocoa" */,
);
productRefGroup = E3A3B11A25904E7B001B4D0C /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -653,12 +653,12 @@
minimumVersion = 6.1.0;
};
};
E3E9F9AB2642B75100AE6450 /* XCRemoteSwiftPackageReference "appcenter-sdk-apple" */ = {
E3F4BC852788A5780075DC52 /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/microsoft/appcenter-sdk-apple";
repositoryURL = "https://github.com/getsentry/sentry-cocoa";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.3.0;
minimumVersion = 7.8.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand All @@ -679,20 +679,20 @@
package = E394DAB0263E965500F5B042 /* XCRemoteSwiftPackageReference "KeyboardShortcuts" */;
productName = KeyboardShortcuts;
};
E3E14061259A0D97004FC89F /* Defaults */ = {
isa = XCSwiftPackageProductDependency;
package = E3E14060259A0D97004FC89F /* XCRemoteSwiftPackageReference "Defaults" */;
productName = Defaults;
};
E3E7D7AD27218C8A009D71F4 /* Regex */ = {
isa = XCSwiftPackageProductDependency;
package = E394DAA9263D73AD00F5B042 /* XCRemoteSwiftPackageReference "Regex" */;
productName = Regex;
};
E3E9F9AC2642B75100AE6450 /* AppCenterCrashes */ = {
E3F4BC862788A5780075DC52 /* Sentry */ = {
isa = XCSwiftPackageProductDependency;
package = E3E9F9AB2642B75100AE6450 /* XCRemoteSwiftPackageReference "appcenter-sdk-apple" */;
productName = AppCenterCrashes;
package = E3F4BC852788A5780075DC52 /* XCRemoteSwiftPackageReference "sentry-cocoa" */;
productName = Sentry;
};
E3F4BC882788A64F0075DC52 /* Defaults */ = {
isa = XCSwiftPackageProductDependency;
package = E3E14060259A0D97004FC89F /* XCRemoteSwiftPackageReference "Defaults" */;
productName = Defaults;
};
/* End XCSwiftPackageProductDependency section */
};
Expand Down
1 change: 1 addition & 0 deletions Color Picker/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct AppMain: App {
}
}

@MainActor
private final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true }

Expand Down
39 changes: 20 additions & 19 deletions Color Picker/AppState.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import SwiftUI
import Combine
import Defaults
import AppCenter
import AppCenterCrashes
import Sentry

@MainActor
final class AppState: ObservableObject {
static let shared = AppState()

Expand Down Expand Up @@ -42,14 +42,14 @@ final class AppState: ObservableObject {
let menu = NSMenu()

if Defaults[.menuBarItemClickAction] != .showColorSampler {
menu.addCallbackItem("Pick Color") { [self] _ in
menu.addCallbackItem("Pick Color") { [self] in
pickColor()
}
.setShortcut(for: .pickColor)
}

if Defaults[.menuBarItemClickAction] != .toggleWindow {
menu.addCallbackItem("Toggle Window") { [self] _ in
menu.addCallbackItem("Toggle Window") { [self] in
colorPanel.toggle()
}
.setShortcut(for: .toggleWindow)
Expand All @@ -61,7 +61,7 @@ final class AppState: ObservableObject {
menu.addHeader("Recently Picked Colors")

for color in colors {
let menuItem = menu.addCallbackItem(color.stringRepresentation) { _ in
let menuItem = menu.addCallbackItem(color.stringRepresentation) {
color.stringRepresentation.copyToPasteboard()
}

Expand All @@ -75,7 +75,7 @@ final class AppState: ObservableObject {

menu.addSeparator()

menu.addCallbackItem("Send Feedback…") { _ in
menu.addCallbackItem("Send Feedback…") {
SSApp.openSendFeedbackPage()
}

Expand All @@ -93,10 +93,10 @@ final class AppState: ObservableObject {

let item = $0

$0.button!.onAction { [self] _ in
$0.button!.onAction { [self] in
let event = NSApp.currentEvent!

func showMenu() {
let showMenu = {
item.menu = createMenu()
item.button!.performClick(nil)
item.menu = nil
Expand Down Expand Up @@ -126,12 +126,7 @@ final class AppState: ObservableObject {
}

init() {
AppCenter.start(
withAppSecret: "f44a0ef2-9271-4bdb-8320-dcceaa857c36",
services: [
Crashes.self
]
)
setUpConfig()

DispatchQueue.main.async { [self] in
didLaunch()
Expand All @@ -150,6 +145,15 @@ 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() {
// Make the invisible native SwitUI window not block access to the desktop. (macOS 12.0)
// https://github.com/feedback-assistant/reports/issues/253
Expand Down Expand Up @@ -192,11 +196,8 @@ final class AppState: ObservableObject {
}

func pickColor() {
NSColorSampler().show { [weak self] in
guard
let self = self,
let color = $0
else {
Task {
guard let color = await NSColorSampler().sample() else {
return
}

Expand Down
3 changes: 3 additions & 0 deletions Color Picker/ColorPickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ struct ColorPickerView: View {
hexColor.copyToPasteboard()
} label: {
Image(systemName: "doc.on.doc.fill")
// TODO: Enable when targeting macOS 12 and remove `.fill` in the string. Also on the other buttons.
// .symbolVariant(.fill)
// .symbolRenderingMode(.hierarchical)
}
.buttonStyle(.borderless)
.contentShape(.rectangle)
Expand Down
1 change: 1 addition & 0 deletions Color Picker/Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extension AppState {
}

// We use this instead of `applicationShouldHandleReopen` because of the macOS bug.
// https://github.com/feedback-assistant/reports/issues/246
NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)
.sink { [self] _ in
handleAppReopen()
Expand Down
2 changes: 1 addition & 1 deletion Color Picker/InternetAccessPolicy.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Website": "https://sindresorhus.com/system-color-picker",
"Connections" : [
{
"Host" : "*.appcenter.ms",
"Host" : "*.sentry.io",
"NetworkProtocol" : "TCP",
"Port" : "443",
"Purpose" : "System Color Picker sends crash reports to this server.",
Expand Down
Loading

0 comments on commit 13ff751

Please sign in to comment.