Skip to content

Commit

Permalink
Makes it able to turn off the notifications on Chrome OS.
Browse files Browse the repository at this point in the history
zonble committed Mar 16, 2024
1 parent dcb839a commit 262c256
Showing 5 changed files with 70 additions and 34 deletions.
4 changes: 3 additions & 1 deletion output/chromeos/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -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" }
}
4 changes: 3 additions & 1 deletion output/chromeos/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
@@ -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": "使用系統提示通知" }
}
8 changes: 7 additions & 1 deletion output/chromeos/options.html
Original file line number Diff line number Diff line change
@@ -99,14 +99,20 @@ <h1 id="options_title">McBopomofo Options</h1>
</select>
</td>
</tr>
<tr>
<td class="option_title" id="system">System:</td>
<td>
<input type="checkbox" name="use_notification" id="use_notification"><label for="use_notification"
id="use_notification_label">Use system notification</label>
</td>
</tr>
<tr>
<td class="option_title" id="others_title">Others:</td>
<td>
<a href="#" id="others_manage_user_phrases">Manage User Phrases</a><br />
<p id="others_keyboard_shortcut">You can also set the keyboard shortcuts by visiting
chrome://extensions/shortcuts .</p>
</td>

</tr>

</table>
34 changes: 20 additions & 14 deletions output/chromeos/options.js
Original file line number Diff line number Diff line change
@@ -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");
};
54 changes: 37 additions & 17 deletions src/chromeos_ime.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 262c256

Please sign in to comment.