mirror of
https://github.com/exituser/Pearcleaner.git
synced 2026-09-17 10:48:52 +00:00
v3.7.9 work
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 ---
|
||||
|
||||
Reference in New Issue
Block a user