Skip to content

Commit

Permalink
- add erase all simulators menu
Browse files Browse the repository at this point in the history
  • Loading branch information
savvycom-copilot committed Oct 12, 2014
1 parent 3408150 commit c52fc70
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 32 deletions.
8 changes: 6 additions & 2 deletions SimulatorManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
0ADB3B13178F3DE4004E9BB9 /* LaunchAtLoginController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ADB3B12178F3DE4004E9BB9 /* LaunchAtLoginController.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
8155085C19E6081600C99832 /* RecentAppsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8155085B19E6081600C99832 /* RecentAppsManager.m */; };
81AC54BE19EA10AD004C2C3C /* SimulatorErase.sh in Resources */ = {isa = PBXBuildFile; fileRef = 81AC54BD19EA10AD004C2C3C /* SimulatorErase.sh */; };
81D6BB7519C40261006974D1 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 81D6BB7419C40261006974D1 /* Images.xcassets */; };
81D6BB7819C4062E006974D1 /* Simulator.m in Sources */ = {isa = PBXBuildFile; fileRef = 81D6BB7719C4062E006974D1 /* Simulator.m */; };
81D6BB7B19C414BD006974D1 /* SimulatorApp.m in Sources */ = {isa = PBXBuildFile; fileRef = 81D6BB7A19C414BD006974D1 /* SimulatorApp.m */; };
Expand All @@ -25,6 +26,7 @@
0ADB3B12178F3DE4004E9BB9 /* LaunchAtLoginController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LaunchAtLoginController.m; sourceTree = "<group>"; };
8155085A19E6081600C99832 /* RecentAppsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RecentAppsManager.h; sourceTree = "<group>"; };
8155085B19E6081600C99832 /* RecentAppsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RecentAppsManager.m; sourceTree = "<group>"; };
81AC54BD19EA10AD004C2C3C /* SimulatorErase.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = SimulatorErase.sh; sourceTree = "<group>"; };
81D6BB7419C40261006974D1 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
81D6BB7619C4062E006974D1 /* Simulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Simulator.h; sourceTree = "<group>"; };
81D6BB7719C4062E006974D1 /* Simulator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Simulator.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -129,6 +131,7 @@
C149EC0915D5214600B1F558 /* main.m */,
C149EC0B15D5214600B1F558 /* SimulatorManager-Prefix.pch */,
C149EC0C15D5214600B1F558 /* Credits.rtf */,
81AC54BD19EA10AD004C2C3C /* SimulatorErase.sh */,
);
name = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -186,6 +189,7 @@
files = (
81D6BB7519C40261006974D1 /* Images.xcassets in Resources */,
C149EC0815D5214600B1F558 /* InfoPlist.strings in Resources */,
81AC54BE19EA10AD004C2C3C /* SimulatorErase.sh in Resources */,
C149EC0E15D5214600B1F558 /* Credits.rtf in Resources */,
C149EC1415D5214600B1F558 /* MainMenu.xib in Resources */,
);
Expand Down Expand Up @@ -294,7 +298,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SimulatorManager/SimulatorManager-Prefix.pch";
INFOPLIST_FILE = "SimulatorManager/SimulatorManager-Info.plist";
MACOSX_DEPLOYMENT_TARGET = 10.7;
MACOSX_DEPLOYMENT_TARGET = 10.8;
PRODUCT_NAME = SimulatorManager;
WRAPPER_EXTENSION = app;
};
Expand All @@ -310,7 +314,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SimulatorManager/SimulatorManager-Prefix.pch";
INFOPLIST_FILE = "SimulatorManager/SimulatorManager-Info.plist";
MACOSX_DEPLOYMENT_TARGET = 10.7;
MACOSX_DEPLOYMENT_TARGET = 10.8;
PRODUCT_NAME = SimulatorManager;
WRAPPER_EXTENSION = app;
};
Expand Down
53 changes: 51 additions & 2 deletions SimulatorManager/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@
#import "AppDelegate.h"
#import "Simulator.h"
#import "RecentAppsManager.h"
@interface AppDelegate()
@interface AppDelegate()<NSUserNotificationCenterDelegate>

