Skip to content

Commit

Permalink
fix: 优化实现
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertyyb committed Jul 13, 2022
1 parent 9a27e0e commit 632c863
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 67 deletions.
4 changes: 0 additions & 4 deletions Fire.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
45D996AA253C5232001460A8 /* GeneralPane.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45D996A9253C5232001460A8 /* GeneralPane.swift */; };
45DB6EC727E5B8FE00A39925 /* ThemeConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45DB6EC627E5B8FE00A39925 /* ThemeConfig.swift */; };
45DB6EC927E609CB00A39925 /* ThemePane.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45DB6EC827E609CB00A39925 /* ThemePane.swift */; };
45DCE62226A31F140009FED1 /* ApplicationSettingCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45DCE62126A31F140009FED1 /* ApplicationSettingCache.swift */; };
45E85F742573BE1800F71024 /* wb_98_table.txt in Resources */ = {isa = PBXBuildFile; fileRef = 45E85F732573BE1800F71024 /* wb_98_table.txt */; };
45EBB54E283A073000A56CBA /* Statistics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45EBB54D283A073000A56CBA /* Statistics.swift */; };
45EBB550283A311C00A56CBA /* StatisticsPane.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45EBB54F283A311C00A56CBA /* StatisticsPane.swift */; };
Expand Down Expand Up @@ -108,7 +107,6 @@
45D996A9253C5232001460A8 /* GeneralPane.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = GeneralPane.swift; sourceTree = "<group>"; };
45DB6EC627E5B8FE00A39925 /* ThemeConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeConfig.swift; sourceTree = "<group>"; };
45DB6EC827E609CB00A39925 /* ThemePane.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemePane.swift; sourceTree = "<group>"; };
45DCE62126A31F140009FED1 /* ApplicationSettingCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationSettingCache.swift; sourceTree = "<group>"; };
45E85F732573BE1800F71024 /* wb_98_table.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = wb_98_table.txt; sourceTree = "<group>"; };
45EBB54D283A073000A56CBA /* Statistics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Statistics.swift; sourceTree = "<group>"; };
45EBB54F283A311C00A56CBA /* StatisticsPane.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatisticsPane.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -277,7 +275,6 @@
673C417125468FFA00F462A3 /* ModifierKeyUpChecker.swift */,
673C4177254697E400F462A3 /* TipsWindow.swift */,
677A0873254BD47D000B58D4 /* ToastWindow.swift */,
45DCE62126A31F140009FED1 /* ApplicationSettingCache.swift */,
45EBB54D283A073000A56CBA /* Statistics.swift */,
);
path = Utils;
Expand Down Expand Up @@ -495,7 +492,6 @@
45577EB4254576720064325B /* FirePreferencesController.swift in Sources */,
450B7D9A26A2847D00808A4D /* ApplicationPane.swift in Sources */,
4500AC68287036CB006F3FCC /* DictManager.swift in Sources */,
45DCE62226A31F140009FED1 /* ApplicationSettingCache.swift in Sources */,
459DE990232EB26600A3ACD1 /* CandidatesView.swift in Sources */,
45DB6EC727E5B8FE00A39925 /* ThemeConfig.swift in Sources */,
453377E52849E76A0064E4F2 /* StatusBar.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Fire.xcodeproj/xcshareddata/xcschemes/Fire.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "# Type a script or drag a script file from your workspace to insert its path.&#10;pkill Fire&#10;">
scriptText = "# Type a script or drag a script file from your workspace to insert its path.&#10;pkill -9 Fire&#10;">
</ActionContent>
</ExecutionAction>
</PreActions>
Expand Down
2 changes: 0 additions & 2 deletions Fire/Fire.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class Fire: NSObject {
static let candidateInserted = Notification.Name("Fire.candidateInserted")
static let inputModeChanged = Notification.Name("Fire.inputModeChanged")

let appSettingCache = ApplicationSettingCache()

var inputMode: InputMode = .zhhans

func transformPunctution(_ origin: String)-> String? {
Expand Down
38 changes: 16 additions & 22 deletions Fire/FireInputServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,32 @@
import Foundation
import Defaults

var previousClientIdentifier: String = ""
private var previousClientIdentifier: String = ""
private var inputModeCache: [String: InputMode] = [:]

extension FireInputController {
/**
* 根据当前输入的应用改变输入模式
*/
private func activeCurrentClientInputMode() {
guard let identifier = client()?.bundleIdentifier() else { return }
if let appSetting = Defaults[.appSettings][identifier],
let mode = InputMode(rawValue: appSetting.inputModeSetting.rawValue) {
print("[FireInputController] activeClientInputMode from setting : \(identifier), \(mode)")
Fire.shared.toggleInputMode(mode)
return
}
if !Defaults[.keepAppInputMode] { return }
// 启用APP缓存设置
if let appSetting = Fire.shared.appSettingCache.get(bundleIdentifier: identifier),
guard let identifier = client()?.bundleIdentifier() else { return }
if let appSetting = Defaults[.appSettings][identifier],
let mode = InputMode(rawValue: appSetting.inputModeSetting.rawValue) {
print("[FireInputController] activeClientInputMode from setting : \(identifier), \(mode)")
Fire.shared.toggleInputMode(mode)
return
}
// 启用APP缓存设置
if Defaults[.keepAppInputMode], let mode = inputModeCache[identifier] {
print("[FireInputController] activeClientInputMode from cache: \(identifier), \(mode)")
Fire.shared.toggleInputMode(mode)
}
}

private func savePreviousClientInputMode() {
if previousClientIdentifier.count > 0 {
// 缓存当前输入模式
Fire.shared.appSettingCache.add(
bundleIdentifier: previousClientIdentifier,
setting: ApplicationSettingItem(
bundleId: previousClientIdentifier,
inputMs: InputModeSetting(rawValue: inputMode.rawValue)!
)
)
// 缓存当前输入模式
inputModeCache.updateValue(inputMode, forKey: previousClientIdentifier)
}
}

Expand All @@ -64,14 +57,15 @@ extension FireInputController {
}

/**
* 由于使用recognizedEvents在一些场景下不能监听到flagChanged事件,比如保存文件场景
* 所以这里需要使用NSEvent.addGlobalMonitorForEvents监听shift键被按下
* 1. 由于使用recognizedEvents在一些场景下不能监听到flagChanged事件,比如保存文件场景
* 所以这里需要使用NSEvent.addGlobalMonitorForEvents监听shift键被按下
* 2. 当client变化时,deactiveServer 和 activeServer 的执行是不固定的,有可能 activeServer 先执行,所以需要在activeServer中执行清理逻辑
*/
override func activateServer(_ sender: Any!) {
NSLog("[FireInputController] activate server: \(client()?.bundleIdentifier() ?? sender.debugDescription)")

previousClientHandler()

if let identifier = client()?.bundleIdentifier() {
previousClientIdentifier = identifier
}
Expand Down
38 changes: 0 additions & 38 deletions Fire/Utils/ApplicationSettingCache.swift

This file was deleted.

0 comments on commit 632c863

Please sign in to comment.