Skip to content

Commit

Permalink
[macos] Store blobs in .blob instead of NSTemporaryDirectory()
Browse files Browse the repository at this point in the history
  • Loading branch information
atulsmadhugiri committed Oct 7, 2023
1 parent c69fcac commit de58c87
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions macos/plop/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@ func generateFileName(nameLength: Int = 6, fileExtension: String = ".png") -> St
}

func captureScreenshot() -> String {
let temporaryDirectory: String = NSTemporaryDirectory()
let destinationPath = "\(temporaryDirectory)\(generateFileName())"
let temporaryDirectory = URL.homeDirectory.appending(path: ".blob", directoryHint: .isDirectory)

do {
try FileManager().createDirectory(
at: temporaryDirectory,
withIntermediateDirectories: true
)
} catch {
print("Unable to create $HOME/.blob/ directory.")
}

let destinationPath = "\(temporaryDirectory.path())\(generateFileName())"

let screenCaptureTask = Process()
screenCaptureTask.launchPath = "/usr/sbin/screencapture"
Expand All @@ -37,7 +47,8 @@ func uploadBlob(filepath: String) -> (
let destinationRef = storageBucket.child("\(filename)")
let destinationURL = "https://\(GCLOUD_STORAGE_BUCKET)\(filename)"

let uploadTask: StorageUploadTask = destinationRef.putFile(from: URL(fileURLWithPath: filepath)) { _, error in
let uploadTask: StorageUploadTask = destinationRef.putFile(from: URL(fileURLWithPath: filepath)) {
_, error in
if let error {
print("Error uploading file to Google Cloud Storage: \(error)")
}
Expand Down

0 comments on commit de58c87

Please sign in to comment.