Skip to content

Commit

Permalink
Refactor, use BatFiKit in the app and the helper tool
Browse files Browse the repository at this point in the history
  • Loading branch information
rurza committed May 2, 2023
1 parent 13c521d commit 0fe237f
Show file tree
Hide file tree
Showing 42 changed files with 808 additions and 894 deletions.
16 changes: 0 additions & 16 deletions App/Assets.xcassets/charge.20.imageset/Contents.json

This file was deleted.

Binary file removed App/Assets.xcassets/charge.20.imageset/charge.20.pdf
Binary file not shown.
62 changes: 3 additions & 59 deletions App/BatFiApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
// Created by Adam on 11/04/2023.
//

import Combine
import MenuBuilder
import os
import SecureXPC
import App
import SwiftUI

@main
struct BatFiApp: App {
@State private var chargingDisabled = false
@NSApplicationDelegateAdaptor private var appDelegate: AppDelegate

var body: some Scene {
Expand All @@ -22,61 +18,9 @@ struct BatFiApp: App {
}

final class AppDelegate: NSObject, NSApplicationDelegate {
lazy var statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
private lazy var client: XPCClient = makeClient()
lazy var serviceRegisterer = HelperManager()
private let batteryLevelObserver = BatteryLevelObserver.shared
private var charging: Charging!
private var timer: Timer?

lazy var logger = Logger(category: "💻")

func applicationWillFinishLaunching(_ notification: Notification) {

}
lazy var app = BatFi()

func applicationDidFinishLaunching(_ notification: Notification) {
try? serviceRegisterer.registerServiceIfNeeded()
charging = Charging(client: client)

statusItem.button?.image = NSImage(named: "charge.20")
statusItem.menu = NSMenu {
MenuItem("").view {
BatteryInfoView(batteryLevelObserver: batteryLevelObserver)
}
SeparatorItem()
MenuItem("Install Daemon").onSelect { [weak self] in
guard let self = self else { return }
try? self.serviceRegisterer.registerService()
}
MenuItem("Remove Daemon").onSelect { [weak self] in
guard let self = self else { return }
try? self.serviceRegisterer.removeService()
}
SeparatorItem()
MenuItem("Turn off charging").onSelect { [weak self] in
Task {
guard let self = self else { return }
try await self.charging.turnOffCharging()
}
}
MenuItem("Turn on charging").onSelect { [weak self] in
Task {
guard let self = self else { return }
try await self.charging.autoChargingMode()
}
}
SeparatorItem()
MenuItem("Quit BatFi")
.onSelect(target: NSApp, action: #selector(NSApp.terminate(_:)))
.shortcut("q")
}
}

func makeClient() -> XPCClient {
return XPCClient.forMachService(
named: helperBundleIdentifier,
withServerRequirement: try! .sameTeamIdentifier
)
app.start()
}
}
59 changes: 0 additions & 59 deletions App/BatteryInfoView.swift

This file was deleted.

86 changes: 0 additions & 86 deletions App/BatteryLevelObserver.swift

This file was deleted.

110 changes: 0 additions & 110 deletions App/Charging.swift

This file was deleted.

20 changes: 0 additions & 20 deletions App/SettingsView.swift

This file was deleted.

Loading

0 comments on commit 0fe237f

Please sign in to comment.