Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion BitMatch-iPad/Views/ModularContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,21 @@ struct SettingsSheetView: View {
Text("\(GeneralSettingsPresentation.systemPermission): \(notifier.authorization.title)")
.font(.footnote)
.foregroundColor(.secondary)
if notifier.authorization.showsSettingsButton,
if notifier.isRequestingAuthorization {
ProgressView("Requesting notification permission")
}
if notifier.authorization.showsEnableButton {
Button(NotificationPermissionPromptPresentation.enableTitle) {
Task { await coordinator.enableNotificationsFromPrompt() }
}
.disabled(notifier.isRequestingAuthorization)
}
if notifier.authorizationRequestFailed {
Text(GeneralSettingsPresentation.notificationRequestFailed)
.font(.footnote)
.foregroundStyle(.secondary)
}
if notifier.authorization.showsSettingsButton || notifier.authorizationRequestFailed,
let settingsURL = URL(string: UIApplication.openSettingsURLString) {
Button(GeneralSettingsPresentation.openNotificationSettings) {
openURL(settingsURL)
Expand Down
48 changes: 24 additions & 24 deletions BitMatch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@
CODE_SIGN_ENTITLEMENTS = BitMatch/BitMatch.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
Expand All @@ -654,7 +654,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
PRODUCT_BUNDLE_IDENTIFIER = BitMatchApp.BitMatch;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
Expand All @@ -672,7 +672,7 @@
CODE_SIGN_ENTITLEMENTS = BitMatch/BitMatch.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
Expand All @@ -683,7 +683,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
PRODUCT_BUNDLE_IDENTIFIER = BitMatchApp.BitMatch;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
Expand All @@ -698,11 +698,11 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 15.5;
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
PRODUCT_BUNDLE_IDENTIFIER = BitMatchApp.BitMatchTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
Expand All @@ -716,11 +716,11 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 15.5;
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
PRODUCT_BUNDLE_IDENTIFIER = BitMatchApp.BitMatchTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
Expand All @@ -733,10 +733,10 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
PRODUCT_BUNDLE_IDENTIFIER = BitMatchApp.BitMatchUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
Expand All @@ -749,10 +749,10 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
PRODUCT_BUNDLE_IDENTIFIER = BitMatchApp.BitMatchUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
Expand All @@ -767,7 +767,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -784,7 +784,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "BitMatchiOS.BitMatch-iPad";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -802,7 +802,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -819,7 +819,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "BitMatchiOS.BitMatch-iPad";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -837,11 +837,11 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.5;
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "BitMatchiOS.BitMatch-iPadTests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -858,11 +858,11 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.5;
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "BitMatchiOS.BitMatch-iPadTests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -879,11 +879,11 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.5;
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "BitMatchiOS.BitMatch-iPadUITests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -899,11 +899,11 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.5;
MARKETING_VERSION = 0.2.9;
MARKETING_VERSION = 0.2.10;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "BitMatchiOS.BitMatch-iPadUITests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
3 changes: 2 additions & 1 deletion BitMatch/App/BitMatchApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct BitMatchApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@StateObject private var environment: MacAppEnvironment
@StateObject private var updater: UpdaterController
@State private var menuBarExtraIsInserted = true
#if DEBUG
@ObservedObject private var devModeManager = DevModeManager.shared
#endif
Expand Down Expand Up @@ -176,7 +177,7 @@ struct BitMatchApp: App {
#endif
}

MenuBarExtra {
MenuBarExtra(isInserted: $menuBarExtraIsInserted) {
MacMenuBarCompanion(
coordinator: environment.coordinator,
appDelegate: appDelegate
Expand Down
93 changes: 74 additions & 19 deletions BitMatch/App/MacMenuBarCompanion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,83 @@ struct MacMenuBarStatusLabel: View {
}

var body: some View {
Group {
if coordinator.isOperationInProgress && coordinator.currentMode == .copyAndVerify {
let presentation = TransferProgressPresentation.make(coordinator: coordinator)
ZStack {
Circle().stroke(Color.secondary.opacity(0.4), lineWidth: 2.5)
if let fraction = presentation.fraction {
Circle()
.trim(from: 0, to: fraction)
.stroke(Color.primary, style: StrokeStyle(lineWidth: 2.5, lineCap: .round))
.rotationEffect(.degrees(-90))
} else {
Circle().fill(Color.primary).frame(width: 4, height: 4)
}
}
.accessibilityLabel("BitMatch, \(presentation.title), \(presentation.percentText ?? "progress not yet measured")")
let isActive = coordinator.isOperationInProgress && coordinator.currentMode == .copyAndVerify
let presentation = isActive ? TransferProgressPresentation.make(coordinator: coordinator) : nil
Image(nsImage: MenuBarStatusIcon.image(isActive: isActive, fraction: presentation?.fraction))
.frame(width: 18, height: 18)
.accessibilityLabel(presentation.map {
"BitMatch, \($0.title), \($0.percentText ?? "progress not yet measured")"
} ?? "BitMatch")
}
}

/// Supply an image for the system menu bar, rather than relying on a hosted
/// Shape hierarchy. At most 102 small vector images are retained.
@MainActor
enum MenuBarStatusIcon {
private nonisolated enum State: Hashable, Sendable {
case idle
case indeterminate
case progress(Int)
}

private static var images: [State: NSImage] = [:]

static func image(isActive: Bool, fraction: Double?) -> NSImage {
let state: State
if !isActive {
state = .idle
} else if let fraction, fraction.isFinite {
// Finishing work must not draw a completed progress ring.
state = .progress(Int(min(max(fraction, 0), 0.99) * 100))
} else {
state = .indeterminate
}
if let image = images[state] { return image }

let brandPath = state == .idle
? MenuBarBrandMark().path(in: CGRect(x: 0, y: 0, width: 18, height: 18)).cgPath
: nil
// AppKit may draw on another thread; capture only immutable values,
// with no actor-isolated SwiftUI work inside the callback.
let image = NSImage(size: NSSize(width: 18, height: 18), flipped: true) { @Sendable rect in
guard let context = NSGraphicsContext.current?.cgContext else { return false }
context.setLineCap(.round)
context.setLineJoin(.round)

if let brandPath {
context.setStrokeColor(CGColor(gray: 0, alpha: 1))
context.setLineWidth(1.7)
context.addPath(brandPath)
context.strokePath()
} else {
MenuBarBrandMark()
.stroke(Color.primary, style: StrokeStyle(lineWidth: 1.7, lineCap: .round, lineJoin: .round))
.accessibilityLabel("BitMatch")
let ring = rect.insetBy(dx: 2, dy: 2)
context.setLineWidth(2.5)
context.setStrokeColor(CGColor(gray: 0, alpha: 0.4))
context.strokeEllipse(in: ring)

switch state {
case .progress(let percent) where percent > 0:
context.setStrokeColor(CGColor(gray: 0, alpha: 1))
context.addArc(center: CGPoint(x: ring.midX, y: ring.midY),
radius: ring.width / 2,
startAngle: -.pi / 2,
endAngle: -.pi / 2 + 2 * .pi * CGFloat(percent) / 100,
clockwise: false)
context.strokePath()
case .indeterminate:
context.setFillColor(CGColor(gray: 0, alpha: 1))
context.fillEllipse(in: CGRect(x: rect.midX - 2, y: rect.midY - 2,
width: 4, height: 4))
default:
break
}
}
return true
}
.frame(width: 18, height: 18)
image.isTemplate = true
images[state] = image
return image
}
}

Expand Down
23 changes: 17 additions & 6 deletions BitMatch/Views/PreferencesWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,28 @@ struct PreferencesWindow: View {
LabeledContent(GeneralSettingsPresentation.systemPermission) {
HStack(spacing: 10) {
Text(notifier.authorization.title).foregroundStyle(.secondary)
if notifier.authorization.showsSettingsButton {
Button(GeneralSettingsPresentation.openNotificationSettings) {
openURL(GeneralSettingsPresentation.macNotificationSettingsURL)
}
} else if notifier.authorization.showsEnableButton {
Button("Enable Notifications") {
if notifier.isRequestingAuthorization {
ProgressView().controlSize(.small)
.accessibilityLabel("Requesting notification permission")
}
if notifier.authorization.showsEnableButton {
Button(NotificationPermissionPromptPresentation.enableTitle) {
Task { await coordinator.enableNotificationsFromPrompt() }
}
.disabled(notifier.isRequestingAuthorization)
}
if notifier.authorization.showsSettingsButton || notifier.authorizationRequestFailed {
Button(GeneralSettingsPresentation.openNotificationSettings) {
openURL(GeneralSettingsPresentation.macNotificationSettingsURL())
}
}
}
}
if notifier.authorizationRequestFailed {
Text(GeneralSettingsPresentation.notificationRequestFailed)
.font(.caption)
.foregroundStyle(.secondary)
}
}

Section(GeneralSettingsPresentation.queueSection) {
Expand Down
Loading
Loading