Skip to content

Commit

Permalink
Low Power Mode Alert (#527)
Browse files Browse the repository at this point in the history
* Low Power Mode Alert

* Whitespace

* Revert "Whitespace"

This reverts commit e235094.
  • Loading branch information
IsaacMarovitz committed Dec 5, 2022
1 parent 59e10a1 commit 0eca572
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
31 changes: 27 additions & 4 deletions PlayCover/Views/PlayCoverApp.swift
Expand Up @@ -6,7 +6,6 @@
import SwiftUI

class AppDelegate: NSObject, NSApplicationDelegate {

func application(_ application: NSApplication, open urls: [URL]) {
if let url = urls.first {
if url.pathExtension == "ipa" {
Expand All @@ -25,14 +24,38 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func applicationDidFinishLaunching(_ notification: Notification) {
UserDefaults.standard.register(
defaults: ["NSApplicationCrashOnExceptions": true]
)
UserDefaults.standard.register(
defaults: ["NSApplicationCrashOnExceptions": true]
)
NotificationCenter.default.addObserver(self,
selector: #selector(powerStateChanged),
name: Notification.Name.NSProcessInfoPowerStateDidChange,
object: nil)
if ProcessInfo.processInfo.isLowPowerModeEnabled {
powerModal()
}
}

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}

@objc func powerStateChanged(_ notification: Notification) {
if ProcessInfo.processInfo.isLowPowerModeEnabled {
DispatchQueue.main.async {
self.powerModal()
}
}
}

func powerModal() {
let alert = NSAlert()
alert.messageText = NSLocalizedString("alert.power.title", comment: "")
alert.informativeText = NSLocalizedString("alert.power.subtitle", comment: "")
alert.addButton(withTitle: NSLocalizedString("button.OK", comment: ""))
alert.alertStyle = .critical
alert.runModal()
}
}

@main
Expand Down
2 changes: 2 additions & 0 deletions PlayCover/en.lproj/Localizable.strings
Expand Up @@ -97,6 +97,8 @@
"alert.install.injectPlayToolsQuestion" = "Do you want to inject PlayTools into this application?";
"alert.install.playToolsInformative" = "PlayTools is a tool that allows you to bind keys to screen touches, custom display resolutions, and more, but it may break certain apps";
"alert.supression" = "You can change this in the PlayCover preferences";
"alert.power.title" = "Low Power Mode Enabled!";
"alert.power.subtitle" = "Some apps will not work with Low Power Mode enabled. It is recommended to disable it.";

"button.OK" = "OK";
"button.Proceed" = "Proceed";
Expand Down

0 comments on commit 0eca572

Please sign in to comment.