Skip to content

Commit

Permalink
improve general window behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
marzent committed Mar 25, 2022
1 parent c9d4aeb commit 5bafb86
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 87 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
filePath = "XIV on Mac/Launcher/FFXIVLoginServices.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "84"
endingLineNumber = "84"
startingLineNumber = "90"
endingLineNumber = "90"
landmarkName = "sessionId"
landmarkType = "24">
</BreakpointContent>
Expand Down Expand Up @@ -238,8 +238,8 @@
filePath = "XIV on Mac/Launcher/FFXIVLoginServices.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "64"
endingLineNumber = "64"
startingLineNumber = "70"
endingLineNumber = "70"
landmarkName = "authTop"
landmarkType = "24">
</BreakpointContent>
Expand All @@ -254,8 +254,8 @@
filePath = "XIV on Mac/Launcher/FFXIVLoginServices.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "74"
endingLineNumber = "74"
startingLineNumber = "80"
endingLineNumber = "80"
landmarkName = "authTop"
landmarkType = "24">
</BreakpointContent>
Expand All @@ -270,8 +270,8 @@
filePath = "XIV on Mac/Launcher/FFXIVLoginServices.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "67"
endingLineNumber = "67"
startingLineNumber = "73"
endingLineNumber = "73"
landmarkName = "authTop"
landmarkType = "24">
</BreakpointContent>
Expand All @@ -286,8 +286,8 @@
filePath = "XIV on Mac/Launcher/FFXIVLoginServices.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "77"
endingLineNumber = "77"
startingLineNumber = "83"
endingLineNumber = "83"
landmarkName = "authTop"
landmarkType = "24">
</BreakpointContent>
Expand All @@ -302,8 +302,8 @@
filePath = "XIV on Mac/Launcher/FFXIVLoginServices.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "58"
endingLineNumber = "58"
startingLineNumber = "64"
endingLineNumber = "64"
landmarkName = "authTop"
landmarkType = "24">
</BreakpointContent>
Expand Down Expand Up @@ -334,59 +334,27 @@
filePath = "XIV on Mac/AppDelegate.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "141"
endingLineNumber = "141"
startingLineNumber = "151"
endingLineNumber = "151"
landmarkName = "regedit(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "DDE6E6BD-0141-4F72-814B-6981E9A82A17"
shouldBeEnabled = "Yes"
uuid = "FE450891-051D-413F-A6F2-780188CBE09B"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XIV on Mac/AddOns/Dalamud.swift"
filePath = "XIV on Mac/Launcher/FFXIVLoginServices.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "156"
endingLineNumber = "156"
landmarkName = "install()"
startingLineNumber = "307"
endingLineNumber = "307"
landmarkName = "loginData(storedSID:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "41FCA411-3AF6-43F8-AA4F-6E809A6AD672"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XIV on Mac/AddOns/Dalamud.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "111"
endingLineNumber = "111"
landmarkName = "version"
landmarkType = "24">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "A5BD1E95-DB03-4512-A0DA-41E9B58421E0"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XIV on Mac/AddOns/Dalamud.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "91"
endingLineNumber = "91"
landmarkName = "assets"
landmarkType = "24">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
14 changes: 12 additions & 2 deletions XIV on Mac/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ import Sparkle
import AppMover

@main class AppDelegate: NSObject, NSApplicationDelegate, SPUUpdaterDelegate {
var settingsWinController: NSWindowController?
private var settingsWinController: NSWindowController!
private var launchWinController: NSWindowController!
@IBOutlet private var sparkle: SPUStandardUpdaterController!
@IBOutlet private var actAutoLaunch: NSMenuItem!
@IBOutlet private var bhAutoLaunch: NSMenuItem!

func applicationDidFinishLaunching(_ aNotification: Notification) {
let storyboard = NSStoryboard(name: "Main", bundle: nil)
settingsWinController = storyboard.instantiateController(withIdentifier: "SettingsWindow") as? NSWindowController
launchWinController = storyboard.instantiateController(withIdentifier: "LaunchWindow") as? NSWindowController
launchWinController.showWindow(self)
actAutoLaunch.state = ACT.autoLaunch ? .on : .off
bhAutoLaunch.state = ACT.autoLaunchBH ? .on : .off
checkForRosetta()
Expand All @@ -35,7 +39,6 @@ import AppMover
#else
AppMover.moveIfNecessary()
#endif
settingsWinController = storyboard.instantiateController(withIdentifier: "SettingsWindow") as? NSWindowController
}

func updaterWillRelaunchApplication(_ updater: SPUUpdater) {
Expand All @@ -50,6 +53,13 @@ import AppMover
return true
}

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
if !flag {
launchWinController.showWindow(self)
}
return true
}

