mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-17 02:33:27 +01:00
Lists connected devices
This commit is contained in:
21
AltServer/ALTDeviceManager.h
Normal file
21
AltServer/ALTDeviceManager.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// ALTDeviceManager.h
|
||||
// AltServer
|
||||
//
|
||||
// Created by Riley Testut on 5/24/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
#import <AltSign/AltSign.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface ALTDeviceManager : NSObject
|
||||
|
||||
@property (class, nonatomic, readonly) ALTDeviceManager *sharedManager;
|
||||
|
||||
@property (nonatomic, readonly) NSArray<ALTDevice *> *connectedDevices;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
96
AltServer/ALTDeviceManager.mm
Normal file
96
AltServer/ALTDeviceManager.mm
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// ALTDeviceManager.m
|
||||
// AltServer
|
||||
//
|
||||
// Created by Riley Testut on 5/24/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ALTDeviceManager.h"
|
||||
|
||||
#include <libimobiledevice/libimobiledevice.h>
|
||||
#include <libimobiledevice/lockdown.h>
|
||||
|
||||
@implementation ALTDeviceManager
|
||||
|
||||
+ (ALTDeviceManager *)sharedManager
|
||||
{
|
||||
static ALTDeviceManager *_manager = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_manager = [[self alloc] init];
|
||||
});
|
||||
|
||||
return _manager;
|
||||
}
|
||||
|
||||
#pragma mark - Getters -
|
||||
|
||||
- (NSArray<ALTDevice *> *)connectedDevices
|
||||
{
|
||||
int count = 0;
|
||||
char **udids = NULL;
|
||||
|
||||
if (idevice_get_device_list(&udids, &count) < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Unable to retrieve device list!\n");
|
||||
return @[];
|
||||
}
|
||||
|
||||
NSMutableArray *connectedDevices = [NSMutableArray array];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
char *udid = udids[i];
|
||||
|
||||
idevice_t device = NULL;
|
||||
idevice_new(&device, udid);
|
||||
|
||||
if (!device)
|
||||
{
|
||||
fprintf(stderr, "ERROR: No device with UDID %s attached.\n", udid);
|
||||
continue;
|
||||
}
|
||||
|
||||
lockdownd_client_t client = NULL;
|
||||
if (lockdownd_client_new(device, &client, "altserver") != LOCKDOWN_E_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Connecting to device failed!\n");
|
||||
|
||||
idevice_free(device);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
char *device_name = NULL;
|
||||
if (lockdownd_get_device_name(client, &device_name) != LOCKDOWN_E_SUCCESS || device_name == NULL)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Could not get device name!\n");
|
||||
|
||||
lockdownd_client_free(client);
|
||||
idevice_free(device);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
lockdownd_client_free(client);
|
||||
idevice_free(device);
|
||||
|
||||
NSString *name = [NSString stringWithCString:device_name encoding:NSUTF8StringEncoding];
|
||||
NSString *identifier = [NSString stringWithCString:udid encoding:NSUTF8StringEncoding];
|
||||
|
||||
ALTDevice *altDevice = [[ALTDevice alloc] initWithName:name identifier:identifier];
|
||||
[connectedDevices addObject:altDevice];
|
||||
|
||||
if (device_name != NULL)
|
||||
{
|
||||
free(device_name);
|
||||
}
|
||||
}
|
||||
|
||||
idevice_device_list_free(udids);
|
||||
|
||||
return connectedDevices;
|
||||
}
|
||||
|
||||
@end
|
||||
5
AltServer/AltServer-Bridging-Header.h
Normal file
5
AltServer/AltServer-Bridging-Header.h
Normal file
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
||||
#import "ALTDeviceManager.h"
|
||||
@@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11134" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11134"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Application-->
|
||||
@@ -673,7 +674,7 @@
|
||||
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
|
||||
</connections>
|
||||
</application>
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModuleProvider="target"/>
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="AltServer" customModuleProvider="target"/>
|
||||
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
||||
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
@@ -703,10 +704,26 @@
|
||||
<!--View Controller-->
|
||||
<scene sceneID="hIz-AP-VOD">
|
||||
<objects>
|
||||
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModule="AltServer" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" id="m2S-Jp-Qdl">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Lkz-Gl-wBp">
|
||||
<rect key="frame" x="148" y="118" width="184" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="List Connected Devices" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="MKD-1Q-nZx">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="listConnectedDevices:" target="XfG-lQ-9wD" id="zmE-CS-Q4o"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="Lkz-Gl-wBp" firstAttribute="centerY" secondItem="m2S-Jp-Qdl" secondAttribute="centerY" id="2ik-iR-0j4"/>
|
||||
<constraint firstItem="Lkz-Gl-wBp" firstAttribute="centerX" secondItem="m2S-Jp-Qdl" secondAttribute="centerX" id="oPG-tb-YM0"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</viewController>
|
||||
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
|
||||
@@ -10,18 +10,17 @@ import Cocoa
|
||||
|
||||
class ViewController: NSViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
override func viewDidLoad()
|
||||
{
|
||||
super.viewDidLoad()
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
}
|
||||
|
||||
override var representedObject: Any? {
|
||||
didSet {
|
||||
// Update the view, if already loaded.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension ViewController
|
||||
{
|
||||
@IBAction func listConnectedDevices(_ sender: NSButton)
|
||||
{
|
||||
let devices = ALTDeviceManager.shared.connectedDevices
|
||||
print(devices)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user