Shiki: OOBE // Write certain default values to user plist if nil.
This commit is contained in:
parent
00a6b36e5a
commit
05b8e05b29
|
@ -68,11 +68,12 @@ class AppDelegate: NSObject, NSApplicationDelegate,
|
||||||
LanguageModelManager.loadDataModels()
|
LanguageModelManager.loadDataModels()
|
||||||
LanguageModelManager.loadUserPhrasesModel()
|
LanguageModelManager.loadUserPhrasesModel()
|
||||||
|
|
||||||
if UserDefaults.standard.object(forKey: kCheckUpdateAutomatically) == nil {
|
OOBE.setMissingDefaults()
|
||||||
UserDefaults.standard.set(false, forKey: kCheckUpdateAutomatically)
|
|
||||||
UserDefaults.standard.synchronize()
|
// 只要使用者沒有勾選檢查更新、沒有主動做出要檢查更新的操作,就不要檢查更新。
|
||||||
|
if (UserDefaults.standard.object(forKey: kCheckUpdateAutomatically) != nil) == true {
|
||||||
|
checkForUpdate()
|
||||||
}
|
}
|
||||||
checkForUpdate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func showPreferences() {
|
@objc func showPreferences() {
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
//
|
||||||
|
// clsOOBEDefaults.swift
|
||||||
|
//
|
||||||
|
// Copyright (c) 2021-2022 The vChewing Project.
|
||||||
|
//
|
||||||
|
// Contributors:
|
||||||
|
// Shiki Suen (@ShikiSuen) @ vChewing
|
||||||
|
//
|
||||||
|
// Based on the Syrup Project and the Formosana Library
|
||||||
|
// by Lukhnos Liu (@lukhnos).
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person
|
||||||
|
// obtaining a copy of this software and associated documentation
|
||||||
|
// files (the "Software"), to deal in the Software without
|
||||||
|
// restriction, including without limitation the rights to use,
|
||||||
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the
|
||||||
|
// Software is furnished to do so, subject to the following
|
||||||
|
// conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
|
private let kCheckUpdateAutomatically = "CheckUpdateAutomatically"
|
||||||
|
private let kCandidateListTextSize = "CandidateListTextSize"
|
||||||
|
private let kChooseCandidateUsingSpaceKey = "ChooseCandidateUsingSpaceKey"
|
||||||
|
private let kSelectPhraseAfterCursorAsCandidate = "SelectPhraseAfterCursorAsCandidate"
|
||||||
|
private let kUseHorizontalCandidateList = "UseHorizontalCandidateList"
|
||||||
|
private let kChineseConversionEnabledKey = "ChineseConversionEnabled"
|
||||||
|
|
||||||
|
@objc public class OOBE : NSObject {
|
||||||
|
|
||||||
|
@objc public static func setMissingDefaults () {
|
||||||
|
// 既然 Preferences Module 的預設屬性不自動寫入 plist、而且還是 private,那這邊就先寫入了。
|
||||||
|
|
||||||
|
// 首次啟用輸入法時設定不要自動更新,免得在某些要隔絕外部網路連線的保密機構內觸犯資安規則。
|
||||||
|
if UserDefaults.standard.object(forKey: kCheckUpdateAutomatically) == nil {
|
||||||
|
UserDefaults.standard.set(false, forKey: kCheckUpdateAutomatically)
|
||||||
|
UserDefaults.standard.synchronize()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 預設選字窗字詞文字尺寸,設成 18 剛剛好
|
||||||
|
if UserDefaults.standard.object(forKey: kCandidateListTextSize) == nil {
|
||||||
|
UserDefaults.standard.set(Preferences.candidateListTextSize, forKey: kCandidateListTextSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 預設摁空格鍵來選字,所以設成 true
|
||||||
|
if UserDefaults.standard.object(forKey: kChooseCandidateUsingSpaceKey) == nil {
|
||||||
|
UserDefaults.standard.set(Preferences.chooseCandidateUsingSpace, forKey: kChooseCandidateUsingSpaceKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 預設漢音風格選字,所以要設成 0
|
||||||
|
if UserDefaults.standard.object(forKey: kSelectPhraseAfterCursorAsCandidate) == nil {
|
||||||
|
UserDefaults.standard.set(Preferences.selectPhraseAfterCursorAsCandidate, forKey: kSelectPhraseAfterCursorAsCandidate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 預設橫向選字窗,不爽請自行改成縱向選字窗
|
||||||
|
if UserDefaults.standard.object(forKey: kUseHorizontalCandidateList) == nil {
|
||||||
|
UserDefaults.standard.set(Preferences.useHorizontalCandidateList, forKey: kUseHorizontalCandidateList)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 預設停用繁體轉康熙模組
|
||||||
|
if UserDefaults.standard.object(forKey: kChineseConversionEnabledKey) == nil {
|
||||||
|
UserDefaults.standard.set(Preferences.chineseConversionEnabled, forKey: kChineseConversionEnabledKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
UserDefaults.standard.synchronize()
|
||||||
|
}
|
||||||
|
}
|
|
@ -195,6 +195,10 @@ static double FindHighestScore(const vector<NodeAnchor>& nodes, double epsilon)
|
||||||
|
|
||||||
- (void)activateServer:(id)client
|
- (void)activateServer:(id)client
|
||||||
{
|
{
|
||||||
|
// Write missing OOBE user plist entries.
|
||||||
|
[OOBE setMissingDefaults];
|
||||||
|
|
||||||
|
// Read user plist.
|
||||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||||
|
|
||||||
// Override the keyboard layout. Use US if not set.
|
// Override the keyboard layout. Use US if not set.
|
||||||
|
@ -1470,6 +1474,9 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
|
|
||||||
- (void)showPreferences:(id)sender
|
- (void)showPreferences:(id)sender
|
||||||
{
|
{
|
||||||
|
// Write missing OOBE user plist entries.
|
||||||
|
[OOBE setMissingDefaults];
|
||||||
|
|
||||||
// show the preferences panel, and also make the IME app itself the focus
|
// show the preferences panel, and also make the IME app itself the focus
|
||||||
if ([IMKInputController instancesRespondToSelector:@selector(showPreferences:)]) {
|
if ([IMKInputController instancesRespondToSelector:@selector(showPreferences:)]) {
|
||||||
[super showPreferences:sender];
|
[super showPreferences:sender];
|
||||||
|
|
|
@ -214,7 +214,7 @@ struct ComposingKeys {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: -
|
// MARK: -
|
||||||
class Preferences: NSObject {
|
@objc public class Preferences: NSObject {
|
||||||
@UserDefault(key: kKeyboardLayoutPreferenceKey, defaultValue: 0)
|
@UserDefault(key: kKeyboardLayoutPreferenceKey, defaultValue: 0)
|
||||||
@objc static var keyboardLayout: Int
|
@objc static var keyboardLayout: Int
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ class Preferences: NSObject {
|
||||||
@UserDefault(key: kSelectPhraseAfterCursorAsCandidatePreferenceKey, defaultValue: false)
|
@UserDefault(key: kSelectPhraseAfterCursorAsCandidatePreferenceKey, defaultValue: false)
|
||||||
@objc static var selectPhraseAfterCursorAsCandidate: Bool
|
@objc static var selectPhraseAfterCursorAsCandidate: Bool
|
||||||
|
|
||||||
@UserDefault(key: kUseHorizontalCandidateListPreferenceKey, defaultValue: false)
|
@UserDefault(key: kUseHorizontalCandidateListPreferenceKey, defaultValue: true)
|
||||||
@objc static var useHorizontalCandidateList: Bool
|
@objc static var useHorizontalCandidateList: Bool
|
||||||
|
|
||||||
@ComposingBufferSize(key: kComposingBufferSizePreferenceKey)
|
@ComposingBufferSize(key: kComposingBufferSizePreferenceKey)
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
5BC3EE1C278FC48C00F5E44C /* VTCandidateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC3EE19278FC48C00F5E44C /* VTCandidateController.swift */; };
|
5BC3EE1C278FC48C00F5E44C /* VTCandidateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC3EE19278FC48C00F5E44C /* VTCandidateController.swift */; };
|
||||||
5BC3EE1D278FC48C00F5E44C /* HorizontalCandidateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC3EE1A278FC48C00F5E44C /* HorizontalCandidateController.swift */; };
|
5BC3EE1D278FC48C00F5E44C /* HorizontalCandidateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC3EE1A278FC48C00F5E44C /* HorizontalCandidateController.swift */; };
|
||||||
5BC3FB83278492DE0022E99A /* data-chs.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5BC3FB82278492DE0022E99A /* data-chs.txt */; };
|
5BC3FB83278492DE0022E99A /* data-chs.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5BC3FB82278492DE0022E99A /* data-chs.txt */; };
|
||||||
|
5BD0D1A4279463510008F48E /* clsOOBEDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BD0D1A3279463510008F48E /* clsOOBEDefaults.swift */; };
|
||||||
5BDF2CFE2791BE4400838ADB /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2CFD2791BE4400838ADB /* InputSourceHelper.swift */; };
|
5BDF2CFE2791BE4400838ADB /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2CFD2791BE4400838ADB /* InputSourceHelper.swift */; };
|
||||||
5BDF2CFF2791BECC00838ADB /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2CFD2791BE4400838ADB /* InputSourceHelper.swift */; };
|
5BDF2CFF2791BECC00838ADB /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2CFD2791BE4400838ADB /* InputSourceHelper.swift */; };
|
||||||
5BDF2D012791C03B00838ADB /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2D002791C03B00838ADB /* PreferencesWindowController.swift */; };
|
5BDF2D012791C03B00838ADB /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2D002791C03B00838ADB /* PreferencesWindowController.swift */; };
|
||||||
|
@ -113,6 +114,7 @@
|
||||||
5BC3EE19278FC48C00F5E44C /* VTCandidateController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VTCandidateController.swift; sourceTree = "<group>"; };
|
5BC3EE19278FC48C00F5E44C /* VTCandidateController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VTCandidateController.swift; sourceTree = "<group>"; };
|
||||||
5BC3EE1A278FC48C00F5E44C /* HorizontalCandidateController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HorizontalCandidateController.swift; sourceTree = "<group>"; };
|
5BC3EE1A278FC48C00F5E44C /* HorizontalCandidateController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HorizontalCandidateController.swift; sourceTree = "<group>"; };
|
||||||
5BC3FB82278492DE0022E99A /* data-chs.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "data-chs.txt"; sourceTree = "<group>"; };
|
5BC3FB82278492DE0022E99A /* data-chs.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "data-chs.txt"; sourceTree = "<group>"; };
|
||||||
|
5BD0D1A3279463510008F48E /* clsOOBEDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = clsOOBEDefaults.swift; sourceTree = "<group>"; };
|
||||||
5BDF2CFD2791BE4400838ADB /* InputSourceHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputSourceHelper.swift; sourceTree = "<group>"; };
|
5BDF2CFD2791BE4400838ADB /* InputSourceHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputSourceHelper.swift; sourceTree = "<group>"; };
|
||||||
5BDF2D002791C03B00838ADB /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
|
5BDF2D002791C03B00838ADB /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
|
||||||
5BDF2D022791C71200838ADB /* NonModalAlertWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonModalAlertWindowController.swift; sourceTree = "<group>"; };
|
5BDF2D022791C71200838ADB /* NonModalAlertWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonModalAlertWindowController.swift; sourceTree = "<group>"; };
|
||||||
|
@ -272,6 +274,7 @@
|
||||||
5BC2D2842793B434002C0BEC /* KeyValueBlobReader.h */,
|
5BC2D2842793B434002C0BEC /* KeyValueBlobReader.h */,
|
||||||
5BC2D2852793B434002C0BEC /* CMakeLists.txt */,
|
5BC2D2852793B434002C0BEC /* CMakeLists.txt */,
|
||||||
5BC2D2862793B434002C0BEC /* KeyValueBlobReader.cpp */,
|
5BC2D2862793B434002C0BEC /* KeyValueBlobReader.cpp */,
|
||||||
|
5BD0D1A3279463510008F48E /* clsOOBEDefaults.swift */,
|
||||||
);
|
);
|
||||||
path = vChewing;
|
path = vChewing;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -715,6 +718,7 @@
|
||||||
5BDF2D062791DFF200838ADB /* AppDelegate.swift in Sources */,
|
5BDF2D062791DFF200838ADB /* AppDelegate.swift in Sources */,
|
||||||
5BC3EE1B278FC48C00F5E44C /* VerticalCandidateController.swift in Sources */,
|
5BC3EE1B278FC48C00F5E44C /* VerticalCandidateController.swift in Sources */,
|
||||||
5B42B64027876FDC00BB9B9F /* UserOverrideModel.cpp in Sources */,
|
5B42B64027876FDC00BB9B9F /* UserOverrideModel.cpp in Sources */,
|
||||||
|
5BD0D1A4279463510008F48E /* clsOOBEDefaults.swift in Sources */,
|
||||||
D427A9C125ED28CC005D43E0 /* OpenCCBridge.swift in Sources */,
|
D427A9C125ED28CC005D43E0 /* OpenCCBridge.swift in Sources */,
|
||||||
6A0D4F4515FC0EB100ABF4B3 /* Mandarin.cpp in Sources */,
|
6A0D4F4515FC0EB100ABF4B3 /* Mandarin.cpp in Sources */,
|
||||||
6A0421A815FEF3F50061ED63 /* FastLM.cpp in Sources */,
|
6A0421A815FEF3F50061ED63 /* FastLM.cpp in Sources */,
|
||||||
|
|
Loading…
Reference in New Issue