@property (nonatomic, strong) NSMutableArray *simulators;
@property (weak) IBOutlet NSMenuItem *launchAtLoginMenuItem;
@property (nonatomic, strong) NSDate *lastModDate;
@property (nonatomic, strong) RecentAppsManager *recentManager;
@property (assign, nonatomic) BOOL recentAppUpdate;
@property (weak) IBOutlet NSMenuItem *eraseMenuItem;

@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
}

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification{
return YES;
}

- (NSString *)simulatorDevicesDirectory {
NSArray *array = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
Expand Down Expand Up @@ -63,7 +73,7 @@ - (void)menuWillOpen:(NSMenu *)menu {
- (void) loadMenu {
// Clear out the hosts so we can start over
NSUInteger n = [[menu itemArray] count];
for (int i=0;i<n-4;i++) {
for (int i=0;i<n-6;i++) {
[menu removeItemAtIndex:0];
}

Expand Down Expand Up @@ -197,6 +207,45 @@ - (void)openSimulatorDataFolder:(NSMenuItem *)menuItem {
Simulator *simulator = menuItem.representedObject;
[[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:[simulator appDataPath:nil]]];
}
- (IBAction)eraseAllSimulators:(id)sender {
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = @"Are you sure you want to reset content and settings from all iOS Simulators?";
alert.informativeText = @"All installed applications, content, and settings will be erased.\n\nPlease quit running Simulator before continue.";

alert.alertStyle = NSWarningAlertStyle;

[alert addButtonWithTitle:@"Reset"];
[alert addButtonWithTitle:@"Don't Reset"];

NSInteger result = [alert runModal];
if (result == NSAlertFirstButtonReturn) {
[self performEraseSimulators];
}
}
- (void)performEraseSimulators {
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = @"Simulator Manager";
notification.informativeText = @"Erasing Simulator...";
[self.eraseMenuItem setEnabled:NO];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *commandPath = [[NSBundle mainBundle] pathForResource:@"SimulatorErase" ofType:@"sh"];

for (Simulator *simulator in self.simulators) {
NSTask *eraseTask = [[NSTask alloc] init];
[eraseTask setLaunchPath:commandPath];
[eraseTask setArguments:@[simulator.UDID]];
[eraseTask launch];
[eraseTask waitUntilExit];
}
dispatch_async(dispatch_get_main_queue(), ^{
notification.informativeText = @"All Simulators are erased";
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
[self.eraseMenuItem setEnabled:YES];
});
});
}

- (IBAction)launchAtLogin:(id)sender {
NSMenuItem *menuItem = sender;
if (menuItem.state == NSOffState) menuItem.state = NSOnState;
Expand Down
15 changes: 15 additions & 0 deletions SimulatorManager/SimulatorErase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

# Simulator.command
# SimulatorManager
#
# Created by Tue Nguyen on 10/12/14.
# Copyright (c) 2014 Pharaoh. All rights reserved.

XCODE_PATH=`xcode-select -p`

echo $XCODE_PATH

#cd "$XCODE_PATH/usr/bin"

$XCODE_PATH/usr/bin/simctl erase "${1}"
4 changes: 2 additions & 2 deletions SimulatorManager/SimulatorManager-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1</string>
<string>1.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.1</string>
<string>5</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
99 changes: 73 additions & 26 deletions SimulatorManager/en.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1070</int>
<string key="IBDocument.SystemVersion">14A343f</string>
<int key="IBDocument.SystemTarget">1080</int>
<string key="IBDocument.SystemVersion">14A388a</string>
<string key="IBDocument.InterfaceBuilderVersion">6245</string>
<string key="IBDocument.AppKitVersion">1334</string>
<string key="IBDocument.HIToolboxVersion">751.00</string>
<string key="IBDocument.AppKitVersion">1343.14</string>
<string key="IBDocument.HIToolboxVersion">755.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="NS.object.0">6245</string>
Expand Down Expand Up @@ -99,6 +99,24 @@
<object class="NSMenu" id="862705665">
<string key="NSTitle"/>
<array class="NSMutableArray" key="NSMenuItems">
<object class="NSMenuItem" id="1064529420">
<reference key="NSMenu" ref="862705665"/>
<bool key="NSIsDisabled">YES</bool>
<bool key="NSIsSeparator">YES</bool>
<string key="NSTitle"/>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
<object class="NSMenuItem" id="796561994">
<reference key="NSMenu" ref="862705665"/>
<string key="NSTitle">Erase All Simulators</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
<object class="NSMenuItem" id="1029632860">
<reference key="NSMenu" ref="862705665"/>
<bool key="NSIsDisabled">YES</bool>
Expand Down Expand Up @@ -197,6 +215,14 @@
</object>
<int key="connectionID">659</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">eraseAllSimulators:</string>
<reference key="source" ref="1014"/>
<reference key="destination" ref="796561994"/>
</object>
<int key="connectionID">663</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">menu</string>
Expand Down Expand Up @@ -245,6 +271,14 @@
</object>
<int key="connectionID">660</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">eraseMenuItem</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="796561994"/>
</object>
<int key="connectionID">664</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
Expand Down Expand Up @@ -331,6 +365,8 @@
<reference ref="630128020"/>
<reference ref="116792579"/>
<reference ref="605965567"/>
<reference ref="796561994"/>
<reference ref="1064529420"/>
</array>
<reference key="parent" ref="0"/>
</object>
Expand Down Expand Up @@ -370,6 +406,17 @@
<reference key="parent" ref="862705665"/>
<string key="objectName">Launch At Login</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">661</int>
<reference key="object" ref="796561994"/>
<reference key="parent" ref="862705665"/>
<string key="objectName">Erase All Simulators</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">662</int>
<reference key="object" ref="1064529420"/>
<reference key="parent" ref="862705665"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
Expand All @@ -392,12 +439,14 @@
<string key="649.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="652.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="658.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="661.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="662.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">660</int>
<int key="maxID">664</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -420,19 +469,22 @@
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">../Shuttle/AppDelegate.h</string>
<string key="minorKey">../SimulatorManager/AppDelegate.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">AppDelegate</string>
<dictionary class="NSMutableDictionary" key="actions">
<string key="eraseAllSimulators:">id</string>
<string key="launchAtLogin:">id</string>
<string key="quit:">id</string>
<string key="showAbout:">id</string>
<string key="showExportPanel:">id</string>
<string key="showImportPanel:">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName">
<object class="IBActionInfo" key="eraseAllSimulators:">
<string key="name">eraseAllSimulators:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="launchAtLogin:">
<string key="name">launchAtLogin:</string>
<string key="candidateClassName">id</string>
Expand All @@ -445,29 +497,24 @@
<string key="name">showAbout:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="showExportPanel:">
<string key="name">showExportPanel:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="showImportPanel:">
<string key="name">showImportPanel:</string>
<string key="candidateClassName">id</string>
</object>
</dictionary>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">launchAtLoginMenuItem</string>
<string key="NS.object.0">NSMenuItem</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">launchAtLoginMenuItem</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<dictionary class="NSMutableDictionary" key="outlets">
<string key="eraseMenuItem">NSMenuItem</string>
<string key="launchAtLoginMenuItem">NSMenuItem</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
<object class="IBToOneOutletInfo" key="eraseMenuItem">
<string key="name">eraseMenuItem</string>
<string key="candidateClassName">NSMenuItem</string>
</object>
<object class="IBToOneOutletInfo" key="launchAtLoginMenuItem">
<string key="name">launchAtLoginMenuItem</string>
<string key="candidateClassName">NSMenuItem</string>
</object>
</object>
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">../Shuttle/AppDelegate.m</string>
<string key="minorKey">../SimulatorManager/AppDelegate.m</string>
</object>
</object>
</array>
Expand Down Expand Up @@ -559,7 +606,7 @@
<bool key="IBDocument.previouslyAttemptedUpgradeToXcode5">NO</bool>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
<real value="1070" key="NS.object.0"/>
<real value="1080" key="NS.object.0"/>
</object>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
Expand Down

0 comments on commit c52fc70

Please sign in to comment.