Skip to content

Commit 78957cc

Browse files
authored
Merge pull request #147 from Planetable/improved-published-folders-ui
Add auto-refresh logic to dashboard window titles.
2 parents b52c2d1 + 41edc5a commit 78957cc

6 files changed

Lines changed: 30 additions & 14 deletions

File tree

Planet/Labs/Published Folders/Dashboard/PFDashboardContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ struct PFDashboardContentView: NSViewRepresentable {
107107
if (host == "127.0.0.1" || host == "localhost") && UInt16(port) == IPFSDaemon.shared.gatewayPort {
108108
let indexPage = currentURL.appendingPathComponent("index.html")
109109
do {
110-
let request = URLRequest(url: indexPage, cachePolicy: .returnCacheDataElseLoad, timeoutInterval: 0.05)
110+
let request = URLRequest(url: indexPage, cachePolicy: .returnCacheDataElseLoad, timeoutInterval: 0.1)
111111
let (_, response) = try await URLSession.shared.data(for: request)
112112
if let httpResponse = response as? HTTPURLResponse {
113113
if httpResponse.statusCode != 200 {

Planet/Labs/Published Folders/Dashboard/PFDashboardView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ struct PFDashboardView: View {
4545
self.contentView = PFDashboardContentView(url: self.$url)
4646
}
4747
}
48+
.onReceive(serviceStore.timer, perform: { _ in
49+
serviceStore.updateWindowTitles()
50+
})
4851
.task {
4952
serviceStore.restoreSelectedFolderNavigation()
5053
}

Planet/Labs/Published Folders/Dashboard/PFDashboardWindow.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ class PFDashboardWindow: NSWindow {
1212
override init(contentRect: NSRect, styleMask style: NSWindow.StyleMask, backing backingStoreType: NSWindow.BackingStoreType, defer flag: Bool) {
1313
super.init(contentRect: contentRect, styleMask: style, backing: backingStoreType, defer: flag)
1414
self.collectionBehavior = .fullScreenNone
15-
self.title = "Published Folders Dashboard"
1615
self.titlebarAppearsTransparent = false
16+
self.title = "Published Folders Dashboard"
17+
self.subtitle = ""
1718
self.toolbarStyle = .unified
1819
self.contentViewController = PFDashboardContainerViewController()
1920
self.delegate = self

Planet/Labs/Published Folders/Dashboard/PFDashboardWindowController.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ class PFDashboardWindowController: NSWindowController {
2828
NotificationCenter.default.addObserver(forName: .dashboardRefreshToolbar, object: nil, queue: .main) { [weak self] _ in
2929
self?.setupToolbar()
3030
}
31+
NotificationCenter.default.addObserver(forName: .dashboardUpdateWindowTitles, object: nil, queue: .main) { [weak self] n in
32+
guard let titles = n.object as? [String: String] else { return }
33+
if let theTitle = titles["title"], theTitle != "" {
34+
self?.window?.title = theTitle
35+
}
36+
if let theSubtitle = titles["subtitle"], theSubtitle != "" {
37+
self?.window?.subtitle = theSubtitle
38+
}
39+
}
3140
}
3241

3342
required init?(coder: NSCoder) {
@@ -49,18 +58,8 @@ class PFDashboardWindowController: NSWindowController {
4958
toolbar.allowsUserCustomization = false
5059
toolbar.autosavesConfiguration = true
5160
toolbar.displayMode = .iconOnly
52-
w.title = "Published Folders Dashboard"
53-
w.subtitle = ""
5461
w.toolbar = toolbar
5562
w.toolbar?.validateVisibleItems()
56-
let serviceStore = PlanetPublishedServiceStore.shared
57-
if let selectedID = serviceStore.selectedFolderID, let folder = serviceStore.publishedFolders.first(where: { $0.id == selectedID }) {
58-
w.title = folder.url.lastPathComponent
59-
w.subtitle = "Never Published"
60-
if let date = folder.published {
61-
w.subtitle = "Last Published: " + date.relativeDateDescription()
62-
}
63-
}
6463
}
6564

6665
@objc func openInPublicGateway(_ sender: Any) {

Planet/Labs/Published Folders/PlanetPublishedFolders+Extension.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extension CGFloat {
1717
extension Notification.Name {
1818
static let dashboardInspectorIsCollapsedStatusChanged = Notification.Name("PublishedFoldersDashboardInspectorIsCollapsedStatusChangedNotification")
1919
static let dashboardRefreshToolbar = Notification.Name("PublishedFoldersDashboardRefreshToolbarNotification")
20+
static let dashboardUpdateWindowTitles = Notification.Name("PublishedFoldersDashboardUpdateWindowTitlesNotification")
2021
static let dashboardLoadPreviewURL = Notification.Name("PublishedFoldersDashboardLoadPreviewURLNotification")
2122
static let dashboardProcessDirectoryURL = Notification.Name("PublishedFoldersDabhaordProcessDirectoryURLNotification")
2223
static let dashboardResetWebViewHistory = Notification.Name("PublishedFoldersDashboardResetWebViewHistoryNotification")

Planet/Labs/Published Folders/PlanetPublishedServiceStore.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class PlanetPublishedServiceStore: ObservableObject {
3535
NotificationCenter.default.post(name: .dashboardRefreshToolbar, object: nil)
3636
Task { @MainActor in
3737
self.restoreSelectedFolderNavigation()
38+
self.updateWindowTitles()
3839
}
3940
}
4041
}
@@ -80,13 +81,23 @@ class PlanetPublishedServiceStore: ObservableObject {
8081

8182
func restoreSelectedFolderNavigation() {
8283
if let id = selectedFolderID, let folder = publishedFolders.first(where: { $0.id == id }), let _ = folder.published, let publishedLink = folder.publishedLink, let url = URL(string: "\(IPFSDaemon.shared.gateway)/ipns/\(publishedLink)") {
83-
debugPrint("restore navigation for folder: \(folder.url.lastPathComponent)")
8484
NotificationCenter.default.post(name: .dashboardResetWebViewHistory, object: id)
8585
selectedFolderIDChanged = true
8686
NotificationCenter.default.post(name: .dashboardLoadPreviewURL, object: url)
8787
}
8888
}
8989

90+
func updateWindowTitles() {
91+
guard let id = selectedFolderID, let folder = publishedFolders.first(where: { $0.id == id }) else { return }
92+
var titles: [String: String] = [:]
93+
titles["title"] = folder.url.lastPathComponent
94+
titles["subtitle"] = "Never Published"
95+
if let date = folder.published {
96+
titles["subtitle"] = "Last Published: " + date.relativeDateDescription()
97+
}
98+
NotificationCenter.default.post(name: .dashboardUpdateWindowTitles, object: titles)
99+
}
100+
90101
@MainActor
91102
func updateSelectedFolderNavigation(withCurrentURL currentURL: URL, canGoForward: Bool, forwardURL: URL?, canGoBackward: Bool, backwardURL: URL?) {
92103
guard let _ = selectedFolderID else { return }
@@ -236,8 +247,9 @@ class PlanetPublishedServiceStore: ObservableObject {
236247
}
237248
updatePublishedFolders(updatedFolders)
238249
NotificationCenter.default.post(name: .dashboardRefreshToolbar, object: nil)
239-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
250+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
240251
NotificationCenter.default.post(name: .dashboardWebViewGoHome, object: nil)
252+
self?.updateWindowTitles()
241253
}
242254
debugPrint("Folder published -> \(folder.url)")
243255
}

0 commit comments

Comments
 (0)