move environment runtime check to compile time (#1709)

This commit is contained in:
Thai D. V 2023-12-06 12:41:26 +07:00 committed by GitHub
parent df1a44cc21
commit 2e350f5fce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 136 additions and 123 deletions

View file

@ -10,11 +10,11 @@ extension IceCubesApp {
}
.keyboardShortcut("n", modifiers: .shift)
Button("menu.new-post") {
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestinationEditor.newStatusEditor(visibility: userPreferences.postVisibility))
} else {
sidebarRouterPath.presentedSheet = .newStatusEditor(visibility: userPreferences.postVisibility)
}
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationEditor.newStatusEditor(visibility: userPreferences.postVisibility))
#else
sidebarRouterPath.presentedSheet = .newStatusEditor(visibility: userPreferences.postVisibility)
#endif
}
.keyboardShortcut("n", modifiers: .command)
}

View file

@ -42,7 +42,9 @@ private struct SafariRouter: ViewModifier {
return .handled
}
}
guard preferences.preferredBrowser == .inAppSafari, !ProcessInfo.processInfo.isMacCatalystApp else { return .systemAction }
#if !targetEnvironment(macCatalyst)
guard preferences.preferredBrowser == .inAppSafari else { return .systemAction }
#endif
// SFSafariViewController only supports initial URLs with http:// or https:// schemes.
guard let scheme = url.scheme, ["https", "http"].contains(scheme.lowercased()) else {
return .systemAction

View file

@ -57,11 +57,11 @@ struct SideBarView<Content: View>: View {
private var postButton: some View {
Button {
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestinationEditor.newStatusEditor(visibility: userPreferences.postVisibility))
} else {
routerPath.presentedSheet = .newStatusEditor(visibility: userPreferences.postVisibility)
}
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationEditor.newStatusEditor(visibility: userPreferences.postVisibility))
#else
routerPath.presentedSheet = .newStatusEditor(visibility: userPreferences.postVisibility)
#endif
} label: {
Image(systemName: "square.and.pencil")
.resizable()

View file

@ -233,11 +233,11 @@ struct AddAccountView: View {
do {
signInClient = .init(server: sanitizedName)
if let oauthURL = try await signInClient?.oauthURL() {
if ProcessInfo.processInfo.isMacCatalystApp {
openURL(oauthURL)
} else {
self.oauthURL = oauthURL
}
#if targetEnvironment(macCatalyst)
openURL(oauthURL)
#else
self.oauthURL = oauthURL
#endif
} else {
isSigninIn = false
}

View file

@ -173,24 +173,24 @@ struct SettingsTabs: View {
private var otherSections: some View {
@Bindable var preferences = preferences
Section("settings.section.other") {
if !ProcessInfo.processInfo.isMacCatalystApp {
Picker(selection: $preferences.preferredBrowser) {
ForEach(PreferredBrowser.allCases, id: \.rawValue) { browser in
switch browser {
case .inAppSafari:
Text("settings.general.browser.in-app").tag(browser)
case .safari:
Text("settings.general.browser.system").tag(browser)
}
#if !targetEnvironment(macCatalyst)
Picker(selection: $preferences.preferredBrowser) {
ForEach(PreferredBrowser.allCases, id: \.rawValue) { browser in
switch browser {
case .inAppSafari:
Text("settings.general.browser.in-app").tag(browser)
case .safari:
Text("settings.general.browser.system").tag(browser)
}
} label: {
Label("settings.general.browser", systemImage: "network")
}
Toggle(isOn: $preferences.inAppBrowserReaderView) {
Label("settings.general.browser.in-app.readerview", systemImage: "doc.plaintext")
}
.disabled(preferences.preferredBrowser != PreferredBrowser.inAppSafari)
} label: {
Label("settings.general.browser", systemImage: "network")
}
Toggle(isOn: $preferences.inAppBrowserReaderView) {
Label("settings.general.browser.in-app.readerview", systemImage: "doc.plaintext")
}
.disabled(preferences.preferredBrowser != PreferredBrowser.inAppSafari)
#endif
Toggle(isOn: $preferences.isOpenAIEnabled) {
Label("settings.other.hide-openai", systemImage: "faxmachine")
}
@ -209,19 +209,19 @@ struct SettingsTabs: View {
private var appSection: some View {
Section {
if !ProcessInfo.processInfo.isMacCatalystApp {
NavigationLink(destination: IconSelectorView()) {
Label {
Text("settings.app.icon")
} icon: {
let icon = IconSelectorView.Icon(string: UIApplication.shared.alternateIconName ?? "AppIcon")
Image(uiImage: .init(named: icon.iconName)!)
.resizable()
.frame(width: 25, height: 25)
.cornerRadius(4)
}
#if !targetEnvironment(macCatalyst)
NavigationLink(destination: IconSelectorView()) {
Label {
Text("settings.app.icon")
} icon: {
let icon = IconSelectorView.Icon(string: UIApplication.shared.alternateIconName ?? "AppIcon")
Image(uiImage: .init(named: icon.iconName)!)
.resizable()
.frame(width: 25, height: 25)
.cornerRadius(4)
}
}
#endif
Link(destination: URL(string: "https://github.com/Dimillian/IceCubesApp")!) {
Label("settings.app.source", systemImage: "link")

View file

@ -81,13 +81,13 @@ struct AccountDetailHeaderView: View {
return
}
let attachement = MediaAttachment.imageWith(url: account.header)
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestinationMedia.mediaViewer(attachments: [attachement],
selectedAttachment: attachement))
} else {
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationMedia.mediaViewer(
attachments: [attachement],
selectedAttachment: attachement))
#else
quickLook.prepareFor(selectedMediaAttachment: attachement, mediaAttachments: [attachement])
}
#endif
}
.accessibilityElement(children: .combine)
.accessibilityAddTraits([.isImage, .isButton])
@ -117,12 +117,12 @@ struct AccountDetailHeaderView: View {
return
}
let attachement = MediaAttachment.imageWith(url: account.avatar)
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestinationMedia.mediaViewer(attachments: [attachement],
selectedAttachment: attachement))
} else {
quickLook.prepareFor(selectedMediaAttachment: attachement, mediaAttachments: [attachement])
}
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationMedia.mediaViewer(attachments: [attachement],
selectedAttachment: attachement))
#else
quickLook.prepareFor(selectedMediaAttachment: attachement, mediaAttachments: [attachement])
#endif
}
.accessibilityElement(children: .combine)
.accessibilityAddTraits([.isImage, .isButton])

View file

@ -201,12 +201,12 @@ struct ConversationMessageView: View {
.frame(height: 200)
.contentShape(Rectangle())
.onTapGesture {
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestinationMedia.mediaViewer(attachments: [attachement],
selectedAttachment: attachement))
} else {
quickLook.prepareFor(selectedMediaAttachment: attachement, mediaAttachments: [attachement])
}
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationMedia.mediaViewer(attachments: [attachement],
selectedAttachment: attachement))
#else
quickLook.prepareFor(selectedMediaAttachment: attachement, mediaAttachments: [attachement])
#endif
}
}

View file

@ -6,13 +6,21 @@ public extension Font {
// See https://gist.github.com/zacwest/916d31da5d03405809c4 for iOS values
// Custom values for Mac
private static let title = 28.0
private static let headline = onMac ? 20.0 : 17.0
private static let body = onMac ? 19.0 : 17.0
private static let callout = onMac ? 17.0 : 16.0
private static let subheadline = onMac ? 16.0 : 15.0
private static let footnote = onMac ? 15.0 : 13.0
private static let caption = onMac ? 14.0 : 12.0
private static let onMac = ProcessInfo.processInfo.isMacCatalystApp
#if targetEnvironment(macCatalyst)
private static let headline = 20.0
private static let body = 19.0
private static let callout = 17.0
private static let subheadline = 16.0
private static let footnote = 15.0
private static let caption = 14.0
#else
private static let headline = 17.0
private static let body = 17.0
private static let callout = 16.0
private static let subheadline = 15.0
private static let footnote = 13.0
private static let caption = 12.0
#endif
private static func customFont(size: CGFloat, relativeTo textStyle: TextStyle) -> Font {
if let chosenFont = Theme.shared.chosenFont {

View file

@ -47,12 +47,11 @@ public struct AvatarView: View {
}
public static let account = FrameConfig(width: 80, height: 80)
public static let status = {
if ProcessInfo.processInfo.isMacCatalystApp {
return FrameConfig(width: 48, height: 48)
}
return FrameConfig(width: 40, height: 40)
}()
#if targetEnvironment(macCatalyst)
public static let status = FrameConfig(width: 48, height: 48)
#else
public static let status = FrameConfig(width: 40, height: 40)
#endif
public static let embed = FrameConfig(width: 34, height: 34)
public static let badge = FrameConfig(width: 28, height: 28, cornerRadius: 14)
public static let list = FrameConfig(width: 20, height: 20, cornerRadius: 10)

View file

@ -26,12 +26,12 @@ public struct StatusEditorToolbarItem: ToolbarContent {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
Task { @MainActor in
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestinationEditor.newStatusEditor(visibility: visibility))
} else {
routerPath.presentedSheet = .newStatusEditor(visibility: visibility)
HapticManager.shared.fireHaptic(.buttonPress)
}
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationEditor.newStatusEditor(visibility: visibility))
#else
routerPath.presentedSheet = .newStatusEditor(visibility: visibility)
HapticManager.shared.fireHaptic(.buttonPress)
#endif
}
} label: {
Image(systemName: "square.and.pencil")

View file

@ -37,13 +37,13 @@ struct StatusEditorAccessoryView: View {
} label: {
Label("status.editor.photo-library", systemImage: "photo")
}
if !ProcessInfo.processInfo.isMacCatalystApp {
Button {
isCameraPickerPresented = true
} label: {
Label("status.editor.camera-picker", systemImage: "camera")
}
#if !targetEnvironment(macCatalyst)
Button {
isCameraPickerPresented = true
} label: {
Label("status.editor.camera-picker", systemImage: "camera")
}
#endif
Button {
isFileImporterPresented = true
} label: {

View file

@ -216,12 +216,14 @@ public struct StatusEditorView: View {
SoundEffectManager.shared.playSound(.tootSent)
NotificationCenter.default.post(name: .shareSheetClose,
object: nil)
if !viewModel.mode.isInShareExtension, !preferences.requestedReview, !ProcessInfo.processInfo.isMacCatalystApp {
#if !targetEnvironment(macCatalyst)
if !viewModel.mode.isInShareExtension, !preferences.requestedReview {
if let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
SKStoreReviewController.requestReview(in: scene)
}
preferences.requestedReview = true
}
#endif
}
}
@ -292,10 +294,10 @@ public struct StatusEditorView: View {
}
private func close() {
if ProcessInfo.processInfo.isMacCatalystApp {
dismissWindow()
} else {
dismiss()
}
#if targetEnvironment(macCatalyst)
dismissWindow()
#else
dismiss()
#endif
}
}

View file

@ -45,9 +45,10 @@ extension TextView.Representable {
textView.allowsEditingTextAttributes = false
textView.returnKeyType = .default
textView.allowsEditingTextAttributes = true
if ProcessInfo.processInfo.isMacCatalystApp {
textView.inlinePredictionType = .no
}
#if targetEnvironment(macCatalyst)
textView.inlinePredictionType = .no
#endif
self.getTextView?(textView)
}

View file

@ -220,12 +220,13 @@ public struct StatusRowView: View {
Button("accessibility.status.media-viewer-action.label") {
HapticManager.shared.fireHaptic(.notification(.success))
let attachments = viewModel.finalStatus.mediaAttachments
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestinationMedia.mediaViewer(attachments: attachments,
selectedAttachment: attachments[0]))
} else {
quickLook.prepareFor(selectedMediaAttachment: attachments[0], mediaAttachments: attachments)
}
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationMedia.mediaViewer(
attachments: attachments,
selectedAttachment: attachments[0]))
#else
quickLook.prepareFor(selectedMediaAttachment: attachments[0], mediaAttachments: attachments)
#endif
}
}

View file

@ -205,11 +205,11 @@ struct StatusRowActionsView: View {
switch action {
case .respond:
SoundEffectManager.shared.playSound(.share)
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestinationEditor.replyToStatusEditor(status: viewModel.localStatus ?? viewModel.status))
} else {
viewModel.routerPath.presentedSheet = .replyToStatusEditor(status: viewModel.localStatus ?? viewModel.status)
}
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationEditor.replyToStatusEditor(status: viewModel.localStatus ?? viewModel.status))
#else
viewModel.routerPath.presentedSheet = .replyToStatusEditor(status: viewModel.localStatus ?? viewModel.status)
#endif
case .favorite:
SoundEffectManager.shared.playSound(.favorite)
await statusDataController.toggleFavorite(remoteStatus: viewModel.localStatusId)

View file

@ -53,20 +53,20 @@ struct StatusRowContextMenu: View {
systemImage: "bookmark")
}
Button {
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestinationEditor.replyToStatusEditor(status: viewModel.status))
} else {
viewModel.routerPath.presentedSheet = .replyToStatusEditor(status: viewModel.status)
}
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationEditor.replyToStatusEditor(status: viewModel.status))
#else
viewModel.routerPath.presentedSheet = .replyToStatusEditor(status: viewModel.status)
#endif
} label: {
Label("status.action.reply", systemImage: "arrowshape.turn.up.left")
}
Button {
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestinationEditor.quoteStatusEditor(status: viewModel.status))
} else {
viewModel.routerPath.presentedSheet = .quoteStatusEditor(status: viewModel.status)
}
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationEditor.quoteStatusEditor(status: viewModel.status))
#else
viewModel.routerPath.presentedSheet = .quoteStatusEditor(status: viewModel.status)
#endif
} label: {
Label("status.action.quote", systemImage: "quote.bubble")
}
@ -163,11 +163,11 @@ struct StatusRowContextMenu: View {
}
if currentInstance.isEditSupported {
Button {
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestinationEditor.editStatusEditor(status: viewModel.status.reblogAsAsStatus ?? viewModel.status))
} else {
viewModel.routerPath.presentedSheet = .editStatusEditor(status: viewModel.status.reblogAsAsStatus ?? viewModel.status)
}
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationEditor.editStatusEditor(status: viewModel.status.reblogAsAsStatus ?? viewModel.status))
#else
viewModel.routerPath.presentedSheet = .editStatusEditor(status: viewModel.status.reblogAsAsStatus ?? viewModel.status)
#endif
} label: {
Label("status.action.edit", systemImage: "pencil")
}

View file

@ -115,19 +115,19 @@ public struct StatusRowMediaPreviewView: View {
}
private func tabAction(for index: Int) {
if ProcessInfo.processInfo.isMacCatalystApp {
#if targetEnvironment(macCatalyst)
openWindow(
value: WindowDestinationMedia.mediaViewer(
attachments: attachments,
selectedAttachment: attachments[index]
)
)
} else {
#else
quickLook.prepareFor(
selectedMediaAttachment: attachments[index],
mediaAttachments: attachments
)
}
#endif
}
private static func accessibilityLabel(for attachment: MediaAttachment) -> Text {