2026-09-19 15:52:16 +02:00
|
|
|
//
|
|
|
|
|
// ClipboardService.swift
|
2026-09-20 15:05:19 +02:00
|
|
|
// KeeVault
|
2026-09-19 15:52:16 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
#if os(iOS)
|
|
|
|
|
import UIKit
|
|
|
|
|
#else
|
|
|
|
|
import AppKit
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
public enum ClipboardService {
|
|
|
|
|
public static func copy(_ text: String, expiresAfter seconds: TimeInterval = 30) {
|
|
|
|
|
#if os(iOS)
|
|
|
|
|
UIPasteboard.general.setItems(
|
|
|
|
|
[[UIPasteboard.typeAutomatic: text]],
|
|
|
|
|
options: [.expirationDate: Date().addingTimeInterval(seconds)]
|
|
|
|
|
)
|
|
|
|
|
#else
|
|
|
|
|
let pb = NSPasteboard.general
|
|
|
|
|
pb.clearContents()
|
|
|
|
|
pb.setString(text, forType: .string)
|
|
|
|
|
let captured = text
|
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
|
|
|
|
|
if pb.string(forType: .string) == captured { pb.clearContents() }
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|