mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(user-menu) add error handling
This commit is contained in:
parent
0b3348ee77
commit
21ac9bb45b
2 changed files with 18 additions and 3 deletions
|
|
@ -10,7 +10,10 @@ const {
|
|||
|
||||
const title = 'Cloud Commander';
|
||||
|
||||
module.exports.alert = (...a) => alert(title, ...a);
|
||||
module.exports.alert = (...a) => alert(title, ...a, {
|
||||
cancel: false,
|
||||
});
|
||||
|
||||
module.exports.prompt = (...a) => prompt(title, ...a);
|
||||
module.exports.confirm = (...a) => confirm(title, ...a);
|
||||
module.exports.progress = (...a) => progress(title, ...a);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,11 @@ const currify = require('currify/legacy');
|
|||
const {promisify} = require('es6-promisify');
|
||||
const load = require('load.js');
|
||||
const createElement = require('@cloudcmd/create-element');
|
||||
const tryCatch = require('try-catch');
|
||||
const tryToCatch = require('try-to-catch/legacy');
|
||||
|
||||
const Images = require('../../dom/images');
|
||||
const Dialog = require('../../dom/dialog');
|
||||
const getUserMenu = require('./get-user-menu');
|
||||
const navigate = require('./navigate');
|
||||
|
||||
|
|
@ -40,7 +43,11 @@ async function show() {
|
|||
|
||||
const {dirPath} = CurrentInfo;
|
||||
const res = await fetch(`/api/v1/user-menu?dir=${dirPath}`);
|
||||
const userMenu = getUserMenu(await res.text());
|
||||
const [error, userMenu] = tryCatch(getUserMenu, await res.text());
|
||||
|
||||
if (error)
|
||||
return Dialog.alert(`User menu error: ${error.message}`);
|
||||
|
||||
const options = Object.keys(userMenu);
|
||||
|
||||
const el = createElement('select', {
|
||||
|
|
@ -50,6 +57,7 @@ async function show() {
|
|||
});
|
||||
|
||||
const keys = options.map(getKey);
|
||||
|
||||
el.addEventListener('keydown', onKeyDown(keys, options, userMenu));
|
||||
el.addEventListener('dblclick', onDblClick(options, userMenu));
|
||||
|
||||
|
|
@ -88,6 +96,7 @@ const onKeyDown = currify(async (keys, options, userMenu, e) => {
|
|||
keyCode,
|
||||
target,
|
||||
} = e;
|
||||
|
||||
const key = e.key.toUpperCase();
|
||||
|
||||
e.preventDefault();
|
||||
|
|
@ -110,9 +119,12 @@ const onKeyDown = currify(async (keys, options, userMenu, e) => {
|
|||
const runUserMenu = async (value, options, userMenu) => {
|
||||
hide();
|
||||
|
||||
await userMenu[value]({
|
||||
const [e] = await tryToCatch(userMenu[value], {
|
||||
DOM,
|
||||
CloudCmd,
|
||||
});
|
||||
|
||||
if (e)
|
||||
Dialog.alert(e.stack);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue