v3.7.9 work

This commit is contained in:
Alin
2024-07-06 18:09:25 -06:00
parent 05101ea39f
commit 5aededb3a4
8 changed files with 74 additions and 28 deletions
@@ -133,7 +133,12 @@ struct PermissionsNotificationView: View {
.help("Check all permissions") .help("Check all permissions")
} else { } else {
Button(action: { Button(action: {
if #available(macOS 13.0, *) {
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
}
else {
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil) NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
}
}) { }) {
labelContent labelContent
} }
+27 -5
View File
@@ -25,14 +25,24 @@ class ThemeSettings: ObservableObject {
// pearcleaner - Color(.sRGB, red: 0.188143, green: 0.208556, blue: 0.262679, opacity: 1) // pearcleaner - Color(.sRGB, red: 0.188143, green: 0.208556, blue: 0.262679, opacity: 1)
init() { init() {
// Initialize color from UserDefaults or use a default value themeColor = userDefaults.color(forKey: colorKey) ?? .clear
if let components = UserDefaults.standard.object(forKey: colorKey) as? [CGFloat], components.count >= 4 { }
themeColor = Color(.sRGB, red: components[0], green: components[1], blue: components[2], opacity: components[3])
} else { func setupInitialColor() {
themeColor = Color(.sRGB, red: 0.188143, green: 0.208556, blue: 0.262679, opacity: 1) if userDefaults.color(forKey: colorKey) == nil {
// Only set the initial color if it has not been set by the user.
let darkMode = isDarkMode() // Safe to call here after the application is fully set up.
themeColor = darkMode ? Color(.sRGB, red: 0.188143, green: 0.208556, blue: 0.262679, opacity: 1) :
Color(.sRGB, red: 1.0, green: 1.0, blue: 1.0, opacity: 1)
saveThemeColor()
} }
} }
private func loadThemeColor() {
if let components = UserDefaults.standard.array(forKey: colorKey) as? [CGFloat], components.count == 4 {
themeColor = Color(.sRGB, red: components[0], green: components[1], blue: components[2], opacity: components[3])
}
}
func saveThemeColor() { func saveThemeColor() {
let nsColor = NSColor(themeColor) let nsColor = NSColor(themeColor)
@@ -90,6 +100,18 @@ extension Color {
} }
} }
extension Color {
/// Checks if the current themeColor is of a light or dark variant to set the appropriate displayMode on launch
func isLight() -> Bool? {
guard let components = NSColor(self).cgColor.components, components.count >= 3 else {
return nil
}
// Formula to calculate perceived luminance
let brightness = 0.299 * components[0] + 0.587 * components[1] + 0.114 * components[2]
return brightness > 0.5
}
}
extension UserDefaults { extension UserDefaults {
func color(forKey key: String) -> Color? { func color(forKey key: String) -> Color? {
guard let components = array(forKey: key) as? [CGFloat], components.count == 4 else { guard let components = array(forKey: key) as? [CGFloat], components.count == 4 else {
+9
View File
@@ -468,6 +468,15 @@ func isNested(path: URL) -> Bool {
return parentDirectory != applicationsPath && parentDirectory != homeApplicationsPath return parentDirectory != applicationsPath && parentDirectory != homeApplicationsPath
} }
// Check if macOS is 14.0 or higher
func isMacOS14OrHigher() -> Bool {
if #available(macOS 14, *) {
return true
} else {
return false
}
}
// --- Extend Int to convert hours to seconds --- // --- Extend Int to convert hours to seconds ---
+16 -9
View File
@@ -202,19 +202,26 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
func appearanceCheck(reset: Bool = false) { func appearanceCheck(reset: Bool = false) {
let dm = UserDefaults.standard.integer(forKey: "displayMode")
var displayMode = DisplayMode(rawValue: dm)
let dark = isDarkMode()
if dark {
displayMode?.colorScheme = .dark
} else {
displayMode?.colorScheme = .light
}
UserDefaults.standard.set(displayMode?.rawValue, forKey: "displayMode") // Setup initial color
ThemeSettings.shared.setupInitialColor()
// Get the current theme color
let themeColor = ThemeSettings.shared.themeColor
// Determine if the color is light or dark
if let isLightColor = themeColor.isLight() {
let shouldUseDarkMode = !isLightColor // Use dark mode if color is dark
UserDefaults.standard.set(shouldUseDarkMode ? DisplayMode.dark.rawValue : DisplayMode.light.rawValue, forKey: "displayMode")
} else {
// Default to system preference if unable to determine color brightness
let dark = isDarkMode()
UserDefaults.standard.set(dark ? DisplayMode.dark.rawValue : DisplayMode.light.rawValue, forKey: "displayMode")
}
// Reset theme when OS changes appearance // Reset theme when OS changes appearance
if reset { if reset {
let dark = isDarkMode()
ThemeSettings.shared.resetToDefault(dark: dark) ThemeSettings.shared.resetToDefault(dark: dark)
} }
+1 -1
View File
@@ -217,7 +217,7 @@ struct GeneralSettingsTab: View {
HStack(spacing: 0) { HStack(spacing: 0) {
Image(systemName: "accessibility") Image(systemName: isMacOS14OrHigher() ? "accessibility" : "figure.arms.open")
.resizable() .resizable()
.scaledToFit() .scaledToFit()
.frame(width: 20, height: 20) .frame(width: 20, height: 20)
+3 -10
View File
@@ -33,13 +33,6 @@ struct InterfaceSettingsTab: View {
@Binding var search: String @Binding var search: String
let icons = ["externaldrive", "trash", "folder", "pear-1", "pear-1.5", "pear-2", "pear-3", "pear-4"] let icons = ["externaldrive", "trash", "folder", "pear-1", "pear-1.5", "pear-2", "pear-3", "pear-4"]
var isMacOS14OrHigher: Bool {
if #available(macOS 14, *) {
return true
} else {
return false
}
}
var body: some View { var body: some View {
@@ -191,7 +184,7 @@ struct InterfaceSettingsTab: View {
.font(.callout) .font(.callout)
.foregroundStyle(Color("mode").opacity(0.5)) .foregroundStyle(Color("mode").opacity(0.5))
} }
InfoButton(text: "Changing the color mode will reset the base color to defaults") InfoButton(text: "This changes the text color to match the OS. It will also reset the base color to defaults when swapping between these.")
Spacer() Spacer()
Picker("", selection: $selectedTheme) { Picker("", selection: $selectedTheme) {
Text("Auto") Text("Auto")
@@ -260,7 +253,7 @@ struct InterfaceSettingsTab: View {
.padding(.leading) .padding(.leading)
HStack(spacing: 0) { HStack(spacing: 0) {
Image(systemName: mini ? "square.resize.up" : "square.resize.down") Image(systemName: isMacOS14OrHigher() ? "square.resize.up" : "macwindow.on.rectangle")
.resizable() .resizable()
.scaledToFit() .scaledToFit()
.frame(width: 20, height: 20) .frame(width: 20, height: 20)
@@ -448,7 +441,7 @@ struct InterfaceSettingsTab: View {
HStack(spacing: 0) { HStack(spacing: 0) {
Image(systemName: isLaunchAtLoginEnabled ? "person" : "person.slash") Image(systemName: isLaunchAtLoginEnabled ? "person.fill" : "person")
.resizable() .resizable()
.scaledToFit() .scaledToFit()
.frame(width: 20, height: 20) .frame(width: 20, height: 20)
+6 -1
View File
@@ -117,7 +117,12 @@ struct AppSearchView: View {
.buttonStyle(SimpleButtonStyle(icon: "circle.fill", label: "Settings", help: "Settings", size: 5)) .buttonStyle(SimpleButtonStyle(icon: "circle.fill", label: "Settings", help: "Settings", size: 5))
} else { } else {
Button("Settings") { Button("Settings") {
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: NSApp.delegate, from: nil) if #available(macOS 13.0, *) {
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
}
else {
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
}
showMenu = false showMenu = false
} }
.buttonStyle(SimpleButtonStyle(icon: "circle.fill", label: "Settings", help: "Settings", size: 5)) .buttonStyle(SimpleButtonStyle(icon: "circle.fill", label: "Settings", help: "Settings", size: 5))
+6 -1
View File
@@ -100,7 +100,12 @@ struct PermView: View {
.buttonStyle(SimpleButtonBrightStyle(icon: "gear", label: "Settings", help: "Check permissions in Settings", color: Color("mode"))) .buttonStyle(SimpleButtonBrightStyle(icon: "gear", label: "Settings", help: "Check permissions in Settings", color: Color("mode")))
} else { } else {
Button("Settings") { Button("Settings") {
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: NSApp.delegate, from: nil) if #available(macOS 13.0, *) {
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
}
else {
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
}
} }
.buttonStyle(SimpleButtonBrightStyle(icon: "gear", label: "Settings", help: "Check permissions in Settings", color: .red)) .buttonStyle(SimpleButtonBrightStyle(icon: "gear", label: "Settings", help: "Check permissions in Settings", color: .red))
} }