Skip to content

Commit

Permalink
Require macOS 12
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 16, 2022
1 parent d514207 commit d135a36
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 212 deletions.
50 changes: 25 additions & 25 deletions Pasteboard Viewer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@
/* Begin PBXBuildFile section */
E31C294223FBE2FA00DF3442 /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = E31C294123FBE2FA00DF3442 /* Defaults */; };
E31C294423FBE32200DF3442 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = E31C294323FBE32200DF3442 /* Constants.swift */; };
E337758A2486CB9200DBE2A0 /* AppCenterCrashes in Frameworks */ = {isa = PBXBuildFile; productRef = E33775892486CB9200DBE2A0 /* AppCenterCrashes */; };
E338690024AC782D0074DFF8 /* InternetAccessPolicy.json in Resources */ = {isa = PBXBuildFile; fileRef = E33868FF24AC782D0074DFF8 /* InternetAccessPolicy.json */; };
E353C8B4256BE26800D08A09 /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E353C8B3256BE26800D08A09 /* WelcomeView.swift */; };
E353C8B4256BE26800D08A09 /* WelcomeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E353C8B3256BE26800D08A09 /* WelcomeScreen.swift */; };
E38A392227DC9FD900AD75D7 /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = E38A392127DC9FD900AD75D7 /* Sentry */; };
E3A7F1DD23F7DAD400CDF428 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A7F1DC23F7DAD400CDF428 /* App.swift */; };
E3A7F1DF23F7DAD400CDF428 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A7F1DE23F7DAD400CDF428 /* ContentView.swift */; };
E3A7F1DF23F7DAD400CDF428 /* MainScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A7F1DE23F7DAD400CDF428 /* MainScreen.swift */; };
E3A7F1E123F7DAD700CDF428 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E3A7F1E023F7DAD700CDF428 /* Assets.xcassets */; };
E3A7F1E423F7DAD700CDF428 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E3A7F1E323F7DAD700CDF428 /* Preview Assets.xcassets */; };
E3A7F20F23F7E36000CDF428 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A7F20E23F7E36000CDF428 /* Utilities.swift */; };
E3A7F21223F8498F00CDF428 /* PasteboardContentsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A7F21123F8498F00CDF428 /* PasteboardContentsView.swift */; };
E3A7F21223F8498F00CDF428 /* ContentsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A7F21123F8498F00CDF428 /* ContentsScreen.swift */; };
E3BB8DC623FBDBCE007A3849 /* Pasteboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3BB8DC523FBDBCE007A3849 /* Pasteboard.swift */; };
E3E4394225FDF97A000DE4B8 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3E4394125FDF97A000DE4B8 /* AppState.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
E31C294323FBE32200DF3442 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
E33868FF24AC782D0074DFF8 /* InternetAccessPolicy.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = InternetAccessPolicy.json; sourceTree = "<group>"; };
E353C8B3256BE26800D08A09 /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = "<group>"; };
E353C8B3256BE26800D08A09 /* WelcomeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeScreen.swift; sourceTree = "<group>"; };
E3A7F1D923F7DAD400CDF428 /* Pasteboard Viewer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Pasteboard Viewer.app"; sourceTree = BUILT_PRODUCTS_DIR; };
E3A7F1DC23F7DAD400CDF428 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
E3A7F1DE23F7DAD400CDF428 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
E3A7F1DE23F7DAD400CDF428 /* MainScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainScreen.swift; sourceTree = "<group>"; };
E3A7F1E023F7DAD700CDF428 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
E3A7F1E323F7DAD700CDF428 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
E3A7F1E823F7DAD700CDF428 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E3A7F1E923F7DAD700CDF428 /* Pasteboard_Viewer.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Pasteboard_Viewer.entitlements; sourceTree = "<group>"; };
E3A7F20E23F7E36000CDF428 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
E3A7F21123F8498F00CDF428 /* PasteboardContentsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasteboardContentsView.swift; sourceTree = "<group>"; };
E3A7F21123F8498F00CDF428 /* ContentsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentsScreen.swift; sourceTree = "<group>"; };
E3BB8DC523FBDBCE007A3849 /* Pasteboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pasteboard.swift; sourceTree = "<group>"; };
E3E4394125FDF97A000DE4B8 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -45,7 +45,7 @@
buildActionMask = 2147483647;
files = (
E31C294223FBE2FA00DF3442 /* Defaults in Frameworks */,
E337758A2486CB9200DBE2A0 /* AppCenterCrashes in Frameworks */,
E38A392227DC9FD900AD75D7 /* Sentry in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -75,10 +75,10 @@
E3A7F1DC23F7DAD400CDF428 /* App.swift */,
E3E4394125FDF97A000DE4B8 /* AppState.swift */,
E31C294323FBE32200DF3442 /* Constants.swift */,
E3A7F1DE23F7DAD400CDF428 /* ContentView.swift */,
E3A7F21123F8498F00CDF428 /* PasteboardContentsView.swift */,
E3A7F1DE23F7DAD400CDF428 /* MainScreen.swift */,
E3A7F21123F8498F00CDF428 /* ContentsScreen.swift */,
E3BB8DC523FBDBCE007A3849 /* Pasteboard.swift */,
E353C8B3256BE26800D08A09 /* WelcomeView.swift */,
E353C8B3256BE26800D08A09 /* WelcomeScreen.swift */,
E3A7F20E23F7E36000CDF428 /* Utilities.swift */,
E3A7F1E023F7DAD700CDF428 /* Assets.xcassets */,
E3D883B124C898890001C032 /* Other */,
Expand Down Expand Up @@ -124,7 +124,7 @@
name = "Pasteboard Viewer";
packageProductDependencies = (
E31C294123FBE2FA00DF3442 /* Defaults */,
E33775892486CB9200DBE2A0 /* AppCenterCrashes */,
E38A392127DC9FD900AD75D7 /* Sentry */,
);
productName = "Pasteboard Viewer";
productReference = E3A7F1D923F7DAD400CDF428 /* Pasteboard Viewer.app */;
Expand Down Expand Up @@ -156,7 +156,7 @@
mainGroup = E3A7F1D023F7DAD400CDF428;
packageReferences = (
E31C294023FBE2FA00DF3442 /* XCRemoteSwiftPackageReference "Defaults" */,
E33775882486CB9200DBE2A0 /* XCRemoteSwiftPackageReference "appcenter-sdk-apple" */,
E38A392027DC9FD900AD75D7 /* XCRemoteSwiftPackageReference "sentry-cocoa" */,
);
productRefGroup = E3A7F1DA23F7DAD400CDF428 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -208,13 +208,13 @@
buildActionMask = 2147483647;
files = (
E3A7F20F23F7E36000CDF428 /* Utilities.swift in Sources */,
E3A7F21223F8498F00CDF428 /* PasteboardContentsView.swift in Sources */,
E3A7F21223F8498F00CDF428 /* ContentsScreen.swift in Sources */,
E3BB8DC623FBDBCE007A3849 /* Pasteboard.swift in Sources */,
E3E4394225FDF97A000DE4B8 /* AppState.swift in Sources */,
E3A7F1DF23F7DAD400CDF428 /* ContentView.swift in Sources */,
E3A7F1DF23F7DAD400CDF428 /* MainScreen.swift in Sources */,
E3A7F1DD23F7DAD400CDF428 /* App.swift in Sources */,
E31C294423FBE32200DF3442 /* Constants.swift in Sources */,
E353C8B4256BE26800D08A09 /* WelcomeView.swift in Sources */,
E353C8B4256BE26800D08A09 /* WelcomeScreen.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -272,7 +272,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 11.5;
MACOSX_DEPLOYMENT_TARGET = 12.3;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -327,7 +327,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 11.5;
MACOSX_DEPLOYMENT_TARGET = 12.3;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -417,15 +417,15 @@
repositoryURL = "https://github.com/sindresorhus/Defaults";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 6.1.0;
minimumVersion = 6.2.0;
};
};
E33775882486CB9200DBE2A0 /* XCRemoteSwiftPackageReference "appcenter-sdk-apple" */ = {
E38A392027DC9FD900AD75D7 /* 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.4.1;
minimumVersion = 7.10.2;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand All @@ -436,10 +436,10 @@
package = E31C294023FBE2FA00DF3442 /* XCRemoteSwiftPackageReference "Defaults" */;
productName = Defaults;
};
E33775892486CB9200DBE2A0 /* AppCenterCrashes */ = {
E38A392127DC9FD900AD75D7 /* Sentry */ = {
isa = XCSwiftPackageProductDependency;
package = E33775882486CB9200DBE2A0 /* XCRemoteSwiftPackageReference "appcenter-sdk-apple" */;
productName = AppCenterCrashes;
package = E38A392027DC9FD900AD75D7 /* XCRemoteSwiftPackageReference "sentry-cocoa" */;
productName = Sentry;
};
/* End XCSwiftPackageProductDependency section */
};
Expand Down
39 changes: 11 additions & 28 deletions Pasteboard Viewer/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,41 @@ import Defaults
struct AppMain: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
@StateObject private var appState = AppState()
// TODO: Remove the below when targeting macOS 12.
@AppStorage(.stayOnTop) private var stayOnTop
@State var window: NSWindow? // swiftlint:disable:this swiftui_state_private

var body: some Scene {
WindowGroup {
ContentView()
MainScreen()
.environmentObject(appState)
.onAppear(perform: onAppear)
.task {
DispatchQueue.main.async {
showWelcomeScreenIfNeeded()
}
}
.bindNativeWindow($window)
.windowTabbingMode(.disallowed)
.windowLevel(stayOnTop ? .floating : .normal)
.eraseToAnyView() // This fixes an issue where the window size is not persisted. (macOS 12.1)
}
.commands {
// TODO: Remove this when SwiftUI support preventing the sidebar from being hidden.
SidebarCommands()
CommandGroup(replacing: .newItem) {}
CommandGroup(after: .windowSize) {
if #available(macOS 12, *) {
Defaults.Toggle("Stay on Top", key: .stayOnTop)
} else {
Toggle("Stay on Top", isOn: $stayOnTop)
}
Defaults.Toggle("Stay on Top", key: .stayOnTop)
}
CommandGroup(replacing: .help) {
// TODO: `Link` doesn't yet work here. (macOS 11.3)
// Link("Website", destination: "https://sindresorhus.com/pasteboard-viewer")
Button("Website") {
"https://sindresorhus.com/pasteboard-viewer".openUrl()
}
Button("Rate on the App Store") {
"macappstore://apps.apple.com/app/id1499215709?action=write-review".openUrl()
}
Button("More Apps by Me") {
"macappstore://apps.apple.com/developer/id328077650".openUrl()
}
Link("Website", destination: "https://sindresorhus.com/pasteboard-viewer")
Link("Rate on the App Store", destination: "macappstore://apps.apple.com/app/id1499215709?action=write-review")
Link("More Apps by Me", destination: "macappstore://apps.apple.com/developer/id328077650")
Divider()
Button("Send Feedback…") {
SSApp.openSendFeedbackPage()
}
}
}
}

