Skip to content

Commit 3dd7c68

Browse files
committed
Fix windows not being retained on older versions of macos
1 parent 96d68e7 commit 3dd7c68

File tree

4 files changed

+88
-18
lines changed

4 files changed

+88
-18
lines changed

TmpDisk.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
22A69389277005B80040FDEF /* TmpDiskLauncher.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 22A6935C277004E80040FDEF /* TmpDiskLauncher.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
2929
22A6938B27700B4B0040FDEF /* AutoCreateManagerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22A6938A27700B4B0040FDEF /* AutoCreateManagerViewController.swift */; };
3030
22A6938D27702BDF0040FDEF /* CheckBoxTableCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22A6938C27702BDF0040FDEF /* CheckBoxTableCellView.swift */; };
31+
22D93DBE27B85E0F0024FB53 /* WindowManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22D93DBD27B85E0F0024FB53 /* WindowManager.swift */; };
3132
/* End PBXBuildFile section */
3233

3334
/* Begin PBXContainerItemProxy section */
@@ -90,6 +91,7 @@
9091
22A69387277005840040FDEF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
9192
22A6938A27700B4B0040FDEF /* AutoCreateManagerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoCreateManagerViewController.swift; sourceTree = "<group>"; };
9293
22A6938C27702BDF0040FDEF /* CheckBoxTableCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckBoxTableCellView.swift; sourceTree = "<group>"; };
94+
22D93DBD27B85E0F0024FB53 /* WindowManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowManager.swift; sourceTree = "<group>"; };
9395
/* End PBXFileReference section */
9496

9597
/* Begin PBXFrameworksBuildPhase section */
@@ -156,6 +158,7 @@
156158
220082432765504E00A8524B /* AppDelegate.swift */,
157159
2264C5E1276553E600C45CB8 /* StatusBarController.swift */,
158160
2264C5EB27657AAC00C45CB8 /* TmpDiskManager.swift */,
161+
22D93DBD27B85E0F0024FB53 /* WindowManager.swift */,
159162
220082472765505100A8524B /* Assets.xcassets */,
160163
22235EBF27784F8200FBD8AC /* dsa_pub.pem */,
161164
2200826E2765508C00A8524B /* Info.plist */,
@@ -390,6 +393,7 @@
390393
22A6938B27700B4B0040FDEF /* AutoCreateManagerViewController.swift in Sources */,
391394
2264C5EE2765C34000C45CB8 /* NewTmpDiskViewController.swift in Sources */,
392395
2264C5EC27657AAC00C45CB8 /* TmpDiskManager.swift in Sources */,
396+
22D93DBE27B85E0F0024FB53 /* WindowManager.swift in Sources */,
393397
2264C5E2276553E600C45CB8 /* StatusBarController.swift in Sources */,
394398
22A6938D27702BDF0040FDEF /* CheckBoxTableCellView.swift in Sources */,
395399
220082442765504E00A8524B /* AppDelegate.swift in Sources */,
@@ -592,7 +596,7 @@
592596
CODE_SIGN_IDENTITY = "Apple Development";
593597
CODE_SIGN_STYLE = Automatic;
594598
COMBINE_HIDPI_IMAGES = YES;
595-
CURRENT_PROJECT_VERSION = 1001;
599+
CURRENT_PROJECT_VERSION = 1002;
596600
DEVELOPMENT_TEAM = AGZ3AP53DM;
597601
ENABLE_HARDENED_RUNTIME = YES;
598602
GENERATE_INFOPLIST_FILE = YES;
@@ -606,7 +610,7 @@
606610
"@executable_path/../Frameworks",
607611
);
608612
MACOSX_DEPLOYMENT_TARGET = 10.11;
609-
MARKETING_VERSION = 2.0.1;
613+
MARKETING_VERSION = 2.0.2;
610614
PRODUCT_BUNDLE_IDENTIFIER = com.imothee.TmpDisk;
611615
PRODUCT_NAME = "$(TARGET_NAME)";
612616
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -623,7 +627,7 @@
623627
CODE_SIGN_IDENTITY = "Apple Development";
624628
CODE_SIGN_STYLE = Automatic;
625629
COMBINE_HIDPI_IMAGES = YES;
626-
CURRENT_PROJECT_VERSION = 1001;
630+
CURRENT_PROJECT_VERSION = 1002;
627631
DEVELOPMENT_TEAM = AGZ3AP53DM;
628632
ENABLE_HARDENED_RUNTIME = YES;
629633
GENERATE_INFOPLIST_FILE = YES;
@@ -637,7 +641,7 @@
637641
"@executable_path/../Frameworks",
638642
);
639643
MACOSX_DEPLOYMENT_TARGET = 10.11;
640-
MARKETING_VERSION = 2.0.1;
644+
MARKETING_VERSION = 2.0.2;
641645
PRODUCT_BUNDLE_IDENTIFIER = com.imothee.TmpDisk;
642646
PRODUCT_NAME = "$(TARGET_NAME)";
643647
SWIFT_EMIT_LOC_STRINGS = YES;

