From ae4e6b5e37e9555a0684eaa697f2799cc772fa0d Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 13 Sep 2023 15:51:50 -0500 Subject: [PATCH] =?UTF-8?q?[AltServer]=20Removes=20=E2=80=9CInstall=20Mail?= =?UTF-8?q?=20Plug-In=E2=80=9D=20menu=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Leaves “Uninstall Mail Plug-In” option to allow users to remove already-installed plug-ins now that they’re not required. --- AltServer/AppDelegate.swift | 68 ++--------------------- AltServer/Base.lproj/Main.storyboard | 17 +++--- AltServer/Plugin/PluginManager.swift | 83 +--------------------------- 3 files changed, 16 insertions(+), 152 deletions(-) diff --git a/AltServer/AppDelegate.swift b/AltServer/AppDelegate.swift index a6ca037f..bd7ec6db 100644 --- a/AltServer/AppDelegate.swift +++ b/AltServer/AppDelegate.swift @@ -109,16 +109,6 @@ class AppDelegate: NSObject, NSApplicationDelegate { UserDefaults.standard.didPresentInitialNotification = true } } - - self.pluginManager.isUpdateAvailable { result in - guard let isUpdateAvailable = try? result.get() else { return } - self.isAltPluginUpdateAvailable = isUpdateAvailable - - if isUpdateAvailable - { - self.installMailPlugin() - } - } } func applicationWillTerminate(_ aNotification: Notification) @@ -332,46 +322,7 @@ private extension AppDelegate LaunchAtLogin.isEnabled.toggle() } - @objc func handleInstallMailPluginMenuItem(_ item: NSMenuItem) - { - if !self.pluginManager.isMailPluginInstalled || self.isAltPluginUpdateAvailable - { - self.installMailPlugin() - } - else - { - self.uninstallMailPlugin() - } - } - - private func installMailPlugin(completion: ((Result) -> Void)? = nil) - { - self.pluginManager.installMailPlugin { (result) in - DispatchQueue.main.async { - switch result - { - case .failure(PluginError.cancelled): break - case .failure(let error): - let alert = NSAlert() - alert.messageText = NSLocalizedString("Failed to Install Mail Plug-in", comment: "") - alert.informativeText = error.localizedDescription - alert.runModal() - - case .success: - let alert = NSAlert() - alert.messageText = NSLocalizedString("Mail Plug-in Installed", comment: "") - alert.informativeText = NSLocalizedString("Please restart Mail and enable AltPlugin in Mail's Preferences. Mail must be running when installing or refreshing apps with AltServer.", comment: "") - alert.runModal() - - self.isAltPluginUpdateAvailable = false - } - - completion?(result) - } - } - } - - private func uninstallMailPlugin() + @IBAction private func uninstallMailPlugin(_ sender: NSMenuItem) { self.pluginManager.uninstallMailPlugin { (result) in DispatchQueue.main.async { @@ -387,7 +338,7 @@ private extension AppDelegate case .success: let alert = NSAlert() alert.messageText = NSLocalizedString("Mail Plug-in Uninstalled", comment: "") - alert.informativeText = NSLocalizedString("Please restart Mail for changes to take effect. You will not be able to use AltServer until the plug-in is reinstalled.", comment: "") + alert.informativeText = NSLocalizedString("Please restart Mail for changes to take effect.", comment: "") alert.runModal() } } @@ -414,20 +365,11 @@ extension AppDelegate: NSMenuDelegate self.launchAtLoginMenuItem.action = #selector(AppDelegate.toggleLaunchAtLogin(_:)) self.launchAtLoginMenuItem.state = LaunchAtLogin.isEnabled ? .on : .off - if self.isAltPluginUpdateAvailable + if !self.pluginManager.isMailPluginInstalled { - self.installMailPluginMenuItem.title = NSLocalizedString("Update Mail Plug-in…", comment: "") + // Hide "Install Mail Plug-In" option now that it's not required. + self.installMailPluginMenuItem.isHidden = true } - else if self.pluginManager.isMailPluginInstalled - { - self.installMailPluginMenuItem.title = NSLocalizedString("Uninstall Mail Plug-in…", comment: "") - } - else - { - self.installMailPluginMenuItem.title = NSLocalizedString("Install Mail Plug-in…", comment: "") - } - self.installMailPluginMenuItem.target = self - self.installMailPluginMenuItem.action = #selector(AppDelegate.handleInstallMailPluginMenuItem(_:)) // Need to re-set this every time menu appears so we can refresh device app list. self.enableJITMenuController.submenuHandler = { [weak self] device in diff --git a/AltServer/Base.lproj/Main.storyboard b/AltServer/Base.lproj/Main.storyboard index 71f5b70e..95a13dd8 100644 --- a/AltServer/Base.lproj/Main.storyboard +++ b/AltServer/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -14,7 +14,7 @@ - + @@ -26,7 +26,7 @@ - + @@ -125,8 +125,11 @@ - + + + + @@ -395,7 +398,7 @@ - + @@ -403,7 +406,7 @@ - + diff --git a/AltServer/Plugin/PluginManager.swift b/AltServer/Plugin/PluginManager.swift index ddb8b97a..9aefce4f 100644 --- a/AltServer/Plugin/PluginManager.swift +++ b/AltServer/Plugin/PluginManager.swift @@ -149,92 +149,11 @@ class PluginManager extension PluginManager { - func installMailPlugin(completionHandler: @escaping (Result) -> Void) - { - self.isUpdateAvailable(useCache: true) { result in - DispatchQueue.main.async { - do - { - let isUpdateAvailable = try result.get() - - let alert = NSAlert() - if isUpdateAvailable - { - alert.messageText = NSLocalizedString("Update Mail Plug-in", comment: "") - alert.informativeText = NSLocalizedString("An update is available for AltServer's Mail plug-in. Please update the plug-in now in order to keep using AltStore.", comment: "") - - alert.addButton(withTitle: NSLocalizedString("Update Plug-in", comment: "")) - alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "")) - } - else - { - alert.messageText = NSLocalizedString("Install Mail Plug-in", comment: "") - alert.informativeText = NSLocalizedString("AltServer requires a Mail plug-in in order to retrieve necessary information about your Apple ID. Would you like to install it now?", comment: "") - - alert.addButton(withTitle: NSLocalizedString("Install Plug-in", comment: "")) - alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "")) - } - - NSRunningApplication.current.activate(options: .activateIgnoringOtherApps) - - let response = alert.runModal() - guard response == .alertFirstButtonReturn else { throw PluginError.cancelled } - - self.downloadPlugin { (result) in - do - { - let fileURL = try result.get() - - // Ensure plug-in directory exists. - let authorization = try self.runAndKeepAuthorization("mkdir", arguments: ["-p", pluginDirectoryURL.path]) - - // Create temporary directory. - let temporaryDirectoryURL = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) - try FileManager.default.createDirectory(at: temporaryDirectoryURL, withIntermediateDirectories: true, attributes: nil) - defer { try? FileManager.default.removeItem(at: temporaryDirectoryURL) } - - // Unzip AltPlugin to temporary directory. - try self.runAndKeepAuthorization("unzip", arguments: ["-o", fileURL.path, "-d", temporaryDirectoryURL.path], authorization: authorization) - - if FileManager.default.fileExists(atPath: pluginURL.path) - { - // Delete existing Mail plug-in. - try self.runAndKeepAuthorization("rm", arguments: ["-rf", pluginURL.path], authorization: authorization) - } - - // Copy AltPlugin to Mail plug-ins directory. - // Must be separate step than unzip to prevent macOS from considering plug-in corrupted. - let unzippedPluginURL = temporaryDirectoryURL.appendingPathComponent(pluginURL.lastPathComponent) - try self.runAndKeepAuthorization("cp", arguments: ["-R", unzippedPluginURL.path, pluginDirectoryURL.path], authorization: authorization) - - guard self.isMailPluginInstalled else { throw PluginError.unknown() } - - // Enable Mail plug-in preferences. - try self.run("defaults", arguments: ["write", "/Library/Preferences/com.apple.mail", "EnableBundles", "-bool", "YES"], authorization: authorization) - - print("Finished installing Mail plug-in!") - - completionHandler(.success(())) - } - catch - { - completionHandler(.failure(error)) - } - } - } - catch - { - completionHandler(.failure(error)) - } - } - } - } - func uninstallMailPlugin(completionHandler: @escaping (Result) -> Void) { let alert = NSAlert() alert.messageText = NSLocalizedString("Uninstall Mail Plug-in", comment: "") - alert.informativeText = NSLocalizedString("Are you sure you want to uninstall the AltServer Mail plug-in? You will no longer be able to install or refresh apps with AltStore.", comment: "") + alert.informativeText = NSLocalizedString("Are you sure you want to uninstall the AltServer Mail plug-in?", comment: "") alert.addButton(withTitle: NSLocalizedString("Uninstall Plug-in", comment: "")) alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))