From 262c256ea09f9be0aa77f70e3e391190091f7ab6 Mon Sep 17 00:00:00 2001 From: zonble Date: Sat, 16 Mar 2024 16:02:00 +0800 Subject: [PATCH] Makes it able to turn off the notifications on Chrome OS. --- output/chromeos/_locales/en/messages.json | 4 +- output/chromeos/_locales/zh_TW/messages.json | 4 +- output/chromeos/options.html | 8 ++- output/chromeos/options.js | 34 +++++++----- src/chromeos_ime.ts | 54 ++++++++++++++------ 5 files changed, 70 insertions(+), 34 deletions(-) diff --git a/output/chromeos/_locales/en/messages.json b/output/chromeos/_locales/en/messages.json index 8102b22a..fc9d5b69 100644 --- a/output/chromeos/_locales/en/messages.json +++ b/output/chromeos/_locales/en/messages.json @@ -61,5 +61,7 @@ "candidate_keys_count": { "message": "Candidate Keys Count:" }, "use_jk_key": { "message": "Use J/K keys to move cursor when choosing candidates " - } + }, + "system": { "message": "System:" }, + "use_notification": { "message": "Use system notification" } } diff --git a/output/chromeos/_locales/zh_TW/messages.json b/output/chromeos/_locales/zh_TW/messages.json index a8acb4c5..05822848 100644 --- a/output/chromeos/_locales/zh_TW/messages.json +++ b/output/chromeos/_locales/zh_TW/messages.json @@ -55,5 +55,7 @@ "ctrl_enter_html_ruby": { "message": "輸入 HTML Ruby" }, "ctrl_enter_taiwanese_braille": { "message": "輸入台灣點字" }, "candidate_keys_count": { "message": "選字按鍵數量" }, - "use_jk_key": { "message": "使用 JK 按鍵在選字時移動游標" } + "use_jk_key": { "message": "使用 JK 按鍵在選字時移動游標" }, + "system": { "message": "系統:" }, + "use_notification": { "message": "使用系統提示通知" } } diff --git a/output/chromeos/options.html b/output/chromeos/options.html index 86bd397e..9ab8cb4b 100644 --- a/output/chromeos/options.html +++ b/output/chromeos/options.html @@ -99,6 +99,13 @@

McBopomofo Options

+ + System: + + + + Others: @@ -106,7 +113,6 @@

McBopomofo Options

You can also set the keyboard shortcuts by visiting chrome://extensions/shortcuts .