TmpDisk.xcodeproj/xcuserdata/tim.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<key>TmpDisk.xcscheme_^#shared#^_</key>
88
<dict>
99
<key>orderHint</key>
10-
<integer>1</integer>
10+
<integer>0</integer>
1111
</dict>
1212
<key>TmpDiskLauncher.xcscheme_^#shared#^_</key>
1313
<dict>
1414
<key>orderHint</key>
15-
<integer>0</integer>
15+
<integer>1</integer>
1616
</dict>
1717
</dict>
1818
</dict>

TmpDisk/StatusBarController.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class StatusBarController {
3131
private let launcherAppId = "com.imothee.TmpDiskLauncher"
3232
private let updaterController: SPUStandardUpdaterController
3333

34+
private let windowManager = WindowManager()
35+
3436
init() {
3537
statusItem = NSStatusBar.system.statusItem(withLength: 28.0)
3638
statusMenu = NSMenu()
@@ -117,6 +119,10 @@ class StatusBarController {
117119
statusItem.menu = statusMenu
118120
}
119121

122+
func windowWillClose(window: NSWindowController) {
123+
124+
}
125+
120126
// MARK: - Internal
121127

122128
func confirmEject(volume: TmpDiskVolume) -> Bool {
@@ -156,21 +162,15 @@ class StatusBarController {
156162
// MARK: - Actions
157163

158164
@objc func newTmpDisk(sender: AnyObject) {
159-
NSApplication.shared.activate(ignoringOtherApps: true)
160-
let newTmpDiskWindow = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "NewTmpDiskWindow") as? NSWindowController
161-
newTmpDiskWindow?.showWindow(nil)
162-
newTmpDiskWindow?.window?.makeKey()
165+
windowManager.showNewTmpDiskWindow()
163166
}
164167

165168
@objc func recreateAll(sender: AnyObject) {
166169
TmpDiskManager.shared.ejectAllTmpDisks(recreate: true)
167170
}
168171

169172
@objc func autoCreateManager(sender: AnyObject) {
170-
NSApplication.shared.activate(ignoringOtherApps: true)
171-
let autoCreateManagerWindow = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "AutoCreateManagerWindow") as? NSWindowController
172-
autoCreateManagerWindow?.showWindow(nil)
173-
autoCreateManagerWindow?.window?.makeKey()
173+
windowManager.showAutoCreateManagerWindow()
174174
}
175175

176176
@objc func toggleStartOnLogin(sender: AnyObject) {
@@ -186,10 +186,7 @@ class StatusBarController {
186186
}
187187

188188
@objc func preferences(sender: AnyObject) {
189-
NSApplication.shared.activate(ignoringOtherApps: true)
190-
let preferencesWindow = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "PreferencesWindow") as? NSWindowController
191-
preferencesWindow?.showWindow(nil)
192-
preferencesWindow?.window?.makeKey()
189+
windowManager.showPreferencesWindow()
193190
}
194191

195192
@objc func help(sender: AnyObject) {

TmpDisk/WindowManager.swift

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// WindowManager.swift
3+
// TmpDisk
4+
//
5+
// Created by Tim on 2/12/22.
6+
//
7+
8+
import Foundation
9+
import AppKit
10+
11+
class WindowManager: NSObject, NSWindowDelegate {
12+
private var newTmpDiskWindow: NSWindowController?
13+
private var autoCreateManagerWindow: NSWindowController?
14+
private var preferencesWindow: NSWindowController?
15+
16+
func windowWillClose(_ notification: Notification) {
17+
if let window = notification.object as? NSWindow {
18+
switch window.windowController {
19+
case newTmpDiskWindow:
20+
newTmpDiskWindow = nil
21+
break
22+
case autoCreateManagerWindow:
23+
autoCreateManagerWindow = nil
24+
break
25+
case preferencesWindow:
26+
preferencesWindow = nil
27+
break
28+
default:
29+
return
30+
}
31+
}
32+
}
33+
34+
func showNewTmpDiskWindow() {
35+
NSApplication.shared.activate(ignoringOtherApps: true)
36+
37+
if newTmpDiskWindow == nil {
38+
newTmpDiskWindow = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "NewTmpDiskWindow") as? NSWindowController
39+
newTmpDiskWindow?.window?.delegate = self
40+
}
41+
42+
newTmpDiskWindow?.showWindow(nil)
43+
newTmpDiskWindow?.window?.makeKey()
44+
}
45+
46+
func showAutoCreateManagerWindow() {
47+
NSApplication.shared.activate(ignoringOtherApps: true)
48+
49+
if autoCreateManagerWindow == nil {
50+
autoCreateManagerWindow = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "AutoCreateManagerWindow") as? NSWindowController
51+
autoCreateManagerWindow?.window?.delegate = self
52+
}
53+
54+
autoCreateManagerWindow?.showWindow(nil)
55+
autoCreateManagerWindow?.window?.makeKey()
56+
}
57+
58+
func showPreferencesWindow() {
59+
NSApplication.shared.activate(ignoringOtherApps: true)
60+
61+
if preferencesWindow == nil {
62+
preferencesWindow = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "PreferencesWindow") as? NSWindowController
63+
preferencesWindow?.window?.delegate = self
64+
}
65+
66+
preferencesWindow?.showWindow(nil)
67+
preferencesWindow?.window?.makeKey()
68+
}
69+
}

0 commit comments

Comments
 (0)