mirror of
https://github.com/exituser/Pearcleaner.git
synced 2026-09-17 11:58:54 +00:00
initial
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// PearcleanerApp.swift
|
||||
// Pearcleaner
|
||||
//
|
||||
// Created by Alin Lupascu on 10/31/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
@main
|
||||
struct PearcleanerApp: App {
|
||||
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
||||
@StateObject var appState = AppState()
|
||||
@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
|
||||
@AppStorage("displayMode") var displayMode: DisplayMode = .dark
|
||||
@State private var search = ""
|
||||
|
||||
var body: some Scene {
|
||||
|
||||
WindowGroup {
|
||||
AppListView(search: $search)
|
||||
.environmentObject(appState)
|
||||
.frame(minWidth: 1020, minHeight: 700)
|
||||
.preferredColorScheme(displayMode.colorScheme)
|
||||
.alert(isPresented: $appState.showAlert) { presentAlert(appState: appState) }
|
||||
.handlesExternalEvents(preferring: Set(arrayLiteral: "pear"), allowing: Set(arrayLiteral: "*"))
|
||||
.onAppear {
|
||||
NSWindow.allowsAutomaticWindowTabbing = false
|
||||
|
||||
// Get Apps
|
||||
let sortedApps = getSortedApps()
|
||||
appState.sortedApps.userApps = sortedApps.userApps
|
||||
appState.sortedApps.systemApps = sortedApps.systemApps
|
||||
|
||||
Task {
|
||||
|
||||
#if !DEBUG
|
||||
|
||||
// Make sure App Support folder exists in the future if needed for storage
|
||||
// ensureApplicationSupportFolderExists(appState: appState)
|
||||
|
||||
// Check for updates
|
||||
if diskP && diskE {
|
||||
loadGithubReleases(appState: appState)
|
||||
}
|
||||
|
||||
// Check for disk/accessibility permissions
|
||||
_ = checkAndRequestFullDiskAccess(appState: appState)
|
||||
|
||||
|
||||
// TIMERS ////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Check for app updates every 8 hours or whatever user saved setting. Also refresh autosuggestion list
|
||||
let updateSeconds = updateTimeframe.daysToSeconds
|
||||
_ = Timer.scheduledTimer(withTimeInterval: updateSeconds, repeats: true) { _ in
|
||||
DispatchQueue.main.async {
|
||||
loadGithubReleases(appState: appState)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
.windowStyle(.hiddenTitleBar)
|
||||
.windowToolbarStyle(.unified)
|
||||
.windowResizability(.contentMinSize)
|
||||
.commands {
|
||||
AppCommands(appState: appState)
|
||||
CommandGroup(replacing: .newItem, addition: { })
|
||||
}
|
||||
|
||||
Settings {
|
||||
SettingsView()
|
||||
.environmentObject(appState)
|
||||
.toolbarBackground(.clear)
|
||||
.preferredColorScheme(displayMode.colorScheme)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user