-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move to applications alert on first launch (#36)
* chore: add .DS_Store to .gitignore * fix: fix size of GPTInstallView * feat: add move to applications alert on first Whisky launch * chore: code refactoring * chore: add localisation for alert * Update Localizable.strings * Update AppDelegate.swift * Update GPT.swift * Update AppDelegate.swift --------- Co-authored-by: Isaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com>
- Loading branch information
1 parent
99251e3
commit c8e4b07
Showing
7 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// AppDelegate.swift | ||
// Whisky | ||
// | ||
// Created by Viacheslav Shkliarov on 08.06.2023. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
@AppStorage("hasShownMoveToApplicationsAlert") private var hasShownMoveToApplicationsAlert = false | ||
|
||
func applicationDidFinishLaunching(_ notification: Notification) { | ||
if !hasShownMoveToApplicationsAlert { | ||
DispatchQueue.main.asyncAfter(deadline: .now()) { | ||
NSApp.activate(ignoringOtherApps: true) | ||
self.showAlertOnFirstLaunch() | ||
self.hasShownMoveToApplicationsAlert = true | ||
} | ||
} | ||
} | ||
|
||
func applicationWillTerminate(_ notification: Notification) { | ||
WhiskyApp.killBottles() | ||
} | ||
|
||
private func showAlertOnFirstLaunch() { | ||
let alert = NSAlert() | ||
alert.messageText = NSLocalizedString("showAlertOnFirstLaunch.messageText", comment: "") | ||
alert.informativeText = NSLocalizedString("showAlertOnFirstLaunch.informativeText", comment: "") | ||
alert.addButton(withTitle: NSLocalizedString("showAlertOnFirstLaunch.button.moveToApplications", comment: "")) | ||
alert.addButton(withTitle: NSLocalizedString("showAlertOnFirstLaunch.button.dontMove", comment: "")) | ||
|
||
let response = alert.runModal() | ||
|
||
if response == .alertFirstButtonReturn { | ||
let appURL = Bundle.main.bundleURL | ||
|
||
guard let applicationsURL = FileManager.default.urls(for: .applicationDirectory, | ||
in: .localDomainMask).first else { | ||
return | ||
} | ||
|
||
let destinationURL = applicationsURL.appendingPathComponent(appURL.lastPathComponent) | ||
do { | ||
_ = try FileManager.default.replaceItemAt(destinationURL, withItemAt: appURL) | ||
NSWorkspace.shared.open(destinationURL) | ||
} catch { | ||
print("Failed to move the app: \(error)") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters