mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 23:24:32 +00:00
58 lines
1.4 KiB
Swift
58 lines
1.4 KiB
Swift
//
|
|
// TrayDrop+DropItem.swift
|
|
// TrayDrop
|
|
//
|
|
// Created by 秋星桥 on 2024/7/8.
|
|
//
|
|
|
|
import Cocoa
|
|
import Foundation
|
|
import QuickLook
|
|
|
|
extension TrayDrop {
|
|
struct DropItem: Identifiable, Codable, Equatable, Hashable {
|
|
let id: UUID
|
|
|
|
let fileName: String
|
|
let size: Int
|
|
|
|
let copiedDate: Date
|
|
let workspacePreviewImageData: Data
|
|
|
|
init(url: URL) throws {
|
|
assert(!Thread.isMainThread)
|
|
|
|
id = UUID()
|
|
fileName = url.lastPathComponent
|
|
|
|
size = (try? url.resourceValues(forKeys: [.fileSizeKey]))?.fileSize ?? 0
|
|
copiedDate = Date()
|
|
workspacePreviewImageData = url.snapshotPreview().pngRepresentation
|
|
|
|
try FileManager.default.createDirectory(
|
|
at: storageURL.deletingLastPathComponent(),
|
|
withIntermediateDirectories: true
|
|
)
|
|
try FileManager.default.copyItem(at: url, to: storageURL)
|
|
}
|
|
}
|
|
}
|
|
|
|
extension TrayDrop.DropItem {
|
|
static let mainDir = "CopiedItems"
|
|
|
|
var storageURL: URL {
|
|
documentsDirectory
|
|
.appendingPathComponent(Self.mainDir)
|
|
.appendingPathComponent(id.uuidString)
|
|
.appendingPathComponent(fileName)
|
|
}
|
|
|
|
var workspacePreviewImage: NSImage {
|
|
.init(data: workspacePreviewImageData) ?? .init()
|
|
}
|
|
|
|
var shouldClean: Bool { // TODO: In the future clean if old
|
|
return false
|
|
}
|
|
}
|