mirror of
https://github.com/exituser/Pearcleaner.git
synced 2026-09-17 09:38:51 +00:00
v3.8.7
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import FinderSync
|
||||
//import FinderSync
|
||||
|
||||
let home = FileManager.default.homeDirectoryForCurrentUser.path
|
||||
|
||||
@@ -79,10 +79,28 @@ class AppState: ObservableObject {
|
||||
}
|
||||
|
||||
@objc func updateExtensionStatus() {
|
||||
let extensionStatus = FIFinderSyncController.isExtensionEnabled
|
||||
DispatchQueue.main.async {
|
||||
self.finderExtensionEnabled = extensionStatus
|
||||
let task = Process()
|
||||
let pipe = Pipe()
|
||||
|
||||
task.launchPath = "/bin/zsh"
|
||||
task.arguments = ["-c", "pluginkit -m -i com.alienator88.Pearcleaner"]
|
||||
task.standardOutput = pipe
|
||||
task.launch()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
task.waitUntilExit()
|
||||
|
||||
if let output = String(data: data, encoding: .utf8) {
|
||||
// Check if the output starts with a '+' indicating it's enabled
|
||||
let extensionStatus = output.contains("+")
|
||||
DispatchQueue.main.async {
|
||||
self.finderExtensionEnabled = extensionStatus
|
||||
}
|
||||
}
|
||||
// let extensionStatus = FIFinderSyncController.isExtensionEnabled
|
||||
// DispatchQueue.main.async {
|
||||
// self.finderExtensionEnabled = extensionStatus
|
||||
// }
|
||||
}
|
||||
|
||||
func triggerUninstallAlert() {
|
||||
|
||||
@@ -27,12 +27,14 @@ func reloadAppsList(appState: AppState, fsm: FolderSettingsManager) {
|
||||
|
||||
func resizeWindowAuto(windowSettings: WindowSettings, title: String) {
|
||||
if let window = NSApplication.shared.windows.first(where: { $0.title == title }) {
|
||||
print(windowSettings.loadWindowSettings())
|
||||
let newSize = NSSize(width: windowSettings.loadWindowSettings().width, height: windowSettings.loadWindowSettings().height)
|
||||
window.setContentSize(newSize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Check if Pearcleaner has any windows open
|
||||
func hasWindowOpen() -> Bool {
|
||||
for window in NSApp.windows where window.title == "Pearcleaner" {
|
||||
@@ -260,6 +262,18 @@ func manageSymlink(install: Bool) {
|
||||
}
|
||||
|
||||
|
||||
// FinderExtension Sequoia Fix
|
||||
func manageFinderPlugin(install: Bool) {
|
||||
let task = Process()
|
||||
task.launchPath = "/usr/bin/pluginkit"
|
||||
|
||||
task.arguments = ["-e", "\(install ? "use" : "ignore")", "-i", "com.alienator88.Pearcleaner"]
|
||||
|
||||
task.launch()
|
||||
task.waitUntilExit()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Brew cleanup
|
||||
func caskCleanup(app: String) {
|
||||
|
||||
@@ -13,28 +13,20 @@ import Combine
|
||||
class WindowSettings {
|
||||
private let windowWidthKey = "windowWidthKey"
|
||||
private let windowHeightKey = "windowHeightKey"
|
||||
private let windowWidthKeyMini = "windowWidthKeyMini"
|
||||
private let windowHeightKeyMini = "windowHeightKeyMini"
|
||||
private let windowXKey = "windowXKey"
|
||||
private let windowYKey = "windowYKey"
|
||||
@AppStorage("settings.general.mini") private var mini: Bool = false
|
||||
var windows: [NSWindow] = []
|
||||
|
||||
// Register default sizes if the AppStorage keys are invalid
|
||||
func registerDefaultWindowSettings(completion: @escaping () -> Void = {}) {
|
||||
|
||||
let defaults = UserDefaults.standard
|
||||
|
||||
// Get primary screen
|
||||
let screenFrame = NSScreen.main?.visibleFrame ?? NSRect(x: 0, y: 0, width: 800, height: 600)
|
||||
|
||||
// Calculate default window sizes and x/y coordinates
|
||||
let defaultWidth = Float(900) // Default width for regular window
|
||||
let defaultHeight = Float(600) // Default height for regular window
|
||||
let defaultWidthMini = Float(300) // Default width for mini window
|
||||
let defaultHeightMini = Float(370) // Default height for mini window
|
||||
let defaultHeight = Float(628) // Default height for regular window
|
||||
let defaultX = Float((screenFrame.width - CGFloat(defaultWidth)) / 2 + screenFrame.origin.x) // Default X coordinate
|
||||
let defaultY = Float((screenFrame.height - CGFloat(defaultHeight)) / 2 + screenFrame.origin.y) // Default Y coordinate
|
||||
|
||||
// Set defaults only if they are not already set
|
||||
if defaults.object(forKey: windowWidthKey) == nil {
|
||||
defaults.set(defaultWidth, forKey: windowWidthKey)
|
||||
@@ -42,60 +34,69 @@ class WindowSettings {
|
||||
if defaults.object(forKey: windowHeightKey) == nil {
|
||||
defaults.set(defaultHeight, forKey: windowHeightKey)
|
||||
}
|
||||
if defaults.object(forKey: windowWidthKeyMini) == nil {
|
||||
defaults.set(defaultWidthMini, forKey: windowWidthKeyMini)
|
||||
}
|
||||
if defaults.object(forKey: windowHeightKeyMini) == nil {
|
||||
defaults.set(defaultHeightMini, forKey: windowHeightKeyMini)
|
||||
}
|
||||
if defaults.object(forKey: windowXKey) == nil {
|
||||
defaults.set(defaultX, forKey: windowXKey)
|
||||
}
|
||||
if defaults.object(forKey: windowYKey) == nil {
|
||||
defaults.set(defaultY, forKey: windowYKey)
|
||||
}
|
||||
|
||||
completion()
|
||||
|
||||
}
|
||||
|
||||
// Save user window settings
|
||||
func saveWindowSettings(frame: NSRect) {
|
||||
UserDefaults.standard.set(Float(frame.size.width), forKey: mini ? windowWidthKeyMini : windowWidthKey)
|
||||
UserDefaults.standard.set(Float(frame.size.height), forKey: mini ? windowHeightKeyMini : windowHeightKey)
|
||||
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)
|
||||
}
|
||||
|
||||
// Load default window settings or user defined settings
|
||||
func loadWindowSettings() -> NSRect {
|
||||
let width = CGFloat(UserDefaults.standard.float(forKey: mini ? windowWidthKeyMini : windowWidthKey))
|
||||
let height = CGFloat(UserDefaults.standard.float(forKey: mini ? windowHeightKeyMini : windowHeightKey))
|
||||
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)
|
||||
}
|
||||
|
||||
// Reset to default sizes when toggling the window state
|
||||
func resetWindowSettings(mini: Bool) -> NSRect {
|
||||
let screenFrame = NSScreen.main?.visibleFrame ?? NSRect(x: 0, y: 0, width: 800, height: 600)
|
||||
// Define sizes based on whether mini mode is active
|
||||
let defaultWidth: CGFloat = mini ? 300 : 900 // Mini or Regular width
|
||||
let defaultHeight: CGFloat = mini ? 373 : 628 // Mini or Regular height
|
||||
// Calculate the X and Y coordinates based on the size
|
||||
let defaultX = (screenFrame.width - defaultWidth) / 2 + screenFrame.origin.x
|
||||
let defaultY = (screenFrame.height - defaultHeight) / 2 + screenFrame.origin.y
|
||||
// Store these values in UserDefaults (if needed)
|
||||
UserDefaults.standard.set(Float(defaultWidth), forKey: windowWidthKey)
|
||||
UserDefaults.standard.set(Float(defaultHeight), forKey: windowHeightKey)
|
||||
UserDefaults.standard.set(Float(defaultX), forKey: windowXKey)
|
||||
UserDefaults.standard.set(Float(defaultY), forKey: windowYKey)
|
||||
// Return the frame for the window with appropriate size and position
|
||||
return NSRect(x: defaultX, y: defaultY, width: defaultWidth, height: defaultHeight)
|
||||
}
|
||||
|
||||
// Launch new app windows on demand
|
||||
func newWindow<V: View>(withView view: @escaping () -> V) {
|
||||
func newWindow<V: View>(mini: Bool, withView view: @escaping () -> V) {
|
||||
// Close existing window
|
||||
findAndHideWindows(named: ["Pearcleaner"])
|
||||
// Create new window using defaults
|
||||
let contentView = view
|
||||
let frame = self.loadWindowSettings()
|
||||
let frame = self.resetWindowSettings(mini: mini)
|
||||
let newWindow = NSWindow(
|
||||
contentRect: frame,
|
||||
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
||||
backing: .buffered, defer: false)
|
||||
newWindow.contentView = NSHostingView(rootView: contentView())
|
||||
newWindow.titlebarAppearsTransparent = true
|
||||
newWindow.isMovableByWindowBackground = true
|
||||
newWindow.center()
|
||||
newWindow.title = "Pearcleaner"
|
||||
newWindow.isRestorable = false
|
||||
newWindow.titleVisibility = .hidden
|
||||
newWindow.setFrameAutosaveName("Pearcleaner")
|
||||
newWindow.contentView = NSHostingView(rootView: contentView())
|
||||
self.windows.append(newWindow)
|
||||
newWindow.titleVisibility = .hidden
|
||||
newWindow.makeKeyAndOrderFront(nil)
|
||||
resizeWindowAuto(windowSettings: self, title: "Pearcleaner")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user