mirror of
https://github.com/exituser/Pearcleaner.git
synced 2026-09-17 07:19:04 +00:00
v2.2
This commit is contained in:
@@ -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[..<rangeOfDash.lowerBound])
|
||||
bundleComponents[bundleComponents.count - 1] = updatedLastComponent
|
||||
}
|
||||
var bundle: String = ""
|
||||
// var weirdFormatBundle: Bool = false
|
||||
if bundleComponents.count >= 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()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user