Skip to content

Commit

Permalink
Quick rebuild: only index.html is built
Browse files Browse the repository at this point in the history
  • Loading branch information
livid committed Oct 29, 2023
1 parent d54a1d7 commit 9f44965
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
54 changes: 54 additions & 0 deletions Planet/Entities/MyPlanetModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2236,6 +2236,60 @@ class MyPlanetModel: Equatable, Hashable, Identifiable, ObservableObject, Codabl
await sendNotificationForRebuild()
}

func quickRebuild() async throws {
let started = Date()
await MainActor.run {
self.isRebuilding = true
}
defer {
Task { @MainActor in
self.isRebuilding = false
PlanetStatusManager.shared.updateStatus()
}
}
Task { @MainActor in
PlanetStore.shared.isRebuilding = true
PlanetStore.shared.rebuildTasks = 2
PlanetStatusManager.shared.updateStatus()
}
try self.copyTemplateAssets()
Task { @MainActor in
PlanetStore.shared.rebuildTasks = 1
NotificationCenter.default.post(name: .myArticleBuilt, object:nil)
}
try await self.savePublic()
await MainActor.run {
self.isRebuilding = false
}
Task { @MainActor in
PlanetStore.shared.isRebuilding = false
}
Task {
do {
try self.saveOps()
}
catch {
debugPrint("failed to save ops to file: \(error)")
}
}
Task { @MainActor in
PlanetStore.shared.rebuildTasks = 0
NotificationCenter.default.post(name: .myArticleBuilt, object:nil)
}
let ended = Date()
let timeInterval = ended.timeIntervalSince(started)
debugPrint("Quick Rebuild planet: \(name) took \(timeInterval) seconds")
NotificationCenter.default.post(name: .loadArticle, object: nil)
Task { @MainActor in
NotificationCenter.default.post(name: .publishMyPlanet, object: self)
// Update Planet Lite Window Titles
let liteSubtitle = "ipns://\(self.ipns.shortIPNS())"
let info = ["title": self.name, "subtitle": liteSubtitle]
NotificationCenter.default.post(name: .updatePlanetLiteWindowTitles, object: info)
}
await sendNotificationForRebuild()
}

func sendNotificationForRebuild() async {
let notification = UNMutableNotificationContent()
notification.title = "Planet Rebuilt"
Expand Down
24 changes: 21 additions & 3 deletions Planet/Helper/KeyboardShortcutHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class KeyboardShortcutHelper: ObservableObject {
Text("Connect Wallet V2")
}
}

if PlanetStore.shared.app == .planet {
Divider()
Button {
Expand Down Expand Up @@ -181,7 +181,7 @@ class KeyboardShortcutHelper: ObservableObject {
} label: {
Text("Update Following Planets")
}
.keyboardShortcut("r", modifiers: [.command, .shift])
.keyboardShortcut("u", modifiers: [.command, .shift])

Divider()
}
Expand All @@ -207,6 +207,24 @@ class KeyboardShortcutHelper: ObservableObject {
}
.disabled(URLUtils.repoPath() == URLUtils.defaultRepoPath)

Button {
Task(priority: .background) {
do {
try await self.activeMyPlanet?.quickRebuild()
} catch {
Task { @MainActor in
PlanetStore.shared.isShowingAlert = true
PlanetStore.shared.alertTitle = "Failed to Quick Rebuild Planet"
PlanetStore.shared.alertMessage = error.localizedDescription
}
}
}
} label: {
Text("Quick Rebuild Planet")
}
.disabled(activeMyPlanet == nil)
.keyboardShortcut("r", modifiers: [.command, .shift])

Button {
Task(priority: .background) {
do {
Expand Down Expand Up @@ -238,7 +256,7 @@ class KeyboardShortcutHelper: ObservableObject {
}
}
}

func importPlanetAction() {
let panel = NSOpenPanel()
panel.message = "Choose Planet Data"
Expand Down
1 change: 1 addition & 0 deletions Planet/Views/My/RebuildProgressView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct RebuildProgressView: View {
}
Spacer()
Text("\(completed)/\(total) items done")
// TODO: - use a better signal to update progress
.onReceive(NotificationCenter.default.publisher(for: .myArticleBuilt)) {
aNotification in
Task { @MainActor in
Expand Down
20 changes: 19 additions & 1 deletion Planet/Views/Sidebar/MyPlanetSidebarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,24 @@ struct MyPlanetSidebarItem: View {
}
}

Button {
do {
Task(priority: .background) {
try await planet.quickRebuild()
}
}
catch {
Task { @MainActor in
self.planetStore.isShowingAlert = true
self.planetStore.alertTitle = "Failed to Quick Rebuild Planet"
self.planetStore.alertMessage = error.localizedDescription
}
}
} label: {
Text("Quick Rebuild")
}
.keyboardShortcut("r", modifiers: [.command, .shift])

Button {
do {
Task(priority: .background) {
Expand All @@ -334,7 +352,7 @@ struct MyPlanetSidebarItem: View {
}
}
} label: {
Text("Rebuild")
Text("Full Rebuild")
}
.keyboardShortcut("r", modifiers: [.command])

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 = 1751
CURRENT_PROJECT_VERSION = 1752

0 comments on commit 9f44965

Please sign in to comment.