Skip to content

Commit

Permalink
UI: added exit button and startup message
Browse files Browse the repository at this point in the history
Resolves #32
  • Loading branch information
osy committed Mar 2, 2020
1 parent c35cf2c commit 4fd07e2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
10 changes: 6 additions & 4 deletions UTM/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,18 @@
</connections>
</collectionView>
<navigationItem key="navigationItem" title="Virtual Machines" id="y7c-vs-jlM">
<barButtonItem key="leftBarButtonItem" systemItem="stop" id="Jnw-zM-dyF">
<connections>
<action selector="exitUTM:" destination="krH-Hz-4fz" id="wcV-cc-N6y"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" systemItem="add" id="e5k-lL-Xj6">
<connections>
<segue destination="2Ff-Ox-yNa" kind="popoverPresentation" identifier="newVM" popoverAnchorBarButtonItem="e5k-lL-Xj6" id="uhI-Ry-wJ8">
<popoverArrowDirection key="popoverArrowDirection" up="YES" down="YES" left="YES" right="YES"/>
</segue>
</connections>
</barButtonItem>
<connections>
<outlet property="rightBarButtonItem" destination="e5k-lL-Xj6" id="87b-9t-bNR"/>
</connections>
</navigationItem>
<connections>
<segue destination="ckC-eO-gxn" kind="show" identifier="startVM" id="psC-T5-Ggl"/>
Expand Down Expand Up @@ -2829,7 +2831,7 @@
<inferredMetricsTieBreakers>
<segue reference="0fe-13-GUd"/>
<segue reference="M4J-mO-49e"/>
<segue reference="QMb-O0-K4I"/>
<segue reference="eOg-7f-ZC7"/>
<segue reference="Ch9-qF-y79"/>
</inferredMetricsTieBreakers>
</document>
1 change: 1 addition & 0 deletions Views/VMListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
- (IBAction)unwindToMainFromVM:(UIStoryboardSegue*)sender;
- (IBAction)startVMFromButton:(UIButton *)sender;
- (IBAction)startVMFromScreen:(UIButton *)sender;
- (IBAction)exitUTM:(UIBarButtonItem *)sender;

@end

Expand Down
26 changes: 26 additions & 0 deletions Views/VMListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ - (void)viewDidAppear:(BOOL)animated {
[self.collectionView reloadData];
});
});

// show any message
[self showStartupMessage];
}

#pragma mark - Properties
Expand Down Expand Up @@ -114,6 +117,18 @@ - (NSString *)createNewDefaultName {
return [[NSProcessInfo processInfo] globallyUniqueString];
}

- (void)showStartupMessage {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults boolForKey:@"HasShownStartupAlert"]) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:NSLocalizedString(@"Welcome to UTM! Due to a bug in iOS, if you force kill this app, your system will be unstable and you cannot launch UTM again until you reboot. The recommended way to terminate this app is the bottom on the top left. Another limitation is that you can only start one VM per launch, so you must terminate and re-launch to start a new VM.", @"Startup message") preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okay = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK button") style:UIAlertActionStyleDefault handler:nil];
[alert addAction:okay];
[self presentViewController:alert animated:YES completion:^{
[defaults setBool:YES forKey:@"HasShownStartupAlert"];
}];
}
}

#pragma mark - Navigation

- (nonnull UTMVirtualMachine *)cachedVMForCell:(id)cell {
Expand Down Expand Up @@ -307,4 +322,15 @@ - (IBAction)startVMFromScreen:(UIButton *)sender {
[self virtualMachine:self.activeVM transitionToState:self.activeVM.state];
}

- (IBAction)exitUTM:(UIBarButtonItem *)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:NSLocalizedString(@"Are you sure you want to exit UTM? Any running VM will be killed.", @"Exit confirmation") preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *yes = [UIAlertAction actionWithTitle:NSLocalizedString(@"Yes", @"Yes button") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action){
exit(0);
}];
UIAlertAction *no = [UIAlertAction actionWithTitle:NSLocalizedString(@"No", @"No button") style:UIAlertActionStyleCancel handler:nil];
[alert addAction:no];
[alert addAction:yes];
[self presentViewController:alert animated:YES completion:nil];
}

@end

0 comments on commit 4fd07e2

Please sign in to comment.