From 0397db51f727a24693a04cedd41c9d6d9c33fce5 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 10 Nov 2021 11:42:26 -0800 Subject: [PATCH] [AltServer] Hides "Sideload .ipa" menu item by default Manual sideloading is intended to be a fallback for situations where AltStore cannot be used. To emphasize this, we hide the option by default unless the user holds the Option key. --- AltServer/AppDelegate.swift | 27 +++++++++++++++++++++++++++ AltServer/Base.lproj/Main.storyboard | 6 ++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/AltServer/AppDelegate.swift b/AltServer/AppDelegate.swift index 356674bc..cda869a6 100644 --- a/AltServer/AppDelegate.swift +++ b/AltServer/AppDelegate.swift @@ -41,6 +41,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet private var launchAtLoginMenuItem: NSMenuItem! @IBOutlet private var installMailPluginMenuItem: NSMenuItem! + @IBOutlet private var installAltStoreMenuItem: NSMenuItem! + @IBOutlet private var sideloadAppMenuItem: NSMenuItem! private weak var authenticationAppleIDTextField: NSTextField? private weak var authenticationPasswordTextField: NSSecureTextField? @@ -67,6 +69,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { self.appMenu.delegate = self + self.sideloadAppMenuItem.keyEquivalentModifierMask = .option + self.sideloadAppMenuItem.isAlternate = true + let placeholder = NSLocalizedString("No Connected Devices", comment: "") self.connectedDevicesMenuController = MenuController(menu: self.connectedDevicesMenu, items: []) @@ -491,6 +496,28 @@ extension AppDelegate: NSMenuDelegate // Clearing _jitAppListMenuControllers now prevents action handler from being called. // self._jitAppListMenuControllers = [] } + + func menu(_ menu: NSMenu, willHighlight item: NSMenuItem?) + { + guard menu == self.appMenu else { return } + + // The submenu won't update correctly if the user holds/releases + // the Option key while the submenu is visible. + // Workaround: temporarily set submenu to nil to dismiss it, + // which will then cause the correct submenu to appear. + + let previousItem: NSMenuItem + switch item + { + case self.sideloadAppMenuItem: previousItem = self.installAltStoreMenuItem + case self.installAltStoreMenuItem: previousItem = self.sideloadAppMenuItem + default: return + } + + let submenu = previousItem.submenu + previousItem.submenu = nil + previousItem.submenu = submenu + } } extension AppDelegate: NSTextFieldDelegate diff --git a/AltServer/Base.lproj/Main.storyboard b/AltServer/Base.lproj/Main.storyboard index 1c85367a..0916dd2f 100644 --- a/AltServer/Base.lproj/Main.storyboard +++ b/AltServer/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -63,8 +63,10 @@ + +