Skip to content

Commit

Permalink
feat: SidebarModel+Queue
Browse files Browse the repository at this point in the history
  • Loading branch information
buzsh committed Mar 8, 2024
1 parent 652f082 commit 1049927
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
4 changes: 4 additions & 0 deletions SwiftDiffusion.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
2975DF142B8C08800031690E /* VaeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2975DF132B8C08800031690E /* VaeModel.swift */; };
2975DF162B8C0BAB0031690E /* VaeModelMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2975DF152B8C0BAB0031690E /* VaeModelMenu.swift */; };
2991FDD92B9BC38800D553F6 /* PromptBarButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2991FDD82B9BC38800D553F6 /* PromptBarButton.swift */; };
2991FDDC2B9BC5EC00D553F6 /* SidebarModel+Queue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2991FDDB2B9BC5EC00D553F6 /* SidebarModel+Queue.swift */; };
29949F252B9655F4004F8D60 /* SidebarModel+Delete.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29949F242B9655F4004F8D60 /* SidebarModel+Delete.swift */; };
29949F272B965E49004F8D60 /* SidebarModel+Create.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29949F262B965E49004F8D60 /* SidebarModel+Create.swift */; };
2996D0942B6ED5B000B487D5 /* SwiftDiffusionApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2996D0932B6ED5B000B487D5 /* SwiftDiffusionApp.swift */; };
Expand Down Expand Up @@ -240,6 +241,7 @@
2975DF132B8C08800031690E /* VaeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VaeModel.swift; sourceTree = "<group>"; };
2975DF152B8C0BAB0031690E /* VaeModelMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VaeModelMenu.swift; sourceTree = "<group>"; };
2991FDD82B9BC38800D553F6 /* PromptBarButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromptBarButton.swift; sourceTree = "<group>"; };
2991FDDB2B9BC5EC00D553F6 /* SidebarModel+Queue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SidebarModel+Queue.swift"; sourceTree = "<group>"; };
29949F242B9655F4004F8D60 /* SidebarModel+Delete.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SidebarModel+Delete.swift"; sourceTree = "<group>"; };
29949F262B965E49004F8D60 /* SidebarModel+Create.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SidebarModel+Create.swift"; sourceTree = "<group>"; };
2996D0902B6ED5B000B487D5 /* SwiftDiffusion.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftDiffusion.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -607,6 +609,7 @@
29949F242B9655F4004F8D60 /* SidebarModel+Delete.swift */,
293BC4E32B9A6C1400C9DEBF /* SidebarModel+Move.swift */,
293BC4E72B9A71C200C9DEBF /* SidebarModel+Save.swift */,
2991FDDB2B9BC5EC00D553F6 /* SidebarModel+Queue.swift */,
);
path = SidebarModel;
sourceTree = "<group>";
Expand Down Expand Up @@ -1286,6 +1289,7 @@
29C0F3712B7A62180017DD6B /* WindowManager.swift in Sources */,
2952F5052B8639FD00CB8679 /* CheckpointApiModel.swift in Sources */,
29FA4EAC2B9B5DDD007205C8 /* SFSymbol+SwiftUI.swift in Sources */,
2991FDDC2B9BC5EC00D553F6 /* SidebarModel+Queue.swift in Sources */,
29C0F3802B7ABF050017DD6B /* GeneralSection.swift in Sources */,
29D362392B72E59F006C57B3 /* FileUtility.swift in Sources */,
295894332B9ACA250013B6BB /* PasteGenerationDataButton.swift in Sources */,
Expand Down
33 changes: 9 additions & 24 deletions SwiftDiffusion/Views/MainViews/ContentView/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ struct ContentView: View {
.onChange(of: columnVisibility) {
sidebarModel.sidebarIsVisible = (columnVisibility != .doubleColumn)
}
.onChange(of: userSettings.outputDirectoryPath) {
if let directoryPath = userSettings.outputDirectoryUrl?.path {
fileHierarchy.rootPath = directoryPath
Task { await fileHierarchy.refresh() }
}
}
.toolbar {
ToolbarItemGroup(placement: .navigation) {
HStack {
Expand Down Expand Up @@ -133,6 +127,12 @@ struct ContentView: View {
}) {
RequiredInputPathsView()
}
.onChange(of: userSettings.outputDirectoryPath) {
if let directoryPath = userSettings.outputDirectoryUrl?.path {
fileHierarchy.rootPath = directoryPath
Task { await fileHierarchy.refresh() }
}
}
.onChange(of: userSettings.automaticDirectoryPath) {
handleScriptOnLaunch()
}
Expand All @@ -148,7 +148,7 @@ struct ContentView: View {
imageCountToGenerate = Int(currentPrompt.batchSize * currentPrompt.batchCount)

} else if scriptManager.genStatus == .done {
imagesDidGenerateSuccessfully()
imagesGeneratedSuccessfully()

}
}
Expand All @@ -160,14 +160,9 @@ struct ContentView: View {

}

func imagesDidGenerateSuccessfully() {
func imagesGeneratedSuccessfully() {
NotificationUtility.showCompletionNotification(imageCount: imageCountToGenerate)

if let storableSidebarItem = sidebarModel.currentlyGeneratingSidebarItem {
sidebarModel.addToStorableSidebarItems(sidebarItem: storableSidebarItem, withImageUrls: lastSavedImageUrls)
sidebarModel.currentlyGeneratingSidebarItem = nil
}

sidebarModel.generatingSidebarItemFinished(withImageUrls: lastSavedImageUrls)
Task {
await fileHierarchy.refresh()
}
Expand All @@ -177,14 +172,6 @@ struct ContentView: View {
return !userSettings.automaticDirectoryPath.isEmpty && !userSettings.webuiShellPath.isEmpty
}

private func loadLastSelectedImage() async {
if !lastSelectedImagePath.isEmpty, let image = NSImage(contentsOfFile: lastSelectedImagePath) {
await MainActor.run {
self.selectedImage = image
}
}
}

func checkForUpdatesIfAutomaticUpdatesAreEnabled() {
Task {
await updateManager.checkForUpdatesIfNeeded()
Expand All @@ -194,7 +181,6 @@ struct ContentView: View {
}
}
}

}

#Preview {
Expand Down Expand Up @@ -239,7 +225,6 @@ extension ContentView {
}
Task {
await fileHierarchy.refresh()
await loadLastSelectedImage()
}

if !CanvasPreview && !userHasEnteredBothRequiredFields && hasLaunchedBefore {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// SidebarModel+Queue.swift
// SwiftDiffusion
//
// Created by Justin Bush on 3/8/24.
//

import Foundation

extension SidebarModel {
func addToStorableSidebarItems(sidebarItem: SidebarItem, withImageUrls imageUrls: [URL]) {
sidebarItem.imageUrls = imageUrls
storableSidebarItems.append(sidebarItem)
}

func generatingSidebarItemFinished(withImageUrls imageUrls: [URL]) {
guard let sidebarItem = currentlyGeneratingSidebarItem else {
return
}

addToStorableSidebarItems(sidebarItem: sidebarItem, withImageUrls: imageUrls)
currentlyGeneratingSidebarItem = nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ class SidebarModel: ObservableObject {
func setSelectedSidebarItem(to sidebarItem: SidebarItem?) {
selectedItemID = sidebarItem?.id
}

func addToStorableSidebarItems(sidebarItem: SidebarItem, withImageUrls imageUrls: [URL]) {
sidebarItem.imageUrls = imageUrls
storableSidebarItems.append(sidebarItem)
}

func workspaceFolderContainsSelectedSidebarItem() -> Bool {
workspaceFolderContains(sidebarItem: selectedSidebarItem)
Expand Down

0 comments on commit 1049927

Please sign in to comment.