Skip to content

Commit

Permalink
v3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alienator88 committed Mar 17, 2024
1 parent 236c678 commit 8dc9ee6
Show file tree
Hide file tree
Showing 12 changed files with 390 additions and 20 deletions.
12 changes: 12 additions & 0 deletions Pearcleaner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
C7D31D4A2AFEB26700C7ED9E /* AppListItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7D31D492AFEB26700C7ED9E /* AppListItems.swift */; };
C7D31D512AFF00F300C7ED9E /* Locations.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7D31D502AFF00F300C7ED9E /* Locations.swift */; };
C7DC1FEE2B9F7D3D009AC317 /* features.json in Resources */ = {isa = PBXBuildFile; fileRef = C7DC1FED2B9F7D3D009AC317 /* features.json */; };
C7DE67272BA61E8D00EB1633 /* MenuBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7DE67262BA61E8D00EB1633 /* MenuBar.swift */; };
C7DE672B2BA6343D00EB1633 /* MenuBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7DE672A2BA6343D00EB1633 /* MenuBarItem.swift */; };
C7DE672D2BA6356500EB1633 /* MenuBarMiniAppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7DE672C2BA6356500EB1633 /* MenuBarMiniAppView.swift */; };
C7F539382AF60865007DF1B2 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F539372AF60865007DF1B2 /* Utilities.swift */; };
C7FB173B2B96321300B96F9A /* AppsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7FB173A2B96321300B96F9A /* AppsListView.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -97,6 +100,9 @@
C7D31D492AFEB26700C7ED9E /* AppListItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppListItems.swift; sourceTree = "<group>"; };
C7D31D502AFF00F300C7ED9E /* Locations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Locations.swift; sourceTree = "<group>"; };
C7DC1FED2B9F7D3D009AC317 /* features.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = features.json; sourceTree = SOURCE_ROOT; };
C7DE67262BA61E8D00EB1633 /* MenuBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBar.swift; sourceTree = "<group>"; };
C7DE672A2BA6343D00EB1633 /* MenuBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarItem.swift; sourceTree = "<group>"; };
C7DE672C2BA6356500EB1633 /* MenuBarMiniAppView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarMiniAppView.swift; sourceTree = "<group>"; };
C7F539372AF60865007DF1B2 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
C7FB173A2B96321300B96F9A /* AppsListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppsListView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -134,6 +140,7 @@
isa = PBXGroup;
children = (
C77B90192AF1938F009CC655 /* Logic.swift */,
C7DE672A2BA6343D00EB1633 /* MenuBarItem.swift */,
C77B90172AF19382009CC655 /* AppCommands.swift */,
C77B90152AF19377009CC655 /* AppState.swift */,
C7F539372AF60865007DF1B2 /* Utilities.swift */,
Expand Down Expand Up @@ -168,6 +175,7 @@
children = (
C77B901D2AF1A9DB009CC655 /* SettingsWindow.swift */,
C76D08492AF83C6E00D07867 /* General.swift */,
C7DE67262BA61E8D00EB1633 /* MenuBar.swift */,
C76D08472AF83C3F00D07867 /* Update.swift */,
C76D08502AF850F300D07867 /* About.swift */,
);
Expand Down Expand Up @@ -229,6 +237,7 @@
C7045A272B03E71D00376976 /* MiniMode.swift */,
C71848432B8D2D600046CB13 /* ZombieView.swift */,
C7FB173A2B96321300B96F9A /* AppsListView.swift */,
C7DE672C2BA6356500EB1633 /* MenuBarMiniAppView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -347,13 +356,15 @@
C7045A342B068B2900376976 /* UpdateView.swift in Sources */,
C77B90162AF19377009CC655 /* AppState.swift in Sources */,
C7045A322B068AD700376976 /* NewWin.swift in Sources */,
C7DE672D2BA6356500EB1633 /* MenuBarMiniAppView.swift in Sources */,
C7D31D512AFF00F300C7ED9E /* Locations.swift in Sources */,
C77B901A2AF1938F009CC655 /* Logic.swift in Sources */,
C7045A2A2B03FAF000376976 /* TopBarMini.swift in Sources */,
C77B901C2AF193A3009CC655 /* Styles.swift in Sources */,
C7045A282B03E71D00376976 /* MiniMode.swift in Sources */,
C72893052AFD42E600C8C1CD /* DeepLink.swift in Sources */,
C71848442B8D2D600046CB13 /* ZombieView.swift in Sources */,
C7DE672B2BA6343D00EB1633 /* MenuBarItem.swift in Sources */,
C76D084A2AF83C6E00D07867 /* General.swift in Sources */,
C77B90042AF18E2E009CC655 /* PearcleanerApp.swift in Sources */,
C7045A362B068DD700376976 /* PermView.swift in Sources */,
Expand All @@ -367,6 +378,7 @@
C76D08552AF89CDE00D07867 /* RegularMode.swift in Sources */,
C7A9CE472B89164700EB6E78 /* Authorization.swift in Sources */,
C7CF47242B3B3F1700979C5F /* WindowSettings.swift in Sources */,
C7DE67272BA61E8D00EB1633 /* MenuBar.swift in Sources */,
C77B90232AF2D616009CC655 /* FilesView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 2 additions & 0 deletions Pearcleaner/Logic/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct ZombieFile: Identifiable, Equatable, Hashable {
enum CurrentTabView:Int
{
case general
case menubar
// case permissions
// case sentinel
case update
Expand All @@ -113,6 +114,7 @@ enum CurrentTabView:Int
var title: String {
switch self {
case .general: return "General"
case .menubar: return "MenuBar"
// case .permissions: return "Permissions"
// case .sentinel: return "Sentinel"
case .update: return "Update"
Expand Down
60 changes: 60 additions & 0 deletions Pearcleaner/Logic/MenuBarItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// MenuBarItem.swift
// Pearcleaner
//
// Created by Alin Lupascu on 3/16/24.
//

import AppKit
import SwiftUI

class MenuBarExtraManager {
static let shared = MenuBarExtraManager()
private var statusItem: NSStatusItem?
private var popover = NSPopover()

func addMenuBarExtra<V: View>(withView view: @escaping () -> V) {
guard statusItem == nil else { return }

// Initialize the status item
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)

// Set up the status item's button
if let button = statusItem?.button {
button.image = NSImage(systemSymbolName: "menubar.rectangle", accessibilityDescription: "Pearcleaner")
button.action = #selector(togglePopover(_:))
button.target = self
}

// Set up the popover
popover.contentSize = NSSize(width: 300, height: 370)
popover.behavior = .transient
popover.contentViewController = NSHostingController(rootView: view())
}


func removeMenuBarExtra() {
if let item = statusItem {
NSStatusBar.system.removeStatusItem(item)
statusItem = nil
}
}

func getStatus() -> Bool {
if let item = statusItem {
return true
} else {
return false
}
}

@objc func togglePopover(_ sender: AnyObject?) {
if let button = statusItem?.button {
if popover.isShown {
popover.performClose(sender)
} else {
popover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
}
}
}
}
18 changes: 18 additions & 0 deletions Pearcleaner/Logic/WindowSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class WindowSettings {
private let windowXKey = "windowXKey"
private let windowYKey = "windowYKey"
@AppStorage("settings.general.mini") private var mini: Bool = false
var window: NSWindow?

func saveWindowSettings(frame: NSRect) {

Expand All @@ -32,4 +33,21 @@ class WindowSettings {
let y = CGFloat(UserDefaults.standard.float(forKey: windowYKey))
return NSRect(x: x, y: y, width: width, height: height)
}

func newWindow<V: View>(withView view: @escaping () -> V) {
let contentView = view
let frame = self.loadWindowSettings()
// Create the window and set the content view
let newWindow = NSWindow(
contentRect: frame,
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered, defer: false)
newWindow.titlebarAppearsTransparent = true
newWindow.isMovableByWindowBackground = true
newWindow.center()
newWindow.setFrameAutosaveName("Main Window")
newWindow.contentView = NSHostingView(rootView: contentView())
self.window = newWindow
newWindow.makeKeyAndOrderFront(nil)
}
}
41 changes: 35 additions & 6 deletions Pearcleaner/PearcleanerApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import AppKit
import ServiceManagement

@main
struct PearcleanerApp: App {
Expand All @@ -24,10 +25,15 @@ struct PearcleanerApp: App {
@AppStorage("settings.general.instant") private var instantSearch: Bool = true
@AppStorage("settings.general.features") private var features: String = ""
@AppStorage("settings.general.brew") private var brew: Bool = false
@AppStorage("settings.menubar.enabled") private var menubarEnabled: Bool = false
@AppStorage("settings.menubar.mainWin") private var mainWinEnabled: Bool = false

@State private var search = ""
@State private var showPopover: Bool = false
@State private var showFeature: Bool = false



var body: some Scene {

WindowGroup {
Expand Down Expand Up @@ -100,6 +106,15 @@ struct PearcleanerApp: App {
loadAllPaths(allApps: sortedApps, appState: appState, locations: locations)
}

if menubarEnabled {
MenuBarExtraManager.shared.addMenuBarExtra {
MenuBarMiniAppView(search: $search, showPopover: $showPopover)
.environmentObject(locations)
.environmentObject(appState)
}
}



#if !DEBUG
Task {
Expand Down Expand Up @@ -135,6 +150,7 @@ struct PearcleanerApp: App {
#endif
}
}

.windowStyle(.hiddenTitleBar)
.windowResizability(.contentMinSize)
.commands {
Expand All @@ -143,10 +159,13 @@ struct PearcleanerApp: App {

}




Settings {
SettingsView(showPopover: $showPopover, showFeature: $showFeature)
SettingsView(showPopover: $showPopover, search: $search, showFeature: $showFeature)
.environmentObject(appState)
.environmentObject(locations)
.toolbarBackground(.clear)
.preferredColorScheme(displayMode.colorScheme)
}
Expand All @@ -157,14 +176,24 @@ struct PearcleanerApp: App {


class AppDelegate: NSObject, NSApplicationDelegate {

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
let menubarEnabled = UserDefaults.standard.bool(forKey: "settings.menubar.enabled")
return !menubarEnabled
}

// func applicationDidFinishLaunching(_ notification: Notification, win: WindowSettings) {
// let frame = win.loadWindowSettings()
// NSApplication.shared.windows.first?.setFrame(frame, display: true)
// }

func applicationDidFinishLaunching(_ notification: Notification) {
let menubarEnabled = UserDefaults.standard.bool(forKey: "settings.menubar.enabled")

#if !DEBUG
if menubarEnabled {
NSApp.windows.first?.close()
NSApplication.shared.setActivationPolicy(.accessory)
}
#endif

}

}

14 changes: 6 additions & 8 deletions Pearcleaner/Settings/General.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import Foundation
import SwiftUI
import ServiceManagement

struct GeneralSettingsTab: View {
@EnvironmentObject var appState: AppState
@EnvironmentObject var locations: Locations
@State private var windowSettings = WindowSettings()
@AppStorage("settings.general.glass") private var glass: Bool = true
@AppStorage("settings.general.mini") private var mini: Bool = false
Expand All @@ -26,6 +28,7 @@ struct GeneralSettingsTab: View {
@State private var accessStatus: Bool = false
private let themes = ["Auto", "Dark", "Light"]
@Binding var showPopover: Bool
@Binding var search: String

var body: some View {
Form {
Expand Down Expand Up @@ -148,7 +151,7 @@ struct GeneralSettingsTab: View {
.padding(5)
.padding(.leading)

// =========================================================================================================
// === Mini =================================================================================================

Divider()
.padding()
Expand Down Expand Up @@ -247,7 +250,7 @@ struct GeneralSettingsTab: View {
.padding(.leading)


// =========================================================================================================
// === Perms ================================================================================================


Divider()
Expand Down Expand Up @@ -312,7 +315,7 @@ struct GeneralSettingsTab: View {
.padding(.leading)


// =========================================================================================================
// === Sentinel =============================================================================================

Divider()
.padding()
Expand Down Expand Up @@ -362,11 +365,6 @@ struct GeneralSettingsTab: View {
.onAppear {
diskStatus = checkAndRequestFullDiskAccess(appState: appState, skipAlert: true)
accessStatus = checkAndRequestAccessibilityAccess(appState: appState)
// if displayMode.colorScheme == .dark {
// selectedTheme = "Dark"
// } else if displayMode.colorScheme == .light {
// selectedTheme = "Light"
// }
}

}
Expand Down
Loading

0 comments on commit 8dc9ee6

Please sign in to comment.