Skip to content

Commit

Permalink
feat: move to applications alert on first launch (#36)
Browse files Browse the repository at this point in the history
* 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
kavoye and IsaacMarovitz committed Jun 8, 2023
1 parent 99251e3 commit c8e4b07
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

.DS_Store

## User settings
xcuserdata/

Expand Down
4 changes: 4 additions & 0 deletions Whisky.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
6E5E23EC2A30DBCA00ABC192 /* Hdiutil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E5E23EB2A30DBCA00ABC192 /* Hdiutil.swift */; };
6EA2D47E29DDAE5E00C84668 /* BottleRenameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EA2D47D29DDAE5E00C84668 /* BottleRenameView.swift */; };
6EA2D48529DF130F00C84668 /* ProgramSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EA2D48429DF130F00C84668 /* ProgramSettings.swift */; };
EEA5A2462A31DD65008274AE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEA5A2452A31DD65008274AE /* AppDelegate.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -74,6 +75,7 @@
6E899D1129CFC41D00A4A083 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
6EA2D47D29DDAE5E00C84668 /* BottleRenameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottleRenameView.swift; sourceTree = "<group>"; };
6EA2D48429DF130F00C84668 /* ProgramSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgramSettings.swift; sourceTree = "<group>"; };
EEA5A2452A31DD65008274AE /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -129,6 +131,7 @@
6E40495429CCA19C006E3F1B /* Whisky */ = {
isa = PBXGroup;
children = (
EEA5A2452A31DD65008274AE /* AppDelegate.swift */,
6E26058729D927F900DDD788 /* Extensions */,
6E5197CF29D71FF900CF655E /* Models */,
6E5197D029D7200700CF655E /* Utils */,
Expand Down Expand Up @@ -307,6 +310,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EEA5A2462A31DD65008274AE /* AppDelegate.swift in Sources */,
6E40495829CCA19C006E3F1B /* ContentView.swift in Sources */,
6E355E5C29D7830C002D83BE /* InfoView.swift in Sources */,
6E5E23EA2A30D6C400ABC192 /* GPTInstallView.swift in Sources */,
Expand Down
54 changes: 54 additions & 0 deletions Whisky/AppDelegate.swift
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,

Check failure on line 40 in Whisky/AppDelegate.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
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)")
}
}
}
}
6 changes: 5 additions & 1 deletion Whisky/Utils/GPT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import Foundation

// GPT = Game Porting Toolkit
class GPT {
static let libFolder: URL = (Bundle.main.resourceURL ?? URL(fileURLWithPath: ""))
static let applicationFolder: URL = FileManager.default.urls(for: .applicationDirectory, in: .localDomainMask)[0]
static let libFolder: URL = applicationFolder
.appendingPathComponent("Whisky.app")
.appendingPathComponent("Contents")
.appendingPathComponent("Resources")
.appendingPathComponent("Libraries")
.appendingPathComponent("Wine")
.appendingPathComponent("lib")
Expand Down
1 change: 1 addition & 0 deletions Whisky/Views/GPTInstallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct GPTInstallView: View {
.animation(.easeInOut(duration: 0.2), value: dragOver)
}
}
.fixedSize()
.padding()
.onDrop(of: ["public.file-url"], isTargeted: $dragOver) { providers -> Bool in
providers.first?.loadDataRepresentation(forTypeIdentifier: "public.file-url",
Expand Down
6 changes: 0 additions & 6 deletions Whisky/Views/WhiskyApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
import SwiftUI
import Sparkle

class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillTerminate(_ notification: Notification) {
WhiskyApp.killBottles()
}
}

@main
struct WhiskyApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
Expand Down
5 changes: 5 additions & 0 deletions Whisky/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@

"check.updates" = "Check for Updates...";
"kill.bottles" = "Kill All Bottles...";

"showAlertOnFirstLaunch.messageText" = "Would you like to move Whisky to your Applications folder?";
"showAlertOnFirstLaunch.informativeText" = "In some cases, Whisky wont't be able to function properly from a different folder";
"showAlertOnFirstLaunch.button.moveToApplications" = "Move to Applications";
"showAlertOnFirstLaunch.button.dontMove" = "Don't Move";

0 comments on commit c8e4b07

Please sign in to comment.