Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tell the user to manually install App if failed installation detected #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,33 @@
#define ARCH_KEY_NAME @"x86_64"
#endif

#define USER_PREFS_KEY @"FigmaInstallationStarted"

const NSTimeInterval kDefaultTimeoutSecs = 60 * 60 * 12; // 12 hours

void showRetryModal() {
NSDictionary* info = [[NSBundle mainBundle] infoDictionary];
NSDictionary* downloadURLs = [info objectForKey:@"TargetDownloadURLs"];
NSURL* downloadURL = [NSURL URLWithString:[downloadURLs valueForKey:ARCH_KEY_NAME]];
NSString* targetAppName = [info valueForKey:@"TargetAppName"];

NSAlert* alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Download manually"];
[alert addButtonWithTitle:@"Retry"];
[alert setMessageText:[NSString
stringWithFormat:@"%@ Last Installation Failed", targetAppName]];
[alert setInformativeText:[NSString stringWithFormat:@"Download %@ manually to continue.",
targetAppName]];
[alert setAlertStyle:NSAlertStyleCritical];

[NSApp activateIgnoringOtherApps:YES];
if ([alert runModal] == NSAlertFirstButtonReturn) {
[[NSWorkspace sharedWorkspace] openURL:downloadURL];
[NSApp terminate:nullptr];
}

}

void showErrorModal(NSString* errorDecription) {
NSDictionary* info = [[NSBundle mainBundle] infoDictionary];
NSDictionary* downloadURLs = [info objectForKey:@"TargetDownloadURLs"];
Expand Down Expand Up @@ -58,6 +83,13 @@ @interface AppDelegate ()
@implementation AppDelegate

- (void)applicationWillFinishLaunching:(NSNotification*)notification {


if([[NSUserDefaults standardUserDefaults] boolForKey:USER_PREFS_KEY]) {
showRetryModal();
}
[[NSUserDefaults standardUserDefaults] setBool:true forKey:USER_PREFS_KEY];

// On macOS 10.12+, app bundles downloaded from the internet are launched
// from a randomized path until the user moves it to another folder with
// Finder. See: https://github.com/potionfactory/LetsMove/issues/56
Expand Down Expand Up @@ -203,6 +235,7 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {

dispatch_async(dispatch_get_main_queue(), ^{
[self launchInstalledApp];
[[NSUserDefaults standardUserDefaults] setBool:false forKey:USER_PREFS_KEY];
});
}];
[self.task resume];
Expand Down