-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from Planetable/ipfs-status-window
Open IPFS status view in a separate window
- Loading branch information
Showing
12 changed files
with
217 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
Planet/IPFS/Status Views/Window/IPFSStatusViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
Planet/IPFS/Status Views/Window/IPFSStatusWindowController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
Planet/IPFS/Status Views/Window/IPFSStatusWindowManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
CURRENT_PROJECT_VERSION = 2062 | ||
CURRENT_PROJECT_VERSION = 2077 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters