change search feature user option (#587)

This commit is contained in:
end-4
2024-06-10 22:05:29 +07:00
parent ed09026179
commit 2c1dfcc711
2 changed files with 18 additions and 12 deletions
@@ -93,12 +93,14 @@ let configOptions = {
}, },
'search': { 'search': {
'enableActions': true, 'enableFeatures': {
'enableCommands': true, 'actions': true,
'enableMathResults': true, 'commands': true,
'enableDirectorySearch': true, 'mathResults': true,
'enableAiSearch': true, 'directorySearch': true,
'enableWebSearch': true, 'aiSearch': true,
'webSearch': true,
},
'engineBaseUrl': "https://www.google.com/search?q=", 'engineBaseUrl': "https://www.google.com/search?q=",
'excludedSites': ["quora.com"], 'excludedSites': ["quora.com"],
}, },
@@ -191,6 +193,10 @@ let configOptions = {
'prevTab': "Ctrl+Page_Up", 'prevTab': "Ctrl+Page_Up",
}, },
'cheatsheet': { 'cheatsheet': {
'keybinds': {
'nextTab': "Page_Down",
'prevTab': "Page_Up",
},
'nextTab': "Ctrl+Page_Down", 'nextTab': "Ctrl+Page_Down",
'prevTab': "Ctrl+Page_Up", 'prevTab': "Ctrl+Page_Up",
} }
@@ -119,7 +119,7 @@ export const SearchAndWindows = () => {
_appSearchResults = Applications.query(text); _appSearchResults = Applications.query(text);
// Calculate // Calculate
if (userOptions.search.enableMathResults && couldBeMath(text)) { // Eval on typing is dangerous; this is a small workaround. if (userOptions.search.enableFeatures.mathResults && couldBeMath(text)) { // Eval on typing is dangerous; this is a small workaround.
try { try {
const fullResult = eval(text.replace(/\^/g, "**")); const fullResult = eval(text.replace(/\^/g, "**"));
resultsBox.add(CalculationResultButton({ result: fullResult, text: text })); resultsBox.add(CalculationResultButton({ result: fullResult, text: text }));
@@ -127,14 +127,14 @@ export const SearchAndWindows = () => {
// console.log(e); // console.log(e);
} }
} }
if (userOptions.search.enableDirectorySearch && isDir) { if (userOptions.search.enableFeatures.directorySearch && isDir) {
var contents = []; var contents = [];
contents = ls({ path: text, silent: true }); contents = ls({ path: text, silent: true });
contents.forEach((item) => { contents.forEach((item) => {
resultsBox.add(DirectoryButton(item)); resultsBox.add(DirectoryButton(item));
}) })
} }
if (userOptions.search.enableActions && isAction) { // Eval on typing is dangerous, this is a workaround. if (userOptions.search.enableFeatures.actions && isAction) { // Eval on typing is dangerous, this is a workaround.
resultsBox.add(CustomCommandButton({ text: entry.text })); resultsBox.add(CustomCommandButton({ text: entry.text }));
} }
// Add application entries // Add application entries
@@ -147,14 +147,14 @@ export const SearchAndWindows = () => {
// Fallbacks // Fallbacks
// if the first word is an actual command // if the first word is an actual command
if (userOptions.search.enableCommands && !isAction && !hasUnterminatedBackslash(text) && exec(`bash -c "command -v ${text.split(' ')[0]}"`) != '') { if (userOptions.search.enableFeatures.commands && !isAction && !hasUnterminatedBackslash(text) && exec(`bash -c "command -v ${text.split(' ')[0]}"`) != '') {
resultsBox.add(ExecuteCommandButton({ command: entry.text, terminal: entry.text.startsWith('sudo') })); resultsBox.add(ExecuteCommandButton({ command: entry.text, terminal: entry.text.startsWith('sudo') }));
} }
// Add fallback: search // Add fallback: search
if (userOptions.search.enableAiSearch) if (userOptions.search.enableFeatures.aiSearch)
resultsBox.add(AiButton({ text: entry.text })); resultsBox.add(AiButton({ text: entry.text }));
if (userOptions.search.enableWebSearch) if (userOptions.search.enableFeatures.webSearch)
resultsBox.add(SearchButton({ text: entry.text })); resultsBox.add(SearchButton({ text: entry.text }));
if (resultsBox.children.length == 0) resultsBox.add(NoResultButton()); if (resultsBox.children.length == 0) resultsBox.add(NoResultButton());
resultsBox.show_all(); resultsBox.show_all();