- diff --git a/output/chromeos/options.js b/output/chromeos/options.js index 86042c4f..4b4e1046 100644 --- a/output/chromeos/options.js +++ b/output/chromeos/options.js @@ -13,6 +13,7 @@ window.onload = () => { move_cursor: false, letter_mode: "upper", ctrl_enter_option: 0, + use_notification: true, }; function applySettings(settings) { @@ -37,7 +38,6 @@ window.onload = () => { } } { - controller.setCandidateKeysCount(settings.candidate_keys_count); let select = document.getElementById("keys_count"); let options = select.getElementsByTagName("option"); for (let option of options) { @@ -57,24 +57,16 @@ window.onload = () => { } } { + document.getElementById("shift_key").checked = + settings.shift_key_toggle_alphabet_mode; document.getElementById("esc_key").checked = settings.esc_key_clear_entire_buffer; - } - { document.getElementById("jk_key").checked = settings.use_jk_key_to_move_cursor; - } - { - let enabled = settings.shift_key_toggle_alphabet_mode; - if (enabled === undefined) { - enabled = true; - } - document.getElementById("shift_key").checked = enabled; - } - { document.getElementById("move_cursor").checked = settings.move_cursor; + document.getElementById("use_notification").checked = + settings.use_notification; } - { if (settings.letter_mode === "upper") { document.getElementById("uppercase_letters").checked = true; @@ -84,7 +76,6 @@ window.onload = () => { document.getElementById("lowercase_letters").checked = true; } } - { let select = document.getElementById("ctrl_enter_option"); let options = select.getElementsByTagName("option"); @@ -108,6 +99,11 @@ window.onload = () => { if (settings == undefined) { settings = defaultSettings; } + for (let key in defaultSettings) { + if (!(key in settings)) { + settings[key] = defaultSettings[key]; + } + } applySettings(settings); }); @@ -151,6 +147,12 @@ window.onload = () => { saveSettings(settings); }; + document.getElementById("use_notification").onchange = function (event) { + let checked = document.getElementById("use_notification").checked; + settings.use_notification = checked; + saveSettings(settings); + }; + document.getElementById("shift_key").onchange = (event) => { let checked = document.getElementById("shift_key").checked; settings.shift_key_toggle_alphabet_mode = checked; @@ -276,4 +278,8 @@ window.onload = () => { chrome.i18n.getMessage("candidate_keys_count"); document.getElementById("use_jk_key").innerText = chrome.i18n.getMessage("use_jk_key"); + document.getElementById("system").innerText = + chrome.i18n.getMessage("system"); + document.getElementById("use_notification_label").innerText = + chrome.i18n.getMessage("use_notification"); }; diff --git a/src/chromeos_ime.ts b/src/chromeos_ime.ts index 0bd6f1b6..6925f596 100644 --- a/src/chromeos_ime.ts +++ b/src/chromeos_ime.ts @@ -25,6 +25,7 @@ type ChromeMcBopomofoSettings = { ctrl_enter_option: number; half_width_punctuation_enabled: boolean; use_jk_key_to_move_cursor: boolean; + use_notification: boolean; }; class ChromeMcBopomofo { @@ -48,6 +49,7 @@ class ChromeMcBopomofo { ctrl_enter_option: 0, half_width_punctuation_enabled: false, use_jk_key_to_move_cursor: false, + use_notification: true, }; settings: ChromeMcBopomofoSettings = { layout: "standard", @@ -62,6 +64,7 @@ class ChromeMcBopomofo { ctrl_enter_option: 0, half_width_punctuation_enabled: false, use_jk_key_to_move_cursor: false, + use_notification: true, }; lang = "en"; isShiftHold = false; @@ -82,6 +85,7 @@ class ChromeMcBopomofo { this.inputController.setOnOpenUrl((input: string) => { this.tryOpen(input); }); + this.inputController.setOnError(() => {}); // The horizontal candidate windows on ChromeOS is actually broken so we // use the vertical one only. @@ -104,6 +108,12 @@ class ChromeMcBopomofo { ) { this.settings.shift_key_toggle_alphabet_mode = true; } + if ( + this.settings.use_notification === undefined || + this.settings.use_notification === null + ) { + this.settings.use_notification = true; + } this.inputController.setChineseConversionEnabled( this.settings.chinese_conversion === true @@ -214,15 +224,17 @@ class ChromeMcBopomofo { toggleAlphabetMode() { this.isAlphabetMode = !this.isAlphabetMode; - chrome.notifications.create("mcbopomofo-alphabet-mode" + Date.now(), { - title: this.isAlphabetMode - ? this.myLocalizedString("English Mode", "英文模式") - : this.myLocalizedString("Chinese Mode", "中文模式"), + if (this.settings.use_notification) { + chrome.notifications.create("mcbopomofo-alphabet-mode" + Date.now(), { + title: this.isAlphabetMode + ? this.myLocalizedString("English Mode", "英文模式") + : this.myLocalizedString("Chinese Mode", "中文模式"), - message: "", - type: "basic", - iconUrl: "icons/icon48.png", - }); + message: "", + type: "basic", + iconUrl: "icons/icon48.png", + }); + } } toggleChineseConversion() { @@ -231,15 +243,23 @@ class ChromeMcBopomofo { this.settings.chinese_conversion = checked; this.inputController.setChineseConversionEnabled(checked); - chrome.notifications.create("mcbopomofo-chinese-conversion" + Date.now(), { - title: checked - ? this.myLocalizedString("Chinese Conversion On", "簡繁轉換已開啟") - : this.myLocalizedString("Chinese Conversion Off", "簡繁轉換已關閉"), - - message: "", - type: "basic", - iconUrl: "icons/icon48.png", - }); + if (this.settings.use_notification) { + chrome.notifications.create( + "mcbopomofo-chinese-conversion" + Date.now(), + { + title: checked + ? this.myLocalizedString("Chinese Conversion On", "簡繁轉換已開啟") + : this.myLocalizedString( + "Chinese Conversion Off", + "簡繁轉換已關閉" + ), + + message: "", + type: "basic", + iconUrl: "icons/icon48.png", + } + ); + } chrome.storage.sync.set({ settings: this.settings }, () => { if (this.engineID === undefined) return;