func application(_ sender: NSApplication, openFile filename: String) -> Bool {
Wine.launch(args: [filename])
return true
Expand Down
7 changes: 3 additions & 4 deletions XIV on Mac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="SmX-cH-8Kr">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
Expand Down Expand Up @@ -91,8 +91,7 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
<menuItem title="Close" keyEquivalent="\" id="DVo-aG-piG">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
<connections>
<action selector="performClose:" target="Ady-hI-5gd" id="HmO-Ls-i7Q"/>
</connections>
Expand Down Expand Up @@ -1733,7 +1732,7 @@ Gw
<scene sceneID="ImY-2l-0oe">
<objects>
<windowController storyboardIdentifier="LaunchWindow" id="SmX-cH-8Kr" sceneMemberID="viewController">
<window key="window" title="XIV on Mac" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" titlebarAppearsTransparent="YES" id="msO-z3-Trw">
<window key="window" identifier="XOMMainWindowPosition" title="XIV on Mac" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" titlebarAppearsTransparent="YES" id="msO-z3-Trw">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" fullSizeContentView="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="425" y="462" width="163" height="137"/>
Expand Down
7 changes: 6 additions & 1 deletion XIV on Mac/Launcher/FFXIVApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ public struct FFXIVApp {
NotificationCenter.default.post(name: .loginInfo, object: nil, userInfo: [Notification.status.info: "Starting Wine"])
Wine.launch(args: args)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 15.0) {
let maxGameStartTime = 15.0
DispatchQueue.main.asyncAfter(deadline: .now() + maxGameStartTime) {
NotificationCenter.default.post(name: .gameStarted, object: nil)
}
}

static var running: Bool {
Wine.pidOf(processName: "ffxiv_dx11.exe") > 0
}

private static func doubleSpaceify(_ str: String) -> String {
return str.replacingOccurrences(of: " ", with: " ")
Expand Down
5 changes: 5 additions & 0 deletions XIV on Mac/Launcher/FFXIVEnums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public enum FFXIVLoginError: Error {
case networkError
case noInstall
case maintenance
case multibox
case unexpected(code: Int)
}

Expand All @@ -112,6 +113,8 @@ extension FFXIVLoginError: LocalizedError {
return NSLocalizedString("NO_INSTALL_SHORT", comment: "")
case .maintenance:
return NSLocalizedString("MAINTENANCE_SHORT", comment: "")
case .multibox:
return NSLocalizedString("MULTIBOX_SHORT", comment: "")
case .unexpected(_):
return NSLocalizedString("UNEXPECTED_SHORT", comment: "Unexpected Error Title")
}
Expand All @@ -135,6 +138,8 @@ extension FFXIVLoginError: LocalizedError {
return NSLocalizedString("NO_INSTALL", comment: "")
case .maintenance:
return NSLocalizedString("MAINTENANCE", comment: "")
case .multibox:
return NSLocalizedString("MULTIBOX", comment: "")
case .unexpected(_):
return NSLocalizedString("UNEXPECTED", comment: "Unexpected Error Description")
}
Expand Down
15 changes: 12 additions & 3 deletions XIV on Mac/Launcher/FFXIVLoginServices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ import SeeURL

struct FFXIVLogin {
typealias settings = FFXIVSettings
static let userAgent = settings.platform == .mac ? "macSQEXAuthor/2.0.0(MacOSX; ja-jp)" : "SQEXAuthor/2.0.0(Windows 6.2; ja-jp; \(uniqueID))"
static let userAgentPatch = settings.platform == .mac ? "FFXIV-MAC PATCH CLIENT" : "FFXIV PATCH CLIENT"
let authURL = URL(string: "https://ffxiv-login.square-enix.com/oauth/ffxivarr/login/login.send")!
let ticket = Steam.ticket
let authURL = URL(string: "https://ffxiv-login.square-enix.com/oauth/ffxivarr/login/login.send")!

static var userAgent: String {
settings.platform == .mac ? "macSQEXAuthor/2.0.0(MacOSX; ja-jp)" : "SQEXAuthor/2.0.0(Windows 6.2; ja-jp; \(uniqueID))"
}

static var userAgentPatch: String {
settings.platform == .mac ? "FFXIV-MAC PATCH CLIENT" : "FFXIV PATCH CLIENT"
}

var authTopURL: URL {
get throws {
Expand Down Expand Up @@ -134,6 +140,9 @@ struct FFXIVLogin {
guard FFXIVApp().installed else {
throw FFXIVLoginError.noInstall
}
if FFXIVApp.running {
throw FFXIVLoginError.multibox
}
if Frontier.maintenance {
throw FFXIVLoginError.maintenance
}
Expand Down
32 changes: 19 additions & 13 deletions XIV on Mac/Launcher/LaunchController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Cocoa

class LaunchController: NSViewController, NSWindowDelegate {
class LaunchController: NSViewController {

var loginSheetWinController: NSWindowController?
var installerWinController: NSWindowController?
Expand All @@ -31,6 +31,7 @@ class LaunchController: NSViewController, NSWindowDelegate {
setupOTP()
ACT.observe()
NotificationCenter.default.addObserver(self,selector: #selector(installDone(_:)),name: .installDone, object: nil)
NotificationCenter.default.addObserver(self,selector: #selector(loginDone(_:)),name: .gameStarted, object: nil)
if #available(macOS 11.0, *) {
newsTable = FrontierTableView(icon: NSImage(systemSymbolName: "newspaper", accessibilityDescription: nil)!)
topicsTable = FrontierTableView(icon: NSImage(systemSymbolName: "newspaper.fill", accessibilityDescription: nil)!)
Expand Down Expand Up @@ -69,15 +70,9 @@ class LaunchController: NSViewController, NSWindowDelegate {
loginSheetWinController = storyboard?.instantiateController(withIdentifier: "LoginSheet") as? NSWindowController
installerWinController = storyboard?.instantiateController(withIdentifier: "InstallerWindow") as? NSWindowController
patchWinController = storyboard?.instantiateController(withIdentifier: "PatchSheet") as? NSWindowController
view.window?.delegate = self
view.window?.isMovableByWindowBackground = true
}

func windowShouldClose(_ sender: NSWindow) -> Bool {
NSApp.hide(nil)
return false
}

private func populateNews(_ info: Frontier.Info) {
DispatchQueue.main.async {
self.topicsTable.add(items: info.topics)
Expand Down Expand Up @@ -129,10 +124,17 @@ class LaunchController: NSViewController, NSWindowDelegate {
}
}

@objc func loginDone(_ notif: Notification) {
DispatchQueue.main.async { [self] in
loginSheetWinController?.window?.close()
view.window?.close()
}
}

func startPatch(_ patches: [Patch]) {
DispatchQueue.main.async {
self.view.window?.beginSheet(self.patchWinController!.window!)
let patchController = self.patchWinController!.contentViewController! as! PatchController
DispatchQueue.main.async { [self] in
view.window?.beginSheet(patchWinController!.window!)
let patchController = patchWinController!.contentViewController! as! PatchController
patchController.install(patches)
}
}
Expand Down Expand Up @@ -187,13 +189,17 @@ final class AnimatingScrollView: NSScrollView {
}


private func startTimer() {
self.timer.invalidate()
self.timer = Timer.scheduledTimer(withTimeInterval: stayDuration, repeats: true, block: { _ in
func startTimer() {
stopTimer()
timer = Timer.scheduledTimer(withTimeInterval: stayDuration, repeats: true, block: { _ in
self.animate()
})
}

func stopTimer() {
timer.invalidate()
}

// This will override and cancel any running scroll animations
override public func scroll(_ clipView: NSClipView, to point: NSPoint) {
CATransaction.begin()
Expand Down
9 changes: 1 addition & 8 deletions XIV on Mac/LoginSheetController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class LoginSheetController: NSViewController {
super.viewWillAppear()
spinner.usesThreadedAnimation = true
spinner.startAnimation(self)
status.stringValue = "Logging In"
}

@objc func loginUpdate(_ notif: Notification) {
Expand All @@ -30,16 +31,8 @@ class LoginSheetController: NSViewController {
}
}

@objc func loginDone(_ notif: Notification) {
DispatchQueue.main.async {
self.status.stringValue = "Logging In"
self.view.window?.close()
}
}

private func setupObservers() {
NotificationCenter.default.addObserver(self,selector: #selector(loginUpdate(_:)),name: .loginInfo, object: nil)
NotificationCenter.default.addObserver(self,selector: #selector(loginDone(_:)),name: .gameStarted, object: nil)
}

}
10 changes: 6 additions & 4 deletions XIV on Mac/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ struct Util {
}

static func quit() {
let app = NSApplication.shared
for window in app.windows {
window.close()
DispatchQueue.main.async {
let app = NSApplication.shared
for window in app.windows {
window.close()
}
app.terminate(nil)
}
app.terminate(nil)
}

static func rosettaIsInstalled() -> Bool {
Expand Down
Loading

0 comments on commit 5bafb86

Please sign in to comment.