Skip to content

Commit

Permalink
Fixed always light bug with Electron apps
Browse files Browse the repository at this point in the history
  • Loading branch information
planecore committed Jun 11, 2019
1 parent 5435021 commit 59624fc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 31 deletions.
4 changes: 0 additions & 4 deletions Auto Dark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
908230B021F1FBB600FA2D36 /* LocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 908230AF21F1FBB600FA2D36 /* LocationManager.swift */; };
908230B221F20F6600FA2D36 /* PreferencesController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 908230B121F20F6600FA2D36 /* PreferencesController.swift */; };
90D19C2421F35FF9001C410D /* ScheduleManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90D19C2321F35FF9001C410D /* ScheduleManager.swift */; };
90F5E28122AEA5F200DB92D2 /* GetBundleIDs.scpt in Resources */ = {isa = PBXBuildFile; fileRef = 90F5E28022AEA5F200DB92D2 /* GetBundleIDs.scpt */; };
90F5E28522AEAC1000DB92D2 /* DarkMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90F5E28422AEAC1000DB92D2 /* DarkMode.swift */; };
90F5E28722AEAC4600DB92D2 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90F5E28622AEAC4600DB92D2 /* App.swift */; };
/* End PBXBuildFile section */
Expand All @@ -34,7 +33,6 @@
908230AF21F1FBB600FA2D36 /* LocationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationManager.swift; sourceTree = "<group>"; };
908230B121F20F6600FA2D36 /* PreferencesController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesController.swift; sourceTree = "<group>"; };
90D19C2321F35FF9001C410D /* ScheduleManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScheduleManager.swift; sourceTree = "<group>"; };
90F5E28022AEA5F200DB92D2 /* GetBundleIDs.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = GetBundleIDs.scpt; sourceTree = "<group>"; };
90F5E28422AEAC1000DB92D2 /* DarkMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DarkMode.swift; sourceTree = "<group>"; };
90F5E28622AEAC4600DB92D2 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
90FB494F22022444000D6510 /* LICENSE.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -74,7 +72,6 @@
children = (
905E4A7821A19E2500D1DBC7 /* AppDelegate.swift */,
905E4A7F21A19E2500D1DBC7 /* Info.plist */,
90F5E28022AEA5F200DB92D2 /* GetBundleIDs.scpt */,
905E4A7A21A19E2500D1DBC7 /* Assets.xcassets */,
905E4A7C21A19E2500D1DBC7 /* MainMenu.xib */,
90222E9022018C9D004D183C /* Preferences.storyboard */,
Expand Down Expand Up @@ -155,7 +152,6 @@
905E4A7B21A19E2500D1DBC7 /* Assets.xcassets in Resources */,
905E4A7E21A19E2500D1DBC7 /* MainMenu.xib in Resources */,
90222E9122018C9D004D183C /* Preferences.storyboard in Resources */,
90F5E28122AEA5F200DB92D2 /* GetBundleIDs.scpt in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
7 changes: 0 additions & 7 deletions Auto Dark/GetBundleIDs.scpt

This file was deleted.

2 changes: 1 addition & 1 deletion Auto Dark/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.4</string>
<key>CFBundleVersion</key>
<string>9</string>
<string>10</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
Expand Down
28 changes: 9 additions & 19 deletions Auto Dark/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,22 @@ class ViewController: NSObject, ViewControllerDelegate {
}
}

@discardableResult
func getOpenedApps() -> [App] {
let path = Bundle.main.path(forResource: "GetBundleIDs", ofType: "scpt")!
var outstr = ""
let task = Process()
task.launchPath = "/usr/bin/osascript"
task.arguments = [path]
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
if let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue) {
outstr = (output as String).replacingOccurrences(of: "\n", with: "")
}
task.waitUntilExit()
let running = NSWorkspace.shared.runningApplications.filter({$0.activationPolicy == .regular})
var apps = [App]()
for item in outstr.split(separator: " ").joined().split(separator: ",") {
if item != "com.apple.Safari" && item != "com.apple.mail" {
apps.append(App(bundle: String(item)))
for item in running {
if let bundle = item.bundleIdentifier {
if bundle != "com.apple.Safari" && bundle != "com.apple.mail" {
apps.append(App(bundle: bundle))
}
}
}
return apps
}

func setAlwaysLightMenu() {
alwaysLightMenu.removeAllItems()
let apps = getOpenedApps()
var items = [NSMenuItem]()
for app in apps {
let item = NSMenuItem(title: app.name, action: #selector(self.changeAlwaysLight), keyEquivalent: "")
item.image = app.image
Expand All @@ -154,8 +143,9 @@ class ViewController: NSObject, ViewControllerDelegate {
} else {
item.state = .off
}
alwaysLightMenu.addItem(item)
items.append(item)
}
alwaysLightMenu.items = items
}

@objc func changeAlwaysLight(_ sender: Any) {
Expand Down

0 comments on commit 59624fc

Please sign in to comment.