Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application support path fix #60

Merged
merged 2 commits into from Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Diffusion-macOS/ControlsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ struct ControlsView: View {
DispatchQueue.main.async {
switch state {
case .downloading(let progress):
print("\(loader.model.modelVersion): \(progress)")
pipelineState = .downloading(progress)
case .uncompressing:
pipelineState = .uncompressing
Expand Down Expand Up @@ -383,7 +382,6 @@ struct ControlsView: View {
}
.padding()
.onAppear {
print(PipelineLoader.models)
modelDidChange(model: ModelInfo.from(modelVersion: model) ?? ModelInfo.v2Base)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Diffusion/Common/Pipeline/Pipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Pipeline {
) throws -> GenerationResult {
let beginDate = Date()
canceled = false
print("Generating...")

let theSeed = seed ?? UInt32.random(in: 0...maxSeed)
let sampleTimer = SampleTimer()
sampleTimer.start()
Expand Down
2 changes: 1 addition & 1 deletion Diffusion/Common/Pipeline/PipelineLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ZIPFoundation
import StableDiffusion

class PipelineLoader {
static let models = URL.applicationSupportDirectory.appendingPathComponent("hf-diffusion-models")
static let models = Settings.shared.applicationSupportURL().appendingPathComponent("hf-diffusion-models")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

let model: ModelInfo
let computeUnits: ComputeUnits
let maxSeed: UInt32
Expand Down
18 changes: 18 additions & 0 deletions Diffusion/Common/State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,22 @@ class Settings {
return ComputeUnits(rawValue: current)
}
}

public func applicationSupportURL() -> URL {
let fileManager = FileManager.default
guard let appDirectoryURL = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first else {
// To ensure we don't return an optional - if the user domain application support cannot be accessed use the top level application support directory
return URL.applicationSupportDirectory
}

do {
// Create the application support directory if it doesn't exist
try fileManager.createDirectory(at: appDirectoryURL, withIntermediateDirectories: true, attributes: nil)
return appDirectoryURL
} catch {
print("Error creating application support directory: \(error)")
return fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
}
}

}