private func onAppear() {
DispatchQueue.main.async {
showWelcomeScreenIfNeeded()
}
}
}

@MainActor
private final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true }
}
23 changes: 13 additions & 10 deletions Pasteboard Viewer/AppState.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import Combine
import AppCenter
import AppCenterCrashes
import SwiftUI
import Sentry

@MainActor
final class AppState: ObservableObject {
init() {
setUpConfig()
DispatchQueue.main.async(execute: didLaunch)

DispatchQueue.main.async { [self] in
didLaunch()
}
}

private func didLaunch() {
Expand All @@ -19,11 +22,11 @@ final class AppState: ObservableObject {
]
)

AppCenter.start(
withAppSecret: "3da13331-e82c-4245-b7fa-023424c17f16",
services: [
Crashes.self
]
)
#if !DEBUG
SentrySDK.start {
$0.dsn = "https://ded0fb3f6f7e4f0ca1f06048bfc26d57@o844094.ingest.sentry.io/6255818"
$0.enableSwizzling = false
}
#endif
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
import SwiftUI

struct PasteboardContentsView: View {
struct ContentsScreen: View {
@EnvironmentObject private var pasteboardObservable: NSPasteboard.Observable

let type: Pasteboard.Type_

var body: some View {
let data = type.data()
let sizeString = ByteCountFormatter.string(fromByteCount: Int64(data?.count ?? 0), countStyle: .file)
let sizeString = (data?.count ?? 0).formatted(.byteCount(style: .file))

func textSubtitle(_ string: String) -> String {
let lineCount = string.lineCount()
let suffix = lineCount == 1 ? "line" : "lines"
return "\(sizeString)\(lineCount) \(suffix)"
}

func renderString(_ string: String) -> some View {
ScrollableTextView(
text: .constant(string),
borderType: .noBorder
)
.navigationSubtitle(textSubtitle(string))
}

return Group {
// Ensure plain text is always rendered as plain text.
if
type.nsType.toUTType?.conforms(to: .plainText) == true,
let string = type.string()
{
renderString(string)
} else if
type.nsType.toUTType?.conforms(to: .utf16ExternalPlainText) == true,
let data = type.data(),
let string = String(data: data, encoding: .utf16)
{
renderString(string)
} else if
let data = data,
let image = NSImage(data: data)
{
Expand All @@ -36,17 +56,12 @@ struct PasteboardContentsView: View {
)
.navigationSubtitle(textSubtitle(attributedString.string))
} else if let string = type.string() {
ScrollableTextView(
text: .constant(string),
borderType: .noBorder
)
.navigationSubtitle(textSubtitle(string))
renderString(string)
} else if
let data = data,
let view = QuickLookPreview(data: data, contentType: type.nsType.toUTType ?? .plainText)
{
view
.background(Color(.textBackgroundColor))
.navigationSubtitle(sizeString)
} else if let data = data {
ScrollableTextView(
Expand All @@ -59,6 +74,7 @@ struct PasteboardContentsView: View {
.emptyStateTextStyle()
}
}
.background(.background)
.fillFrame()
.navigationTitle(type.title)
}
Expand Down
4 changes: 0 additions & 4 deletions Pasteboard Viewer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,5 @@
<string>clipboard,nspasteboard,copy,paste</string>
<key>NSHumanReadableCopyright</key>
<string>MIT License © Sindre Sorhus</string>
<key>NSSupportsAutomaticTermination</key>
<true/>
<key>NSSupportsSuddenTermination</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Pasteboard Viewer/InternetAccessPolicy.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Website": "https://sindresorhus.com/pasteboard-viewer",
"Connections" : [
{
"Host" : "*.appcenter.ms",
"Host" : "*.sentry.io",
"NetworkProtocol" : "TCP",
"Port" : "443",
"Purpose" : "Pasteboard Viewer sends crash reports to this server.",
Expand Down
Loading

0 comments on commit d135a36

Please sign in to comment.