mirror of
https://github.com/tw93/Mole.git
synced 2026-02-11 02:29:19 +00:00
feat: Add VS Code launch/task configurations and refactor app icon and resource management.
This commit is contained in:
37
app/KeychainHelper.swift
Normal file
37
app/KeychainHelper.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
import Foundation
|
||||
|
||||
// Note: Switched to File-based storage to avoid repetitive System Keychain prompts
|
||||
// during development (Unsigned Binary). Files are set to 600 layout (User Only).
|
||||
class KeychainHelper {
|
||||
static let shared = KeychainHelper()
|
||||
|
||||
private var storeURL: URL {
|
||||
let home = FileManager.default.homeDirectoryForCurrentUser
|
||||
return home.appendingPathComponent(".mole").appendingPathComponent(".key")
|
||||
}
|
||||
|
||||
func save(_ data: String) {
|
||||
let url = storeURL
|
||||
do {
|
||||
try FileManager.default.createDirectory(
|
||||
at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
|
||||
try data.write(to: url, atomically: true, encoding: .utf8)
|
||||
// Set permissions to User Read/Write Only (600) for security
|
||||
try FileManager.default.setAttributes([.posixPermissions: 0o600], ofItemAtPath: url.path)
|
||||
} catch {
|
||||
print("Failed to save credentials: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func load() -> String? {
|
||||
do {
|
||||
return try String(contentsOf: storeURL, encoding: .utf8)
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func delete() {
|
||||
try? FileManager.default.removeItem(at: storeURL)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user