Skip to content

Commit

Permalink
change log dir to temp/rime.squirrel
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Jun 6, 2024
1 parent 9e477f0 commit 4c634f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions sources/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct SquirrelApp {
static let appDir = "/Library/Input Library/Squirrel.app".withCString { dir in
URL(fileURLWithFileSystemRepresentation: dir, isDirectory: false, relativeTo: nil)
}
static let logDir = FileManager.default.temporaryDirectory.appending(component: "rime.squirrel", directoryHint: .isDirectory)

// swiftlint:disable:next cyclomatic_complexity
static func main() {
Expand Down
28 changes: 16 additions & 12 deletions sources/SquirrelApplicationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ final class SquirrelApplicationDelegate: NSObject, NSApplicationDelegate, SPUSta
}

func openLogFolder() {
let logDir = FileManager.default.temporaryDirectory
NSWorkspace.shared.open(logDir)
NSWorkspace.shared.open(SquirrelApp.logDir)
}

func openRimeFolder() {
Expand Down Expand Up @@ -124,15 +123,8 @@ final class SquirrelApplicationDelegate: NSObject, NSApplicationDelegate, SPUSta
}

func setupRime() {
let userDataDir = SquirrelApp.userDir
let fileManager = FileManager.default
if !fileManager.fileExists(atPath: userDataDir.path()) {
do {
try fileManager.createDirectory(at: userDataDir, withIntermediateDirectories: true)
} catch {
print("Error creating user data directory: \(userDataDir.path())")
}
}
createDirIfNotExist(path: SquirrelApp.userDir)
createDirIfNotExist(path: SquirrelApp.logDir)
// swiftlint:disable identifier_name
let notification_handler: @convention(c) (UnsafeMutableRawPointer?, RimeSessionId, UnsafePointer<CChar>?, UnsafePointer<CChar>?) -> Void = notificationHandler
let context_object = Unmanaged.passUnretained(self).toOpaque()
Expand All @@ -141,7 +133,8 @@ final class SquirrelApplicationDelegate: NSObject, NSApplicationDelegate, SPUSta

var squirrelTraits = RimeTraits.rimeStructInit()
squirrelTraits.setCString(Bundle.main.sharedSupportPath!, to: \.shared_data_dir)
squirrelTraits.setCString(userDataDir.path(), to: \.user_data_dir)
squirrelTraits.setCString(SquirrelApp.userDir.path(), to: \.user_data_dir)
squirrelTraits.setCString(SquirrelApp.logDir.path(), to: \.log_dir)
squirrelTraits.setCString("Squirrel", to: \.distribution_code_name)
squirrelTraits.setCString("鼠鬚管", to: \.distribution_name)
squirrelTraits.setCString(Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String, to: \.distribution_version)
Expand Down Expand Up @@ -313,6 +306,17 @@ private extension SquirrelApplicationDelegate {
print("Sync rime on demand.")
self.syncUserData()
}

func createDirIfNotExist(path: URL) {
let fileManager = FileManager.default
if !fileManager.fileExists(atPath: path.path()) {
do {
try fileManager.createDirectory(at: path, withIntermediateDirectories: true)
} catch {
print("Error creating user data directory: \(path.path())")
}
}
}
}

extension NSApplication {
Expand Down

0 comments on commit 4c634f1

Please sign in to comment.