From 33732402a3bb5aa757de118af94c77dc8f872eb2 Mon Sep 17 00:00:00 2001 From: Alin Date: Wed, 27 Dec 2023 09:54:15 -0700 Subject: [PATCH] v2.2 --- Pearcleaner.xcodeproj/project.pbxproj | 12 ++++++---- Pearcleaner/Logic/Logic.swift | 12 +++++----- Pearcleaner/Logic/WindowSettings.swift | 31 ++++++++++++++++++++++++++ Pearcleaner/PearcleanerApp.swift | 24 +++++++++----------- 4 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 Pearcleaner/Logic/WindowSettings.swift diff --git a/Pearcleaner.xcodeproj/project.pbxproj b/Pearcleaner.xcodeproj/project.pbxproj index 803c96d..dba5e16 100644 --- a/Pearcleaner.xcodeproj/project.pbxproj +++ b/Pearcleaner.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ C77B901E2AF1A9DB009CC655 /* SettingsWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = C77B901D2AF1A9DB009CC655 /* SettingsWindow.swift */; }; C77B90232AF2D616009CC655 /* FilesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C77B90222AF2D616009CC655 /* FilesView.swift */; }; C7A27E812AFD7C4600166168 /* com.alienator88.PearcleanerSentinel.plist in Resources */ = {isa = PBXBuildFile; fileRef = C7A27E802AFD7C4600166168 /* com.alienator88.PearcleanerSentinel.plist */; }; + C7CF47242B3B3F1700979C5F /* WindowSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7CF47232B3B3F1700979C5F /* WindowSettings.swift */; }; C7D31D462AFDA90C00C7ED9E /* Sentinel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7D31D452AFDA90C00C7ED9E /* Sentinel.swift */; }; C7D31D482AFEB23700C7ED9E /* TopBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7D31D472AFEB23700C7ED9E /* TopBar.swift */; }; C7D31D4A2AFEB26700C7ED9E /* AppListItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7D31D492AFEB26700C7ED9E /* AppListItems.swift */; }; @@ -88,6 +89,7 @@ C77B90242AF2D796009CC655 /* Pearcleaner.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Pearcleaner.entitlements; sourceTree = ""; }; C7A27E7F2AFD70DD00166168 /* PearcleanerSentinel.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PearcleanerSentinel.entitlements; sourceTree = ""; }; C7A27E802AFD7C4600166168 /* com.alienator88.PearcleanerSentinel.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = com.alienator88.PearcleanerSentinel.plist; sourceTree = ""; }; + C7CF47232B3B3F1700979C5F /* WindowSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowSettings.swift; sourceTree = ""; }; C7D31D452AFDA90C00C7ED9E /* Sentinel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sentinel.swift; sourceTree = ""; }; C7D31D472AFEB23700C7ED9E /* TopBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopBar.swift; sourceTree = ""; }; C7D31D492AFEB26700C7ED9E /* AppListItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppListItems.swift; sourceTree = ""; }; @@ -137,6 +139,7 @@ C77B901B2AF193A3009CC655 /* Styles.swift */, C7D31D502AFF00F300C7ED9E /* Locations.swift */, C7D31D542B008CB900C7ED9E /* Shapes.swift */, + C7CF47232B3B3F1700979C5F /* WindowSettings.swift */, ); path = Logic; sourceTree = ""; @@ -367,6 +370,7 @@ C7D31D482AFEB23700C7ED9E /* TopBar.swift in Sources */, C7F539382AF60865007DF1B2 /* Utilities.swift in Sources */, C76D08552AF89CDE00D07867 /* AppListView.swift in Sources */, + C7CF47242B3B3F1700979C5F /* WindowSettings.swift in Sources */, C77B90232AF2D616009CC655 /* FilesView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -539,7 +543,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 13; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = BK8443AXLU; @@ -557,7 +561,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 2.1; + MARKETING_VERSION = 2.2; PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -574,7 +578,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 13; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = BK8443AXLU; @@ -592,7 +596,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 2.1; + MARKETING_VERSION = 2.2; PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; diff --git a/Pearcleaner/Logic/Logic.swift b/Pearcleaner/Logic/Logic.swift index e1ffdf0..1b53762 100644 --- a/Pearcleaner/Logic/Logic.swift +++ b/Pearcleaner/Logic/Logic.swift @@ -279,15 +279,17 @@ func findPathsForApp(appState: AppState, appInfo: AppInfo) { let fileManager = FileManager.default let dispatchGroup = DispatchGroup() - let bundleComponents = appInfo.bundleIdentifier.components(separatedBy: ".") + var bundleComponents = appInfo.bundleIdentifier.components(separatedBy: ".") + if let lastComponent = bundleComponents.last, let rangeOfDash = lastComponent.range(of: "-") { + // Remove the dash and everything after it + let updatedLastComponent = String(lastComponent[..= 3 { // get last 2 or middle 2 components bundle = bundleComponents[1...2].joined(separator: "").lowercased() } -// if bundleComponents[0] != "com" { -// weirdFormatBundle = true -// } + let nameL = appInfo.appName.pearFormat() let bundleIdentifierL = appInfo.bundleIdentifier.pearFormat() let locations = Locations() diff --git a/Pearcleaner/Logic/WindowSettings.swift b/Pearcleaner/Logic/WindowSettings.swift new file mode 100644 index 0000000..6e9a966 --- /dev/null +++ b/Pearcleaner/Logic/WindowSettings.swift @@ -0,0 +1,31 @@ +// +// WindowSettings.swift +// Pearcleaner +// +// Created by Alin Lupascu on 12/26/23. +// + +import SwiftUI + +class WindowSettings { + private let windowWidthKey = "windowWidthKey" + private let windowHeightKey = "windowHeightKey" + private let windowXKey = "windowXKey" + private let windowYKey = "windowYKey" + + func saveWindowSettings(frame: NSRect) { + UserDefaults.standard.set(Float(frame.size.width), forKey: windowWidthKey) + UserDefaults.standard.set(Float(frame.size.height), forKey: windowHeightKey) + UserDefaults.standard.set(Float(frame.origin.x), forKey: windowXKey) + UserDefaults.standard.set(Float(frame.origin.y), forKey: windowYKey) + } + + func loadWindowSettings() -> NSRect { + let width = CGFloat(UserDefaults.standard.float(forKey: windowWidthKey)) + let height = CGFloat(UserDefaults.standard.float(forKey: windowHeightKey)) + let x = CGFloat(UserDefaults.standard.float(forKey: windowXKey)) + let y = CGFloat(UserDefaults.standard.float(forKey: windowYKey)) + + return NSRect(x: x, y: y, width: width, height: height) + } +} diff --git a/Pearcleaner/PearcleanerApp.swift b/Pearcleaner/PearcleanerApp.swift index c50775a..6aa80eb 100644 --- a/Pearcleaner/PearcleanerApp.swift +++ b/Pearcleaner/PearcleanerApp.swift @@ -12,6 +12,7 @@ import AppKit struct PearcleanerApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate @StateObject var appState = AppState() + @State private var windowSettings = WindowSettings() @AppStorage("settings.updater.updateTimeframe") private var updateTimeframe: Int = 1 @AppStorage("settings.permissions.disk") private var diskP: Bool = false @AppStorage("settings.permissions.events") private var diskE: Bool = false @@ -54,10 +55,20 @@ struct PearcleanerApp: App { } return true } + // Save window size on window dimension change + .onChange(of: NSApplication.shared.windows.first?.frame) { newFrame in + if let newFrame = newFrame { + windowSettings.saveWindowSettings(frame: newFrame) + } + } .onAppear { // Disable tabbing NSWindow.allowsAutomaticWindowTabbing = false + // Set window size on load + let frame = windowSettings.loadWindowSettings() + NSApplication.shared.windows.first?.setFrame(frame, display: true) + // Get Apps let sortedApps = getSortedApps() appState.sortedApps.userApps = sortedApps.userApps @@ -121,20 +132,7 @@ struct PearcleanerApp: App { class AppDelegate: NSObject, NSApplicationDelegate { func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { - #if DEBUG return true - #else - return false - #endif } -// func application(_ sender: NSApplication, open urls: [URL]) { -// for url in urls { -// if url.pathExtension == "app" { -// writeLog(string: url.path) -// print("Dropped app path:", url.path) -// } -// } -// } - }