From 515da271e36a1fa726781c389520713a4013f502 Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 19 Jun 2024 11:13:25 +0800 Subject: [PATCH 1/2] WIP: IPFS Status Window. --- Planet.xcodeproj/project.pbxproj | 6 +++--- .../IPFS Status => IPFS/Status Views}/IPFSStatusView.swift | 0 .../Status Views}/IPFSTrafficChartView.swift | 0 .../IPFS Status => IPFS/Status Views}/IPFSTrafficView.swift | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename Planet/{Labs/IPFS Status => IPFS/Status Views}/IPFSStatusView.swift (100%) rename Planet/{Labs/IPFS Status => IPFS/Status Views}/IPFSTrafficChartView.swift (100%) rename Planet/{Labs/IPFS Status => IPFS/Status Views}/IPFSTrafficView.swift (100%) diff --git a/Planet.xcodeproj/project.pbxproj b/Planet.xcodeproj/project.pbxproj index debdf195..8d7b5f3e 100644 --- a/Planet.xcodeproj/project.pbxproj +++ b/Planet.xcodeproj/project.pbxproj @@ -901,14 +901,14 @@ path = Views; sourceTree = ""; }; - 2A0E918E2BE8EFB500F69578 /* IPFS Status */ = { + 2A0E918E2BE8EFB500F69578 /* Status Views */ = { isa = PBXGroup; children = ( 2A0E918F2BE8EFC600F69578 /* IPFSStatusView.swift */, 2A391F042BF3137A006A3FD6 /* IPFSTrafficView.swift */, 2AC5A09C2BFAF7D700B9B172 /* IPFSTrafficChartView.swift */, ); - path = "IPFS Status"; + path = "Status Views"; sourceTree = ""; }; 2A2556B6293E1EE4006462D8 /* Window Controller */ = { @@ -1264,7 +1264,6 @@ 6A1DA07A28B4273C00C6B5A9 /* Labs */ = { isa = PBXGroup; children = ( - 2A0E918E2BE8EFB500F69578 /* IPFS Status */, 6A2827D22BD88E6C006B4A84 /* Quick Post */, 2A27744C2A9515C300A5DDC2 /* Icon Gallery */, 6AB6E4F92915226400F17328 /* Wallet */, @@ -1463,6 +1462,7 @@ 72114ABE784F27251FE3A0BD /* IPFS */ = { isa = PBXGroup; children = ( + 2A0E918E2BE8EFB500F69578 /* Status Views */, 2A8E08512BF4B139002D0C03 /* Open Views */, 721148C9E7BCB6F1BC539F57 /* IPFSState.swift */, 72114CC4F1FBAAD946B9A376 /* IPFSDaemon.swift */, diff --git a/Planet/Labs/IPFS Status/IPFSStatusView.swift b/Planet/IPFS/Status Views/IPFSStatusView.swift similarity index 100% rename from Planet/Labs/IPFS Status/IPFSStatusView.swift rename to Planet/IPFS/Status Views/IPFSStatusView.swift diff --git a/Planet/Labs/IPFS Status/IPFSTrafficChartView.swift b/Planet/IPFS/Status Views/IPFSTrafficChartView.swift similarity index 100% rename from Planet/Labs/IPFS Status/IPFSTrafficChartView.swift rename to Planet/IPFS/Status Views/IPFSTrafficChartView.swift diff --git a/Planet/Labs/IPFS Status/IPFSTrafficView.swift b/Planet/IPFS/Status Views/IPFSTrafficView.swift similarity index 100% rename from Planet/Labs/IPFS Status/IPFSTrafficView.swift rename to Planet/IPFS/Status Views/IPFSTrafficView.swift From d64f9023c28a9486f897b1d643cefddde4bbd418 Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 19 Jun 2024 13:45:21 +0800 Subject: [PATCH 2/2] Add IPFS Status Window. --- Planet.xcodeproj/project.pbxproj | 32 ++++++++++++ Planet/IPFS/IPFSState.swift | 1 + Planet/IPFS/Status Views/IPFSStatusView.swift | 14 ++++++ .../Status Views/IPFSTrafficChartView.swift | 3 ++ .../Window/IPFSStatusViewController.swift | 37 ++++++++++++++ .../Window/IPFSStatusWindow.swift | 49 +++++++++++++++++++ .../Window/IPFSStatusWindowController.swift | 29 +++++++++++ .../Window/IPFSStatusWindowManager.swift | 46 +++++++++++++++++ Planet/Views/Sidebar/PlanetSidebarView.swift | 2 +- Planet/versioning.xcconfig | 2 +- PlanetLite/AppSidebarView.swift | 2 +- 11 files changed, 214 insertions(+), 3 deletions(-) create mode 100644 Planet/IPFS/Status Views/Window/IPFSStatusViewController.swift create mode 100644 Planet/IPFS/Status Views/Window/IPFSStatusWindow.swift create mode 100644 Planet/IPFS/Status Views/Window/IPFSStatusWindowController.swift create mode 100644 Planet/IPFS/Status Views/Window/IPFSStatusWindowManager.swift diff --git a/Planet.xcodeproj/project.pbxproj b/Planet.xcodeproj/project.pbxproj index 8d7b5f3e..fc85874f 100644 --- a/Planet.xcodeproj/project.pbxproj +++ b/Planet.xcodeproj/project.pbxproj @@ -42,6 +42,14 @@ 2A3388C02BA7E3CD00D563A7 /* PlanetSettingsPublishedFoldersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3388BF2BA7E3CD00D563A7 /* PlanetSettingsPublishedFoldersView.swift */; }; 2A391F052BF3137A006A3FD6 /* IPFSTrafficView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A391F042BF3137A006A3FD6 /* IPFSTrafficView.swift */; }; 2A391F062BF3137A006A3FD6 /* IPFSTrafficView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A391F042BF3137A006A3FD6 /* IPFSTrafficView.swift */; }; + 2A3C6E722C22A3AA007B2CCD /* IPFSStatusViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3C6E6D2C22A3AA007B2CCD /* IPFSStatusViewController.swift */; }; + 2A3C6E732C22A3AA007B2CCD /* IPFSStatusViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3C6E6D2C22A3AA007B2CCD /* IPFSStatusViewController.swift */; }; + 2A3C6E742C22A3AA007B2CCD /* IPFSStatusWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3C6E6E2C22A3AA007B2CCD /* IPFSStatusWindow.swift */; }; + 2A3C6E752C22A3AA007B2CCD /* IPFSStatusWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3C6E6E2C22A3AA007B2CCD /* IPFSStatusWindow.swift */; }; + 2A3C6E762C22A3AA007B2CCD /* IPFSStatusWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3C6E6F2C22A3AA007B2CCD /* IPFSStatusWindowController.swift */; }; + 2A3C6E772C22A3AA007B2CCD /* IPFSStatusWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3C6E6F2C22A3AA007B2CCD /* IPFSStatusWindowController.swift */; }; + 2A3C6E782C22A3AA007B2CCD /* IPFSStatusWindowManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3C6E702C22A3AA007B2CCD /* IPFSStatusWindowManager.swift */; }; + 2A3C6E792C22A3AA007B2CCD /* IPFSStatusWindowManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3C6E702C22A3AA007B2CCD /* IPFSStatusWindowManager.swift */; }; 2A4164D429E64755009BFC24 /* PlanetQuickShareView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A4164D329E64755009BFC24 /* PlanetQuickShareView.swift */; }; 2A4164D729E64878009BFC24 /* PlanetQuickShareViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A4164D629E64878009BFC24 /* PlanetQuickShareViewModel.swift */; }; 2A4164DF29E64C97009BFC24 /* PlanetQuickShare+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A4164DE29E64C97009BFC24 /* PlanetQuickShare+Extension.swift */; }; @@ -556,6 +564,10 @@ 2A2F70ED29670D1300755931 /* CLTextFieldView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CLTextFieldView.swift; sourceTree = ""; }; 2A3388BF2BA7E3CD00D563A7 /* PlanetSettingsPublishedFoldersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanetSettingsPublishedFoldersView.swift; sourceTree = ""; }; 2A391F042BF3137A006A3FD6 /* IPFSTrafficView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPFSTrafficView.swift; sourceTree = ""; }; + 2A3C6E6D2C22A3AA007B2CCD /* IPFSStatusViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPFSStatusViewController.swift; sourceTree = ""; }; + 2A3C6E6E2C22A3AA007B2CCD /* IPFSStatusWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPFSStatusWindow.swift; sourceTree = ""; }; + 2A3C6E6F2C22A3AA007B2CCD /* IPFSStatusWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPFSStatusWindowController.swift; sourceTree = ""; }; + 2A3C6E702C22A3AA007B2CCD /* IPFSStatusWindowManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPFSStatusWindowManager.swift; sourceTree = ""; }; 2A4164D329E64755009BFC24 /* PlanetQuickShareView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanetQuickShareView.swift; sourceTree = ""; }; 2A4164D629E64878009BFC24 /* PlanetQuickShareViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanetQuickShareViewModel.swift; sourceTree = ""; }; 2A4164DE29E64C97009BFC24 /* PlanetQuickShare+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PlanetQuickShare+Extension.swift"; sourceTree = ""; }; @@ -907,6 +919,7 @@ 2A0E918F2BE8EFC600F69578 /* IPFSStatusView.swift */, 2A391F042BF3137A006A3FD6 /* IPFSTrafficView.swift */, 2AC5A09C2BFAF7D700B9B172 /* IPFSTrafficChartView.swift */, + 2A3C6E712C22A3AA007B2CCD /* Window */, ); path = "Status Views"; sourceTree = ""; @@ -975,6 +988,17 @@ path = "ipfs-executables"; sourceTree = ""; }; + 2A3C6E712C22A3AA007B2CCD /* Window */ = { + isa = PBXGroup; + children = ( + 2A3C6E6D2C22A3AA007B2CCD /* IPFSStatusViewController.swift */, + 2A3C6E6E2C22A3AA007B2CCD /* IPFSStatusWindow.swift */, + 2A3C6E6F2C22A3AA007B2CCD /* IPFSStatusWindowController.swift */, + 2A3C6E702C22A3AA007B2CCD /* IPFSStatusWindowManager.swift */, + ); + path = Window; + sourceTree = ""; + }; 2A4164D529E6475E009BFC24 /* Quick Share */ = { isa = PBXGroup; children = ( @@ -1824,6 +1848,7 @@ 6AA2C2032AFF538B00F6C633 /* MyArticleGridView.swift in Sources */, 6AB75A8E2A5496F20050AD58 /* MyPlanetTemplateSettingsView.swift in Sources */, 2A996ADA2A1DA6D100BEF898 /* PlanetDownloadsWebView.swift in Sources */, + 2A3C6E792C22A3AA007B2CCD /* IPFSStatusWindowManager.swift in Sources */, 6A16E3522AB30BE8005D3E7E /* PlanetStore+Timer.swift in Sources */, 2A95E6582A19A3A2001288B8 /* WalletConnectV1.swift in Sources */, 2A95E6572A19A3A2001288B8 /* WalletAccountView.swift in Sources */, @@ -1855,8 +1880,10 @@ 2A95E6E92A19A64F001288B8 /* LoadingIndicatorView.swift in Sources */, 2A95E6622A19A3AA001288B8 /* TemplateBrowserPreviewWebView.swift in Sources */, 6ADD7D892A51B616003D2E54 /* MyArticleModel+Save.swift in Sources */, + 2A3C6E732C22A3AA007B2CCD /* IPFSStatusViewController.swift in Sources */, 2A95E6E12A19A521001288B8 /* dWebServices.swift in Sources */, 2A95E6652A19A3AA001288B8 /* Template.swift in Sources */, + 2A3C6E752C22A3AA007B2CCD /* IPFSStatusWindow.swift in Sources */, 2A95E6692A19A3AF001288B8 /* TB+Extension.swift in Sources */, 2A95E66A2A19A3AF001288B8 /* TBWindowController.swift in Sources */, 2A95E64F2A19A398001288B8 /* PFDashboardInspectorView.swift in Sources */, @@ -1872,6 +1899,7 @@ 2A95E64C2A19A398001288B8 /* PFDashboardView.swift in Sources */, 2A996AD72A1DA6CA00BEF898 /* PlanetDownloadsWindow.swift in Sources */, 2A95E67B2A19A3C4001288B8 /* Updater.swift in Sources */, + 2A3C6E772C22A3AA007B2CCD /* IPFSStatusWindowController.swift in Sources */, 2A95E6902A19A3D0001288B8 /* PlanetKeyManagerView.swift in Sources */, 6A7F60672B21A37100475731 /* SearchView.swift in Sources */, 6AE096BF2A5CC35700A2BECB /* MyPlanetIPNSView.swift in Sources */, @@ -2039,6 +2067,7 @@ 2A23C2062B8ED4E2000138DA /* PlanetDirectoryMonitor.swift in Sources */, 2AC5A09D2BFAF7D700B9B172 /* IPFSTrafficChartView.swift in Sources */, 2A2F70EE29670D1300755931 /* CLTextFieldView.swift in Sources */, + 2A3C6E782C22A3AA007B2CCD /* IPFSStatusWindowManager.swift in Sources */, 2A9B09A5294F35640002719C /* PFDashboardContentView.swift in Sources */, 6A5E63AC28072AD400FB1E84 /* TemplateBrowserView.swift in Sources */, 2AE44EAE28CD219700944786 /* PlanetSettingsModel.swift in Sources */, @@ -2080,6 +2109,7 @@ 6ADD7D882A51B616003D2E54 /* MyArticleModel+Save.swift in Sources */, 6A941CED2AF5E7A300CA8261 /* PlanetStore+ServerInfo.swift in Sources */, 2A9B09A3294F066B0002719C /* PFDashboardWebView.swift in Sources */, + 2A3C6E722C22A3AA007B2CCD /* IPFSStatusViewController.swift in Sources */, 6A2C0BBC2A729DC2009E53DE /* AvatarPickerView.swift in Sources */, 2A2556B8293E1F13006462D8 /* TBContainerViewController.swift in Sources */, 6A7F60662B21A37100475731 /* SearchView.swift in Sources */, @@ -2117,6 +2147,7 @@ 6AC01AF0291ECC7E00EB6B5F /* WalletAccountView.swift in Sources */, 721145603D528B27CC6091D1 /* WriterDragAndDrop.swift in Sources */, 2AA7974329496F730031E873 /* PFDashboardSidebarViewController.swift in Sources */, + 2A3C6E762C22A3AA007B2CCD /* IPFSStatusWindowController.swift in Sources */, 2A391F052BF3137A006A3FD6 /* IPFSTrafficView.swift in Sources */, 72114D4918DAC507F6E3AF7F /* MarkdownUtils.swift in Sources */, 72114FE37ADE9340E448FF3E /* WriterViewModel.swift in Sources */, @@ -2132,6 +2163,7 @@ 2AFB896929BA1455003D893E /* PlanetKeyManagerView.swift in Sources */, 2A27744B2A9515BF00A5DDC2 /* IconManager.swift in Sources */, 6ACF1667292570AF00AE318B /* PlanetUI.swift in Sources */, + 2A3C6E742C22A3AA007B2CCD /* IPFSStatusWindow.swift in Sources */, 2AF3F0422AD2C9BE001A97E1 /* PlanetQuickShareDropDelegate.swift in Sources */, 2AA7974429496F730031E873 /* PFDashboardWindow.swift in Sources */, 2A6247AE292CC5F400714BFA /* IndicatorLabelView.swift in Sources */, diff --git a/Planet/IPFS/IPFSState.swift b/Planet/IPFS/IPFSState.swift index 8a904e4a..2012992f 100644 --- a/Planet/IPFS/IPFSState.swift +++ b/Planet/IPFS/IPFSState.swift @@ -12,6 +12,7 @@ class IPFSState: ObservableObject { @Published var reasonIPFSNotRunning: String? = nil @Published var isShowingStatus = false + @Published var isShowingStatusWindow = false @Published private(set) var isOperating = false @Published private(set) var online = false diff --git a/Planet/IPFS/Status Views/IPFSStatusView.swift b/Planet/IPFS/Status Views/IPFSStatusView.swift index 9fc24616..3073af7c 100644 --- a/Planet/IPFS/Status Views/IPFSStatusView.swift +++ b/Planet/IPFS/Status Views/IPFSStatusView.swift @@ -46,6 +46,19 @@ struct IPFSStatusView: View { .progressViewStyle(.circular) .controlSize(.small) } else { + if !ipfsState.isShowingStatusWindow { + Button { + IPFSStatusWindowManager.shared.activate() + } label: { + Image(systemName: "rectangle.inset.filled.on.rectangle") + .resizable() + .aspectRatio(contentMode: .fit) + .frame(height: 15) + .foregroundStyle(Color.secondary) + } + .buttonStyle(.plain) + .help("Open status in separate window.") + } Toggle("", isOn: $isDaemonOnline) .toggleStyle(SwitchToggleStyle()) .tint(.green) @@ -72,6 +85,7 @@ struct IPFSStatusView: View { } .padding(0) .frame(width: 280) + .background(.regularMaterial) .task { Task.detached(priority: .background) { do { diff --git a/Planet/IPFS/Status Views/IPFSTrafficChartView.swift b/Planet/IPFS/Status Views/IPFSTrafficChartView.swift index 1da4705f..4a3102a3 100644 --- a/Planet/IPFS/Status Views/IPFSTrafficChartView.swift +++ b/Planet/IPFS/Status Views/IPFSTrafficChartView.swift @@ -207,6 +207,9 @@ struct IPFSTrafficChartView: View { ForEach(items, id: \.id) { item in VStack(spacing: 0) { let itemHeight: CGFloat = { + if max <= 0 { + return 1.0 + } let h = CGFloat(isInTraffic ? item.rateIn : item.rateOut) / max * height if h < 1.0 { return 1.0 diff --git a/Planet/IPFS/Status Views/Window/IPFSStatusViewController.swift b/Planet/IPFS/Status Views/Window/IPFSStatusViewController.swift new file mode 100644 index 00000000..55310d20 --- /dev/null +++ b/Planet/IPFS/Status Views/Window/IPFSStatusViewController.swift @@ -0,0 +1,37 @@ +// +// IPFSStatusViewController.swift +// Planet +// + +import Foundation +import Cocoa +import SwiftUI + + +class IPFSStatusViewController: NSViewController { + init() { + super.init(nibName: nil, bundle: nil) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func loadView() { + self.view = NSView() + self.view.wantsLayer = true + self.view.layer?.backgroundColor = .clear + } + + override func viewDidLoad() { + super.viewDidLoad() + let mainView = IPFSStatusView() + let contentView = NSHostingView(rootView: mainView.environmentObject(IPFSState.shared)) + contentView.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(contentView) + contentView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true + contentView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true + contentView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true + contentView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true + } +} diff --git a/Planet/IPFS/Status Views/Window/IPFSStatusWindow.swift b/Planet/IPFS/Status Views/Window/IPFSStatusWindow.swift new file mode 100644 index 00000000..915be2b6 --- /dev/null +++ b/Planet/IPFS/Status Views/Window/IPFSStatusWindow.swift @@ -0,0 +1,49 @@ +// +// IPFSStatusWindow.swift +// Planet +// + +import Foundation +import Cocoa + + +class IPFSStatusWindow: NSWindow { + static let minWidth: CGFloat = 280 + static let minHeight: CGFloat = 280 + + init(withOrigin origin: NSPoint) { + let windowOrigin: NSPoint = { + if origin == .zero { + let screenFrame = NSScreen.main!.frame + let x = (screenFrame.width - Self.minWidth) / 2 + let y = (screenFrame.height - Self.minHeight) / 2 + return NSPoint(x: x, y: y) + } + return origin + }() + super.init(contentRect: NSRect(origin: windowOrigin, size: .init(width: Self.minWidth, height: Self.minHeight)), styleMask: [.closable, .titled, .fullSizeContentView], backing: .buffered, defer: true) + self.minSize = CGSize(width: Self.minWidth, height: Self.minHeight) + self.collectionBehavior = .fullScreenNone + self.title = "IPFS Status" + self.titlebarAppearsTransparent = true + self.titleVisibility = .visible + self.isMovableByWindowBackground = true + self.isOpaque = false + self.backgroundColor = .clear + self.delegate = self + self.setFrameAutosaveName("IPFSStatusWindow") + } +} + + +extension IPFSStatusWindow: NSWindowDelegate { + func windowWillClose(_ notification: Notification) { + } + + func windowShouldClose(_ sender: NSWindow) -> Bool { + Task { @MainActor in + IPFSState.shared.isShowingStatusWindow = false + } + return true + } +} diff --git a/Planet/IPFS/Status Views/Window/IPFSStatusWindowController.swift b/Planet/IPFS/Status Views/Window/IPFSStatusWindowController.swift new file mode 100644 index 00000000..4c3ba6f8 --- /dev/null +++ b/Planet/IPFS/Status Views/Window/IPFSStatusWindowController.swift @@ -0,0 +1,29 @@ +// +// IPFSStatusWindowController.swift +// Planet +// + +import Foundation +import Cocoa + + +class IPFSStatusWindowController: NSWindowController { + init(withOrigin origin: NSPoint) { + let w = IPFSStatusWindow(withOrigin: origin) + super.init(window: w) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + deinit { + self.window?.contentViewController = nil + self.window?.windowController = nil + self.window = nil + } + + override func showWindow(_ sender: Any?) { + super.showWindow(sender) + } +} diff --git a/Planet/IPFS/Status Views/Window/IPFSStatusWindowManager.swift b/Planet/IPFS/Status Views/Window/IPFSStatusWindowManager.swift new file mode 100644 index 00000000..b7b1e971 --- /dev/null +++ b/Planet/IPFS/Status Views/Window/IPFSStatusWindowManager.swift @@ -0,0 +1,46 @@ +// +// IPFSStatusWindowManager.swift +// Planet +// + +import Foundation + + +class IPFSStatusWindowManager: NSObject { + static let shared = IPFSStatusWindowManager() + static let lastWindowOriginKey: String = "PlanetIPFSStatusWindowLastOriginKey" + + private var windowController: IPFSStatusWindowController? + + func activate() { + let origin: NSPoint = { + if let value = UserDefaults.standard.value(forKey: Self.lastWindowOriginKey) as? NSValue { + return value.pointValue + } + return .zero + }() + if windowController == nil { + let wc = IPFSStatusWindowController(withOrigin: origin) + let vc = IPFSStatusViewController() + wc.contentViewController = vc + windowController = wc + } + windowController?.showWindow(nil) + Task { @MainActor in + IPFSState.shared.isShowingStatus = false + IPFSState.shared.isShowingStatusWindow = true + } + } + + func deactivate() { + let windowOrigin: NSPoint = windowController?.window?.frame.origin ?? .zero + UserDefaults.standard.set(NSValue(point: windowOrigin), forKey: Self.lastWindowOriginKey) + windowController?.contentViewController = nil + windowController?.window?.close() + windowController?.window = nil + windowController = nil + Task { @MainActor in + IPFSState.shared.isShowingStatusWindow = false + } + } +} diff --git a/Planet/Views/Sidebar/PlanetSidebarView.swift b/Planet/Views/Sidebar/PlanetSidebarView.swift index 84f6a312..8309f4f6 100644 --- a/Planet/Views/Sidebar/PlanetSidebarView.swift +++ b/Planet/Views/Sidebar/PlanetSidebarView.swift @@ -139,7 +139,7 @@ struct PlanetSidebarView: View { .onTapGesture { guard !ipfsState.isOperating else { return } Task { @MainActor in - self.ipfsState.isShowingStatus.toggle() + self.ipfsState.isShowingStatus = true } } .popover( diff --git a/Planet/versioning.xcconfig b/Planet/versioning.xcconfig index 68d36fa8..19b19052 100644 --- a/Planet/versioning.xcconfig +++ b/Planet/versioning.xcconfig @@ -1 +1 @@ -CURRENT_PROJECT_VERSION = 2062 \ No newline at end of file +CURRENT_PROJECT_VERSION = 2077 diff --git a/PlanetLite/AppSidebarView.swift b/PlanetLite/AppSidebarView.swift index 5f957fc3..67da8dc3 100644 --- a/PlanetLite/AppSidebarView.swift +++ b/PlanetLite/AppSidebarView.swift @@ -69,7 +69,7 @@ struct AppSidebarView: View { .onTapGesture { guard !ipfsState.isOperating else { return } Task { @MainActor in - self.ipfsState.isShowingStatus.toggle() + self.ipfsState.isShowingStatus = true } } .popover(