Skip to content

Commit

Permalink
Add handler
Browse files Browse the repository at this point in the history
  • Loading branch information
asamuzaK committed Dec 30, 2024
1 parent b6b8e03 commit 608edc4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/mjs/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

export const CONTENT_GET = 'getContent';
export const CONTEXT_MENU = 'contextMenu';
export const EDIT_HTML = 'editHtml';
export const EDIT_MD = 'editMarkdown';
export const EDIT_TXT = 'editPlainText';
export const EDITOR_CONFIG_GET = 'getEditorConfig';
export const EDITOR_CONFIG_RES = 'resEditorConfig';
export const EDITOR_CONFIG_TS = 'editorConfigTimestamp';
Expand Down Expand Up @@ -57,7 +60,7 @@ export const MODE_EDIT = 'modeEditText';
export const MODE_EDIT_EXT = 'modeEditTextFileExtension';
export const MODE_EDIT_HTML = 'modeEditTextHtml';
export const MODE_EDIT_MD = 'modeEditTextMarkdown';
export const MODE_EDIT_TXT = 'modeEditTextPlaintext';
export const MODE_EDIT_TXT = 'modeEditTextPlainText';
export const MODE_MATHML = 'modeViewMathML';
export const MODE_SELECTION = 'modeViewSelection';
export const MODE_SOURCE = 'modeViewSource';
Expand Down
52 changes: 36 additions & 16 deletions src/mjs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import {
} from './common.js';
import { setIconBadge } from './icon.js';
import {
CONTENT_GET, CONTEXT_MENU, EDITOR_CONFIG_GET, EDITOR_CONFIG_RES,
EDITOR_CONFIG_TS, EDITOR_EXEC, EDITOR_FILE_NAME, EDITOR_LABEL, EXT_NAME,
FILE_EXT_SELECT, FILE_EXT_SELECT_HTML, FILE_EXT_SELECT_MD,
FILE_EXT_SELECT_TXT, HOST, HOST_COMPAT, HOST_CONNECTION, HOST_ERR_NOTIFY,
HOST_STATUS, HOST_STATUS_GET, HOST_VERSION, HOST_VERSION_CHECK,
HOST_VERSION_LATEST, HOST_VERSION_MIN, ICON, INFO_COLOR, INFO_TEXT,
IS_CONNECTABLE, IS_EXECUTABLE, IS_MAC, LOCAL_FILE_VIEW, MENU_ENABLED,
MODE_EDIT, MODE_EDIT_EXT, MODE_EDIT_HTML, MODE_EDIT_MD, MODE_EDIT_TXT,
MODE_MATHML, MODE_SELECTION, MODE_SOURCE, MODE_SVG, ONLY_EDITABLE,
OPTIONS_OPEN, PATH_OPTIONS_PAGE, PROCESS_CHILD, SYNC_AUTO, SYNC_AUTO_URL,
TMP_FILES_PB, TMP_FILES_PB_REMOVE, TMP_FILE_CREATE, TMP_FILE_DATA_PORT,
TMP_FILE_DATA_REMOVE, TMP_FILE_GET, TMP_FILE_REQ, TMP_FILE_RES, VARS_SET,
WARN_COLOR, WARN_TEXT
CONTENT_GET, CONTEXT_MENU, EDIT_HTML, EDIT_MD, EDIT_TXT, EDITOR_CONFIG_GET,
EDITOR_CONFIG_RES, EDITOR_CONFIG_TS, EDITOR_EXEC, EDITOR_FILE_NAME,
EDITOR_LABEL, EXT_NAME, FILE_EXT_SELECT, FILE_EXT_SELECT_HTML,
FILE_EXT_SELECT_MD, FILE_EXT_SELECT_TXT, HOST, HOST_COMPAT, HOST_CONNECTION,
HOST_ERR_NOTIFY, HOST_STATUS, HOST_STATUS_GET, HOST_VERSION,
HOST_VERSION_CHECK, HOST_VERSION_LATEST, HOST_VERSION_MIN, ICON, INFO_COLOR,
INFO_TEXT, IS_CONNECTABLE, IS_EXECUTABLE, IS_MAC, LOCAL_FILE_VIEW,
MENU_ENABLED, MODE_EDIT, MODE_EDIT_EXT, MODE_EDIT_HTML, MODE_EDIT_MD,
MODE_EDIT_TXT, MODE_MATHML, MODE_SELECTION, MODE_SOURCE, MODE_SVG,
ONLY_EDITABLE, OPTIONS_OPEN, PATH_OPTIONS_PAGE, PROCESS_CHILD, SYNC_AUTO,
SYNC_AUTO_URL, TMP_FILES_PB, TMP_FILES_PB_REMOVE, TMP_FILE_CREATE,
TMP_FILE_DATA_PORT, TMP_FILE_DATA_REMOVE, TMP_FILE_GET, TMP_FILE_REQ,
TMP_FILE_RES, VARS_SET, WARN_COLOR, WARN_TEXT
} from './constant.js';

/* api */
Expand Down Expand Up @@ -900,15 +900,35 @@ export const handleCmd = async (cmd, tab) => {
}
let func;
switch (cmd) {
case EDIT_HTML:
case EDIT_MD:
case EDIT_TXT:
case EDITOR_EXEC: {
if (!tab) {
tab = await getActiveTab();
}
const { id } = tab;
if (tabList.has(id)) {
func = sendMessage(id, {
[CONTENT_GET]: { tab }
});
if (cmd === EDITOR_EXEC) {
func = sendMessage(id, {
[CONTENT_GET]: { tab }
});
} else {
let menuItemId;
if (cmd === EDIT_HTML) {
menuItemId = MODE_EDIT_HTML;
} else if (cmd === EDIT_MD) {
menuItemId = MODE_EDIT_MD;
} else {
menuItemId = MODE_EDIT_TXT;
}
const info = {
menuItemId
};
func = sendMessage(id, {
[CONTENT_GET]: { info, tab }
});
}
}
break;
}
Expand Down

0 comments on commit 608edc4

Please sign in to comment.