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
+6 -1
View File
@@ -133,7 +133,12 @@ struct PermissionsNotificationView: View {
.help("Check all permissions")
} else {
Button(action: {
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
if #available(macOS 13.0, *) {
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
}
else {
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
}
}) {
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)
init() {
// Initialize color from UserDefaults or use a default value
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 {
themeColor = Color(.sRGB, red: 0.188143, green: 0.208556, blue: 0.262679, opacity: 1)
themeColor = userDefaults.color(forKey: colorKey) ?? .clear
}
func setupInitialColor() {
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() {
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 {
func color(forKey key: String) -> Color? {
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
}
// 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 ---