mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltServer] Shows alert when installing AltStore onto second device
This commit is contained in:
@@ -137,6 +137,10 @@ private extension AppDelegate
|
|||||||
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
||||||
UNUserNotificationCenter.current().add(request)
|
UNUserNotificationCenter.current().add(request)
|
||||||
|
|
||||||
|
case .failure(InstallError.cancelled):
|
||||||
|
// Ignore
|
||||||
|
break
|
||||||
|
|
||||||
case .failure(let error as NSError):
|
case .failure(let error as NSError):
|
||||||
|
|
||||||
let alert = NSAlert()
|
let alert = NSAlert()
|
||||||
|
|||||||
@@ -9,17 +9,17 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
import UserNotifications
|
import UserNotifications
|
||||||
|
|
||||||
enum InstallError: Error
|
enum InstallError: LocalizedError
|
||||||
{
|
{
|
||||||
case invalidCredentials
|
case cancelled
|
||||||
case noTeam
|
case noTeam
|
||||||
case missingPrivateKey
|
case missingPrivateKey
|
||||||
case missingCertificate
|
case missingCertificate
|
||||||
|
|
||||||
var localizedDescription: String {
|
var errorDescription: String? {
|
||||||
switch self
|
switch self
|
||||||
{
|
{
|
||||||
case .invalidCredentials: return "The provided Apple ID and password are incorrect."
|
case .cancelled: return NSLocalizedString("The operation was cancelled.", comment: "")
|
||||||
case .noTeam: return "You are not a member of any developer teams."
|
case .noTeam: return "You are not a member of any developer teams."
|
||||||
case .missingPrivateKey: return "The developer certificate's private key could not be found."
|
case .missingPrivateKey: return "The developer certificate's private key could not be found."
|
||||||
case .missingCertificate: return "The developer certificate could not be found."
|
case .missingCertificate: return "The developer certificate could not be found."
|
||||||
@@ -54,12 +54,6 @@ extension ALTDeviceManager
|
|||||||
{
|
{
|
||||||
let account = try result.get()
|
let account = try result.get()
|
||||||
|
|
||||||
let content = UNMutableNotificationContent()
|
|
||||||
content.title = String(format: NSLocalizedString("Installing AltStore to %@...", comment: ""), device.name)
|
|
||||||
|
|
||||||
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
|
||||||
UNUserNotificationCenter.current().add(request)
|
|
||||||
|
|
||||||
self.fetchTeam(for: account) { (result) in
|
self.fetchTeam(for: account) { (result) in
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -75,6 +69,13 @@ extension ALTDeviceManager
|
|||||||
{
|
{
|
||||||
let certificate = try result.get()
|
let certificate = try result.get()
|
||||||
|
|
||||||
|
let content = UNMutableNotificationContent()
|
||||||
|
content.title = String(format: NSLocalizedString("Installing AltStore to %@...", comment: ""), device.name)
|
||||||
|
content.body = NSLocalizedString("This may take a few seconds.", comment: "")
|
||||||
|
|
||||||
|
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
||||||
|
UNUserNotificationCenter.current().add(request)
|
||||||
|
|
||||||
self.downloadApp { (result) in
|
self.downloadApp { (result) in
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -229,6 +230,34 @@ extension ALTDeviceManager
|
|||||||
{
|
{
|
||||||
let certificates = try Result(certificates, error).get()
|
let certificates = try Result(certificates, error).get()
|
||||||
|
|
||||||
|
// Check if there is another AltStore certificate, which means AltStore has been installed with this Apple ID before.
|
||||||
|
if certificates.contains(where: { $0.machineName?.starts(with: "AltStore") == true })
|
||||||
|
{
|
||||||
|
var isCancelled = false
|
||||||
|
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
let alert = NSAlert()
|
||||||
|
alert.messageText = NSLocalizedString("AltStore already installed on another device.", comment: "")
|
||||||
|
alert.informativeText = NSLocalizedString("Apps installed with AltStore on your other devices will stop working. Are you sure you want to continue?", comment: "")
|
||||||
|
|
||||||
|
alert.addButton(withTitle: NSLocalizedString("Continue", comment: ""))
|
||||||
|
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
|
||||||
|
|
||||||
|
NSRunningApplication.current.activate(options: .activateIgnoringOtherApps)
|
||||||
|
|
||||||
|
let buttonIndex = alert.runModal()
|
||||||
|
if buttonIndex == NSApplication.ModalResponse.alertSecondButtonReturn
|
||||||
|
{
|
||||||
|
isCancelled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if isCancelled
|
||||||
|
{
|
||||||
|
return completionHandler(.failure(InstallError.cancelled))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let certificate = certificates.first
|
if let certificate = certificates.first
|
||||||
{
|
{
|
||||||
ALTAppleAPI.shared.revoke(certificate, for: team) { (success, error) in
|
ALTAppleAPI.shared.revoke(certificate, for: team) { (success, error) in
|
||||||
|
|||||||
2
Dependencies/AltSign
vendored
2
Dependencies/AltSign
vendored
Submodule Dependencies/AltSign updated: 7eb56df5d1...279f6e7b08
Reference in New Issue
Block a user