mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-28 15:44:32 +00:00
Restored files from old Mac, force pushing
This commit is contained in:
parent
5dd95228b8
commit
5040381840
126 changed files with 10431 additions and 67 deletions
58
DynamicIsland/components/Shelf/DropItem.swift
Normal file
58
DynamicIsland/components/Shelf/DropItem.swift
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
//
|
||||
// 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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue