Skip to content

Commit

Permalink
v3.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
alienator88 committed Jun 14, 2024
1 parent 72756ad commit 8a4a863
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 173 deletions.
8 changes: 4 additions & 4 deletions Pearcleaner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,8 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
APP_BUILD = 46;
APP_VERSION = 3.7.1;
APP_BUILD = 47;
APP_VERSION = 3.7.2;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
Expand Down Expand Up @@ -638,8 +638,8 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
APP_BUILD = 46;
APP_VERSION = 3.7.1;
APP_BUILD = 47;
APP_VERSION = 3.7.2;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
Expand Down
28 changes: 27 additions & 1 deletion Pearcleaner/Logic/Styles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ extension View {
}
}


// Background color/glass setter
@ViewBuilder
func backgroundView(themeSettings: ThemeSettings, darker: Bool = false, glass: Bool = false) -> some View {
if glass {
Expand All @@ -940,6 +940,32 @@ func backgroundView(themeSettings: ThemeSettings, darker: Bool = false, glass: B
}


struct PickerModifier: ViewModifier {
@State private var isHovered: Bool = false
let themeSettings: ThemeSettings

func body(content: Content) -> some View {
content
.buttonStyle(.borderless)
.padding(4)
.background {
backgroundView(themeSettings: themeSettings, darker: isHovered)
.clipShape(RoundedRectangle(cornerRadius: 10))
}
.onHover { hovering in
isHovered = hovering
}
}
}

extension View {
func pickerStyle(themeSettings: ThemeSettings) -> some View {
self.modifier(PickerModifier(themeSettings: themeSettings))
}
}


// Preset view elements
struct PresetColor: ButtonStyle {
var fillColor: Color
var label: String
Expand Down
107 changes: 90 additions & 17 deletions Pearcleaner/Logic/Updater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,35 +170,62 @@ func UnzipAndReplace(DownloadedFileURL fileURL: String, appState: AppState) {

// --- Updater check frequency

func updateNextUpdateDate() {
@AppStorage("settings.updater.updateTimeframe") var updateTimeframe: Int = 1
@AppStorage("settings.updater.nextUpdateDate") var nextUpdateDate = Date.now.timeIntervalSinceReferenceDate
let updateSeconds = updateTimeframe.daysToSeconds
let newUpdateDate = Calendar.current.startOfDay(for: Date().addingTimeInterval(updateSeconds))
nextUpdateDate = newUpdateDate.timeIntervalSinceReferenceDate
enum UpdateFrequency: String, CaseIterable, Identifiable {
case none = "Never"
case daily = "Daily"
case weekly = "Weekly"
case monthly = "Monthly"

var id: String { self.rawValue }

var interval: TimeInterval? {
switch self {
case .none:
return nil
case .daily:
return 86400 // 1 day in seconds
case .weekly:
return 604800 // 7 days in seconds
case .monthly:
return 2592000 // 30 days in seconds
}
}

func updateNextUpdateDate() {
guard let updateInterval = self.interval else { return }
let newUpdateDate = Calendar.current.startOfDay(for: Date().addingTimeInterval(updateInterval))
UserDefaults.standard.set(newUpdateDate.timeIntervalSinceReferenceDate, forKey: "settings.updater.nextUpdateDate")
}
}

//func updateNextUpdateDate() {
// @AppStorage("settings.updater.updateFrequency") var updateFrequency: UpdateFrequency = .daily
// @AppStorage("settings.updater.nextUpdateDate") var nextUpdateDate = Date.now.timeIntervalSinceReferenceDate
//
// guard let updateInterval = updateFrequency.interval else { return }
// let newUpdateDate = Calendar.current.startOfDay(for: Date().addingTimeInterval(updateInterval))
// nextUpdateDate = newUpdateDate.timeIntervalSinceReferenceDate
//}

func checkAndUpdateIfNeeded(appState: AppState) {
@AppStorage("settings.updater.updateTimeframe") var updateTimeframe: Int = 1
@AppStorage("settings.updater.updateFrequency") var updateFrequency: UpdateFrequency = .daily
@AppStorage("settings.updater.nextUpdateDate") var nextUpdateDate = Date.now.timeIntervalSinceReferenceDate

let updateSeconds = updateTimeframe.daysToSeconds
let now = Date()
guard let updateInterval = updateFrequency.interval else {
printOS("Updater: no update frequency set, skipping check")
return
}

// Retrieve the next update date from UserDefaults
let now = Date()
let nextUpdateDateLocal = Date(timeIntervalSinceReferenceDate: nextUpdateDate)
// let nextUpdateDate = UserDefaults.standard.object(forKey: "settings.updater.nextUpdateDate") as? Date

// If there's no stored next update date or it's in the past, update immediately
if !isSameDay(date1: nextUpdateDateLocal, date2: now) {
// Next update date is in the future, no need to update
printOS("Updater: next update date is in the future, skipping")
printOS("Updater: next update date is in the future, skipping (\(nextUpdateDateLocal))")
return
}

// Update immediately and set next update date
updateApp(appState: appState)
setNextUpdateDate(interval: updateSeconds)
setNextUpdateDate(interval: updateInterval)
}

func updateApp(appState: AppState) {
Expand All @@ -210,13 +237,59 @@ func updateApp(appState: AppState) {
func setNextUpdateDate(interval: TimeInterval) {
let newUpdateDate = Calendar.current.startOfDay(for: Date().addingTimeInterval(interval))
UserDefaults.standard.set(newUpdateDate.timeIntervalSinceReferenceDate, forKey: "settings.updater.nextUpdateDate")
// UserDefaults.standard.set(newUpdateDate, forKey: "settings.updater.nextUpdateDate")
}

func isSameDay(date1: Date, date2: Date) -> Bool {
return Calendar.current.isDate(date1, inSameDayAs: date2)
}

//func updateNextUpdateDate() {
// @AppStorage("settings.updater.updateTimeframe") var updateTimeframe: Int = 1
// @AppStorage("settings.updater.nextUpdateDate") var nextUpdateDate = Date.now.timeIntervalSinceReferenceDate
// let updateSeconds = updateTimeframe.daysToSeconds
// let newUpdateDate = Calendar.current.startOfDay(for: Date().addingTimeInterval(updateSeconds))
// nextUpdateDate = newUpdateDate.timeIntervalSinceReferenceDate
//}
//
//func checkAndUpdateIfNeeded(appState: AppState) {
// @AppStorage("settings.updater.updateTimeframe") var updateTimeframe: Int = 1
// @AppStorage("settings.updater.nextUpdateDate") var nextUpdateDate = Date.now.timeIntervalSinceReferenceDate
//
// let updateSeconds = updateTimeframe.daysToSeconds
// let now = Date()
//
// // Retrieve the next update date from UserDefaults
// let nextUpdateDateLocal = Date(timeIntervalSinceReferenceDate: nextUpdateDate)
//// let nextUpdateDate = UserDefaults.standard.object(forKey: "settings.updater.nextUpdateDate") as? Date
//
// // If there's no stored next update date or it's in the past, update immediately
// if !isSameDay(date1: nextUpdateDateLocal, date2: now) {
// // Next update date is in the future, no need to update
// printOS("Updater: next update date is in the future, skipping")
// return
// }
//
// // Update immediately and set next update date
// updateApp(appState: appState)
// setNextUpdateDate(interval: updateSeconds)
//}
//
//func updateApp(appState: AppState) {
// // Perform your update logic here
// printOS("Updater: performing update")
// loadGithubReleases(appState: appState)
//}
//
//func setNextUpdateDate(interval: TimeInterval) {
// let newUpdateDate = Calendar.current.startOfDay(for: Date().addingTimeInterval(interval))
// UserDefaults.standard.set(newUpdateDate.timeIntervalSinceReferenceDate, forKey: "settings.updater.nextUpdateDate")
//// UserDefaults.standard.set(newUpdateDate, forKey: "settings.updater.nextUpdateDate")
//}
//
//func isSameDay(date1: Date, date2: Date) -> Bool {
// return Calendar.current.isDate(date1, inSameDayAs: date2)
//}



// --- Updater Badge View
Expand Down
17 changes: 9 additions & 8 deletions Pearcleaner/PearcleanerApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ struct PearcleanerApp: App {
@StateObject var locations = Locations()
@StateObject var fsm = FolderSettingsManager()
@State private var windowSettings = WindowSettings()
// @AppStorage("settings.updater.updateTimeframe") private var updateTimeframe: Int = 1
@AppStorage("settings.updater.enableUpdates") private var enableUpdates: Bool = true
@AppStorage("settings.updater.updateFrequency") private var updateFrequency: UpdateFrequency = .daily
@AppStorage("settings.permissions.hasLaunched") private var hasLaunched: Bool = false
@AppStorage("displayMode") var displayMode: DisplayMode = .system
@AppStorage("settings.general.mini") private var mini: Bool = false
Expand Down Expand Up @@ -121,7 +120,7 @@ struct PearcleanerApp: App {
// Get GH releases
loadGithubReleases(appState: appState, releaseOnly: true)

if enableUpdates {
if updateFrequency != .none {
// Update checker
checkAndUpdateIfNeeded(appState: appState)
}
Expand Down Expand Up @@ -181,10 +180,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {

findAndSetWindowFrame(named: ["Pearcleaner"], windowSettings: windowSettings)

if UserDefaults.standard.object(forKey: "themeColor") == nil {
self.appearanceChanged()
}
// if UserDefaults.standard.object(forKey: "themeColor") == nil {
// self.appearanceChanged()
// }

self.appearanceCheck()

if menubarEnabled {
findAndHideWindows(named: ["Pearcleaner"])
NSApplication.shared.setActivationPolicy(.accessory)
Expand All @@ -194,14 +195,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
observer = DistributedNotificationCenter.default().addObserver(forName: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil, queue: OperationQueue.main) { [weak self] _ in
let themeMode = UserDefaults.standard.string(forKey: "settings.general.selectedTheme")
if themeMode == "Auto" {
self?.appearanceChanged()
self?.appearanceCheck()
}
}

}


func appearanceChanged() {
func appearanceCheck() {
let dm = UserDefaults.standard.integer(forKey: "displayMode")
var displayMode = DisplayMode(rawValue: dm)
let dark = isDarkMode()
Expand Down
7 changes: 5 additions & 2 deletions Pearcleaner/Settings/Folders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct FolderSettingsTab: View {
@EnvironmentObject var appState: AppState
@EnvironmentObject var locations: Locations
@EnvironmentObject var fsm: FolderSettingsManager
@EnvironmentObject var themeSettings: ThemeSettings
@State private var isHovered = false

var body: some View {
Expand Down Expand Up @@ -81,7 +82,8 @@ struct FolderSettingsTab: View {
}
.scrollIndicators(.automatic)
.padding()
.background(Color("mode").opacity(0.05))
// .background(Color("mode").opacity(0.05))
.background(backgroundView(themeSettings: themeSettings, darker: true))
.clipShape(RoundedRectangle(cornerRadius: 10))
.onDrop(of: ["public.file-url"], isTargeted: nil) { providers -> Bool in
providers.forEach { provider in
Expand Down Expand Up @@ -173,7 +175,8 @@ struct FolderSettingsTab: View {
}
.scrollIndicators(.automatic)
.padding()
.background(Color("mode").opacity(0.05))
.background(backgroundView(themeSettings: themeSettings, darker: true))
// .background(Color("mode").opacity(0.05))
.clipShape(RoundedRectangle(cornerRadius: 10))
.onDrop(of: ["public.file-url"], isTargeted: nil) { providers -> Bool in
providers.forEach { provider in
Expand Down
Loading

0 comments on commit 8a4a863

Please sign in to comment.