Skip to content

Commit

Permalink
Merge pull request #369 from Planetable/ipfs-status-window
Browse files Browse the repository at this point in the history
Open IPFS status view in a separate window
  • Loading branch information
livid authored Jun 20, 2024
2 parents f1ddf89 + d64f902 commit fe056b1
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 6 deletions.
38 changes: 35 additions & 3 deletions Planet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -556,6 +564,10 @@
2A2F70ED29670D1300755931 /* CLTextFieldView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CLTextFieldView.swift; sourceTree = "<group>"; };
2A3388BF2BA7E3CD00D563A7 /* PlanetSettingsPublishedFoldersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanetSettingsPublishedFoldersView.swift; sourceTree = "<group>"; };
2A391F042BF3137A006A3FD6 /* IPFSTrafficView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPFSTrafficView.swift; sourceTree = "<group>"; };
2A3C6E6D2C22A3AA007B2CCD /* IPFSStatusViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPFSStatusViewController.swift; sourceTree = "<group>"; };
2A3C6E6E2C22A3AA007B2CCD /* IPFSStatusWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPFSStatusWindow.swift; sourceTree = "<group>"; };
2A3C6E6F2C22A3AA007B2CCD /* IPFSStatusWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPFSStatusWindowController.swift; sourceTree = "<group>"; };
2A3C6E702C22A3AA007B2CCD /* IPFSStatusWindowManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPFSStatusWindowManager.swift; sourceTree = "<group>"; };
2A4164D329E64755009BFC24 /* PlanetQuickShareView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanetQuickShareView.swift; sourceTree = "<group>"; };
2A4164D629E64878009BFC24 /* PlanetQuickShareViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanetQuickShareViewModel.swift; sourceTree = "<group>"; };
2A4164DE29E64C97009BFC24 /* PlanetQuickShare+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PlanetQuickShare+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -901,14 +913,15 @@
path = Views;
sourceTree = "<group>";
};
2A0E918E2BE8EFB500F69578 /* IPFS Status */ = {
2A0E918E2BE8EFB500F69578 /* Status Views */ = {
isa = PBXGroup;
children = (
2A0E918F2BE8EFC600F69578 /* IPFSStatusView.swift */,
2A391F042BF3137A006A3FD6 /* IPFSTrafficView.swift */,
2AC5A09C2BFAF7D700B9B172 /* IPFSTrafficChartView.swift */,
2A3C6E712C22A3AA007B2CCD /* Window */,
);
path = "IPFS Status";
path = "Status Views";
sourceTree = "<group>";
};
2A2556B6293E1EE4006462D8 /* Window Controller */ = {
Expand Down Expand Up @@ -975,6 +988,17 @@
path = "ipfs-executables";
sourceTree = "<group>";
};
2A3C6E712C22A3AA007B2CCD /* Window */ = {
isa = PBXGroup;
children = (
2A3C6E6D2C22A3AA007B2CCD /* IPFSStatusViewController.swift */,
2A3C6E6E2C22A3AA007B2CCD /* IPFSStatusWindow.swift */,
2A3C6E6F2C22A3AA007B2CCD /* IPFSStatusWindowController.swift */,
2A3C6E702C22A3AA007B2CCD /* IPFSStatusWindowManager.swift */,
);
path = Window;
sourceTree = "<group>";
};
2A4164D529E6475E009BFC24 /* Quick Share */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1264,7 +1288,6 @@
6A1DA07A28B4273C00C6B5A9 /* Labs */ = {
isa = PBXGroup;
children = (
2A0E918E2BE8EFB500F69578 /* IPFS Status */,
6A2827D22BD88E6C006B4A84 /* Quick Post */,
2A27744C2A9515C300A5DDC2 /* Icon Gallery */,
6AB6E4F92915226400F17328 /* Wallet */,
Expand Down Expand Up @@ -1463,6 +1486,7 @@
72114ABE784F27251FE3A0BD /* IPFS */ = {
isa = PBXGroup;
children = (
2A0E918E2BE8EFB500F69578 /* Status Views */,
2A8E08512BF4B139002D0C03 /* Open Views */,
721148C9E7BCB6F1BC539F57 /* IPFSState.swift */,
72114CC4F1FBAAD946B9A376 /* IPFSDaemon.swift */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down
1 change: 1 addition & 0 deletions Planet/IPFS/IPFSState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -72,6 +85,7 @@ struct IPFSStatusView: View {
}
.padding(0)
.frame(width: 280)
.background(.regularMaterial)
.task {
Task.detached(priority: .background) {
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions Planet/IPFS/Status Views/Window/IPFSStatusViewController.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
49 changes: 49 additions & 0 deletions Planet/IPFS/Status Views/Window/IPFSStatusWindow.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
29 changes: 29 additions & 0 deletions Planet/IPFS/Status Views/Window/IPFSStatusWindowController.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
46 changes: 46 additions & 0 deletions Planet/IPFS/Status Views/Window/IPFSStatusWindowManager.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
}
2 changes: 1 addition & 1 deletion Planet/Views/Sidebar/PlanetSidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Planet/versioning.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 2062
CURRENT_PROJECT_VERSION = 2077
2 changes: 1 addition & 1 deletion PlanetLite/AppSidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit fe056b1

Please sign in to comment.