Skip to content

Commit

Permalink
Finished Adding #44
Browse files Browse the repository at this point in the history
  • Loading branch information
CodySchrank committed Apr 5, 2020
1 parent 37c1ad5 commit 03ed284
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 126 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ At this time it seems like gSwitch will not work on macbooks older than 2011. It
## Notes

Requires macOS >= 10.12

gSwitch provided “as is” without warranty of any kind, either expressed or implied and such software is to be used at your own risk.
42 changes: 8 additions & 34 deletions gSwitch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@
82233ED820844ADF006C57E7 /* ProcessManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82233ED120844ADF006C57E7 /* ProcessManager.swift */; };
82360C722088361700ADD0CE /* PreferencesWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82360C702088361700ADD0CE /* PreferencesWindow.swift */; };
823960BE228949BC0014D7CD /* LaunchAtLogin.framework.dSYM in Resources */ = {isa = PBXBuildFile; fileRef = 823960BD228949BC0014D7CD /* LaunchAtLogin.framework.dSYM */; };
823960C422894B000014D7CD /* org.sparkle-project.Downloader.xpc in Resources */ = {isa = PBXBuildFile; fileRef = 823960C322894B000014D7CD /* org.sparkle-project.Downloader.xpc */; };
823960C622894B0A0014D7CD /* org.sparkle-project.InstallerConnection.xpc in Resources */ = {isa = PBXBuildFile; fileRef = 823960C522894B0A0014D7CD /* org.sparkle-project.InstallerConnection.xpc */; };
823960C822894B120014D7CD /* org.sparkle-project.InstallerLauncher.xpc in Resources */ = {isa = PBXBuildFile; fileRef = 823960C722894B120014D7CD /* org.sparkle-project.InstallerLauncher.xpc */; };
823960CA22894B180014D7CD /* org.sparkle-project.InstallerStatus.xpc in Resources */ = {isa = PBXBuildFile; fileRef = 823960C922894B180014D7CD /* org.sparkle-project.InstallerStatus.xpc */; };
823960CB22894B240014D7CD /* org.sparkle-project.InstallerStatus.xpc in CopyFiles */ = {isa = PBXBuildFile; fileRef = 823960C922894B180014D7CD /* org.sparkle-project.InstallerStatus.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
823960CC22894B2D0014D7CD /* org.sparkle-project.InstallerLauncher.xpc in CopyFiles */ = {isa = PBXBuildFile; fileRef = 823960C722894B120014D7CD /* org.sparkle-project.InstallerLauncher.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
823960CD22894B310014D7CD /* org.sparkle-project.InstallerConnection.xpc in CopyFiles */ = {isa = PBXBuildFile; fileRef = 823960C522894B0A0014D7CD /* org.sparkle-project.InstallerConnection.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
823960CE22894B350014D7CD /* org.sparkle-project.Downloader.xpc in CopyFiles */ = {isa = PBXBuildFile; fileRef = 823960C322894B000014D7CD /* org.sparkle-project.Downloader.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
823960D122894B820014D7CD /* LaunchAtLogin.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 823960D022894B820014D7CD /* LaunchAtLogin.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
823B274E208C0A2900A7DFB6 /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 823B274D208C0A2900A7DFB6 /* dsa_pub.pem */; };
82556518208C505900A6807F /* UpdaterDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82556517208C505900A6807F /* UpdaterDelegate.swift */; };
Expand Down Expand Up @@ -76,10 +68,6 @@
dstPath = "$(CONTENTS_FOLDER_PATH)/XPCServices";
dstSubfolderSpec = 16;
files = (
823960CE22894B350014D7CD /* org.sparkle-project.Downloader.xpc in CopyFiles */,
823960CD22894B310014D7CD /* org.sparkle-project.InstallerConnection.xpc in CopyFiles */,
823960CC22894B2D0014D7CD /* org.sparkle-project.InstallerLauncher.xpc in CopyFiles */,
823960CB22894B240014D7CD /* org.sparkle-project.InstallerStatus.xpc in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -141,10 +129,6 @@
82233ED120844ADF006C57E7 /* ProcessManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProcessManager.swift; sourceTree = "<group>"; };
82360C702088361700ADD0CE /* PreferencesWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindow.swift; sourceTree = "<group>"; };
823960BD228949BC0014D7CD /* LaunchAtLogin.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = LaunchAtLogin.framework.dSYM; path = Carthage/Build/Mac/LaunchAtLogin.framework.dSYM; sourceTree = "<group>"; };
823960C322894B000014D7CD /* org.sparkle-project.Downloader.xpc */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.xpc-service"; path = "org.sparkle-project.Downloader.xpc"; sourceTree = "<group>"; };
823960C522894B0A0014D7CD /* org.sparkle-project.InstallerConnection.xpc */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.xpc-service"; path = "org.sparkle-project.InstallerConnection.xpc"; sourceTree = "<group>"; };
823960C722894B120014D7CD /* org.sparkle-project.InstallerLauncher.xpc */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.xpc-service"; path = "org.sparkle-project.InstallerLauncher.xpc"; sourceTree = "<group>"; };
823960C922894B180014D7CD /* org.sparkle-project.InstallerStatus.xpc */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.xpc-service"; path = "org.sparkle-project.InstallerStatus.xpc"; sourceTree = "<group>"; };
823960D022894B820014D7CD /* LaunchAtLogin.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LaunchAtLogin.framework; path = Carthage/Build/Mac/LaunchAtLogin.framework; sourceTree = "<group>"; };
823B274D208C0A2900A7DFB6 /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsa_pub.pem; sourceTree = "<group>"; };
82556517208C505900A6807F /* UpdaterDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdaterDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -207,7 +191,6 @@
82233E9420844AC9006C57E7 = {
isa = PBXGroup;
children = (
823960BA228949140014D7CD /* XPC */,
82233E9F20844AC9006C57E7 /* gSwitch */,
82233EB020844ACA006C57E7 /* gSwitchTests */,
82233EBB20844ACA006C57E7 /* gSwitchUITests */,
Expand Down Expand Up @@ -355,17 +338,6 @@
name = Frameworks;
sourceTree = "<group>";
};
823960BA228949140014D7CD /* XPC */ = {
isa = PBXGroup;
children = (
823960C922894B180014D7CD /* org.sparkle-project.InstallerStatus.xpc */,
823960C722894B120014D7CD /* org.sparkle-project.InstallerLauncher.xpc */,
823960C522894B0A0014D7CD /* org.sparkle-project.InstallerConnection.xpc */,
823960C322894B000014D7CD /* org.sparkle-project.Downloader.xpc */,
);
path = XPC;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -493,15 +465,11 @@
823B274E208C0A2900A7DFB6 /* dsa_pub.pem in Resources */,
828D681320C897D200A41DD9 /* AdvancedWindow.xib in Resources */,
828D681920C8BCFF00A41DD9 /* HelpWindow.xib in Resources */,
823960C822894B120014D7CD /* org.sparkle-project.InstallerLauncher.xpc in Resources */,
823960C622894B0A0014D7CD /* org.sparkle-project.InstallerConnection.xpc in Resources */,
823960C422894B000014D7CD /* org.sparkle-project.Downloader.xpc in Resources */,
82233EA320844ACA006C57E7 /* Assets.xcassets in Resources */,
AA20D30820EC2D6B009862FB /* PreferencesWindow.xib in Resources */,
82233EA620844ACA006C57E7 /* MainMenu.xib in Resources */,
AAC7195520E2D04E009862FB /* AboutWindow.xib in Resources */,
82556532208C5B9300A6807F /* Sparkle.framework.dSYM in Resources */,
823960CA22894B180014D7CD /* org.sparkle-project.InstallerStatus.xpc in Resources */,
829553CB20884F4700A29C49 /* SwiftyBeaver.framework.dSYM in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -641,6 +609,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
Expand Down Expand Up @@ -702,6 +671,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
Expand Down Expand Up @@ -758,9 +728,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = gSwitch/gSwitch.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.9.6;
DEVELOPMENT_TEAM = Z26D67C784;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -774,6 +745,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.9.6;
PRODUCT_BUNDLE_IDENTIFIER = com.CodySchrank.gSwitch;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "gSwitch/gSwitch-Bridging-Header.h";
Expand All @@ -788,9 +760,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = gSwitch/gSwitch.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.9.6;
DEVELOPMENT_TEAM = Z26D67C784;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -804,6 +777,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.9.6;
PRODUCT_BUNDLE_IDENTIFIER = com.CodySchrank.gSwitch;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "gSwitch/gSwitch-Bridging-Header.h";
Expand Down
28 changes: 20 additions & 8 deletions gSwitch/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

/** Default prefs so shit works */
UserDefaults.standard.register(defaults: [Constants.GPU_CHANGE_NOTIFICATIONS : false])
UserDefaults.standard.register(defaults: [Constants.LAUNCH_AT_LOGIN : true])
UserDefaults.standard.register(defaults: [Constants.USE_LAST_STATE: true])
UserDefaults.standard.register(defaults: [Constants.SAVED_GPU_STATE: SwitcherMode.SetDynamic.rawValue])
setupDefaultPreferences()

/** Startup AutoLauncher */
LaunchAtLogin.isEnabled = (UserDefaults.standard.integer(forKey: Constants.LAUNCH_AT_LOGIN) == 1)
Expand Down Expand Up @@ -184,22 +181,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {
Check for hungry processes because it could cause a crash
*/
let hungryProcesses = processer.getHungryProcesses()
if(hungryProcesses.count > 0) {
if(hungryProcesses.count > 0 && UserDefaults.standard.integer(forKey: Constants.IGNORE_IGPU_CHANGE_WARNING) == 0) {
log.warning("SHOW: Can't switch to integrated only, because of \(String(describing: hungryProcesses))")

let alert = NSAlert.init()

alert.messageText = "Warning! Are you sure you want to change to integrated only?"
alert.informativeText = "You currently have GPU dependencies. Changing the mode now could cause these processes to crash. If there is currently an external display plugged in you cannot change to integrated only."

alert.addButton(withTitle: "Do it anyway").setAccessibilityFocused(true)

alert.addButton(withTitle: "Override Once").setAccessibilityFocused(true)
alert.addButton(withTitle: "Always Override")
alert.addButton(withTitle: "Never mind")

let modalResult = alert.runModal()

switch modalResult {
case .alertFirstButtonReturn:
log.info("Override clicked!")
log.info("Override once clicked!")
unsafeIntegratedOnly();
case .alertSecondButtonReturn:
log.info("Override always clicked!")
UserDefaults.standard.set(1, forKey: Constants.IGNORE_IGPU_CHANGE_WARNING)
unsafeIntegratedOnly();
default:
break;
Expand All @@ -226,6 +228,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {

unsafeDynamicSwitching()
}

public func setupDefaultPreferences() {
UserDefaults.standard.register(defaults: [Constants.LAUNCH_AT_LOGIN : true])
UserDefaults.standard.register(defaults: [Constants.USE_LAST_STATE: true])
UserDefaults.standard.register(defaults: [Constants.IGNORE_IGPU_CHANGE_WARNING: false])
UserDefaults.standard.register(defaults: [Constants.GPU_CHANGE_NOTIFICATIONS : false])
UserDefaults.standard.register(defaults: [Constants.SAVED_GPU_STATE: SwitcherMode.SetDynamic.rawValue])
}

public func checkForUpdates() {
updater?.checkForUpdates()
Expand Down Expand Up @@ -262,6 +272,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {

log.verbose("Use Last State set as \(UserDefaults.standard.integer(forKey: Constants.USE_LAST_STATE) == 1)")

log.verbose("Ignore IGPU Warning set as \(UserDefaults.standard.integer(forKey: Constants.IGNORE_IGPU_CHANGE_WARNING) == 1)")

log.verbose("Saved GPU State set as \(UserDefaults.standard.integer(forKey: Constants.SAVED_GPU_STATE)) (\(SwitcherMode(rawValue: UserDefaults.standard.integer(forKey: Constants.SAVED_GPU_STATE))!))")
}

Expand Down
5 changes: 1 addition & 4 deletions gSwitch/Core/GPUListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ class GPUListener {

if Int(flags.rawValue) & Constants.kCGDisplayRemoveFlag > 0 {
/**
usually gets called when switched. If I could get a flag that only triggered
when the display was disconnected I could save the last desired state that
the user selected and put them back on it.
(because dynamic is forced when a display is connected)
usually gets called when switched.
*/
}
}
Expand Down
4 changes: 2 additions & 2 deletions gSwitch/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.9.5</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1.9.5</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
1 change: 1 addition & 0 deletions gSwitch/Util/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct Constants {
static let LAUNCH_AT_LOGIN = "appLoginStart"
static let USE_LAST_STATE = "useLastState"
static let SAVED_GPU_STATE = "savedGPUState"
static let IGNORE_IGPU_CHANGE_WARNING = "ignoreIGPUChangeWarning"
static let STATUS_MENU_DEPENDENCY_APPEND_INDEX = 5
static let STATUS_MENU_DEPENDENCY_TAG = 10
static let HELP_URL = "https://codyschrank.github.io/gSwitch/#faq"
Expand Down
Loading

0 comments on commit 03ed284

Please sign in to comment.