From d9b4d7033dc775fa48fbc75b750ee321cecd196a Mon Sep 17 00:00:00 2001 From: Myryk Date: Thu, 6 Jun 2024 02:04:54 +0200 Subject: [PATCH 1/4] web search without excluded sites works as expected --- .config/ags/modules/overview/searchbuttons.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.config/ags/modules/overview/searchbuttons.js b/.config/ags/modules/overview/searchbuttons.js index 86d2ffbc0..69bbaab08 100644 --- a/.config/ags/modules/overview/searchbuttons.js +++ b/.config/ags/modules/overview/searchbuttons.js @@ -159,7 +159,11 @@ export const SearchButton = ({ text = '' }) => searchItem({ content: `${text}`, onActivate: () => { App.closeWindow('overview'); - execAsync(['bash', '-c', `xdg-open '${userOptions.search.engineBaseUrl}${text} ${['', ...userOptions.search.excludedSites].join(' -site:')}' &`]).catch(print); + let search = userOptions.search.engineBaseUrl + text; + for (let site of userOptions.search.excludedSites) { + if (site) search += ` -site:${site}`; + } + execAsync(['bash', '-c', `xdg-open '${search}' &`]).catch(print); }, }); From 7656113e590216acf138b390ca9d2c95f6b884c8 Mon Sep 17 00:00:00 2001 From: Myryk Date: Thu, 6 Jun 2024 03:31:22 +0200 Subject: [PATCH 2/4] added NoResultButton for search --- .config/ags/modules/overview/searchbuttons.js | 9 +++++ .config/ags/modules/overview/windowcontent.js | 36 ++++++++++++------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/.config/ags/modules/overview/searchbuttons.js b/.config/ags/modules/overview/searchbuttons.js index 69bbaab08..58f516076 100644 --- a/.config/ags/modules/overview/searchbuttons.js +++ b/.config/ags/modules/overview/searchbuttons.js @@ -7,6 +7,15 @@ import { searchItem } from './searchitem.js'; import { execAndClose, couldBeMath, launchCustomCommand } from './miscfunctions.js'; import GeminiService from '../../services/gemini.js'; +export const NoResultButton = () => searchItem({ + materialIconName: 'Error', + name: "Search invalid", + content: "No results found!", + onActivate: () => { + App.closeWindow('overview'); + }, +}); + export const DirectoryButton = ({ parentPath, name, type, icon }) => { const actionText = Widget.Revealer({ revealChild: false, diff --git a/.config/ags/modules/overview/windowcontent.js b/.config/ags/modules/overview/windowcontent.js index 2f50a6902..564df9355 100644 --- a/.config/ags/modules/overview/windowcontent.js +++ b/.config/ags/modules/overview/windowcontent.js @@ -8,7 +8,7 @@ const { execAsync, exec } = Utils; import { execAndClose, expandTilde, hasUnterminatedBackslash, couldBeMath, launchCustomCommand, ls } from './miscfunctions.js'; import { CalculationResultButton, CustomCommandButton, DirectoryButton, - DesktopEntryButton, ExecuteCommandButton, SearchButton, AiButton + DesktopEntryButton, ExecuteCommandButton, SearchButton, AiButton, NoResultButton, } from './searchbuttons.js'; import { checkKeybind } from '../.widgetutils/keybind.js'; import GeminiService from '../../services/gemini.js'; @@ -99,7 +99,7 @@ export const SearchAndWindows = () => { const isAction = text.startsWith('>'); const isDir = (['/', '~'].includes(entry.text[0])); - if (couldBeMath(text)) { // Eval on typing is dangerous, this is a workaround + if (userOptions.search.enableMathResults && couldBeMath(text)) { // Eval on typing is dangerous, this is a workaround try { const fullResult = eval(text.replace(/\^/g, "**")); // copy @@ -110,7 +110,7 @@ export const SearchAndWindows = () => { // console.log(e); } } - if (isDir) { + if (userOptions.search.enableDirectorySearch && isDir) { App.closeWindow('overview'); execAsync(['bash', '-c', `xdg-open "${expandTilde(text)}"`, `&`]).catch(print); return; @@ -120,24 +120,31 @@ export const SearchAndWindows = () => { _appSearchResults[0].launch(); return; } - else if (text[0] == '>') { // Custom commands + else if (userOptions.search.enableActions && text[0] == '>') { // Custom commands App.closeWindow('overview'); launchCustomCommand(text); return; } // Fallback: Execute command - if (!isAction && exec(`bash -c "command -v ${text.split(' ')[0]}"`) != '') { + if (userOptions.search.enableCommands && !isAction && exec(`bash -c "command -v ${text.split(' ')[0]}"`) != '') { if (text.startsWith('sudo')) execAndClose(text, true); else execAndClose(text, false); } - - else { + else if (userOptions.search.enableAiSearch) { GeminiService.send(text); App.closeWindow('overview'); App.openWindow('sideleft'); } + else if (userOptions.search.enableWebSearch) { + App.closeWindow('overview'); + let search = userOptions.search.engineBaseUrl + text; + for (let site of userOptions.search.excludedSites) { + if (site) search += ` -site:${site}`; + } + execAsync(['bash', '-c', `xdg-open '${search}' &`]).catch(print); + } }, onChange: (entry) => { // this is when you type const isAction = entry.text[0] == '>'; @@ -162,7 +169,7 @@ export const SearchAndWindows = () => { _appSearchResults = Applications.query(text); // Calculate - if (couldBeMath(text)) { // Eval on typing is dangerous; this is a small workaround. + if (userOptions.search.enableMathResults && couldBeMath(text)) { // Eval on typing is dangerous; this is a small workaround. try { const fullResult = eval(text.replace(/\^/g, "**")); resultsBox.add(CalculationResultButton({ result: fullResult, text: text })); @@ -170,14 +177,14 @@ export const SearchAndWindows = () => { // console.log(e); } } - if (isDir) { + if (userOptions.search.enableDirectorySearch && isDir) { var contents = []; contents = ls({ path: text, silent: true }); contents.forEach((item) => { resultsBox.add(DirectoryButton(item)); }) } - if (isAction) { // Eval on typing is dangerous, this is a workaround. + if (userOptions.search.enableActions && isAction) { // Eval on typing is dangerous, this is a workaround. resultsBox.add(CustomCommandButton({ text: entry.text })); } // Add application entries @@ -190,13 +197,16 @@ export const SearchAndWindows = () => { // Fallbacks // if the first word is an actual command - if (!isAction && !hasUnterminatedBackslash(text) && exec(`bash -c "command -v ${text.split(' ')[0]}"`) != '') { + if (userOptions.search.enableCommands && !isAction && !hasUnterminatedBackslash(text) && exec(`bash -c "command -v ${text.split(' ')[0]}"`) != '') { resultsBox.add(ExecuteCommandButton({ command: entry.text, terminal: entry.text.startsWith('sudo') })); } // Add fallback: search - resultsBox.add(AiButton({ text: entry.text })); - resultsBox.add(SearchButton({ text: entry.text })); + if (userOptions.search.enableAiSearch) + resultsBox.add(AiButton({ text: entry.text })); + if (userOptions.search.enableWebSearch) + resultsBox.add(SearchButton({ text: entry.text })); + if (resultsBox.children.length == 0) resultsBox.add(NoResultButton()); resultsBox.show_all(); }, }); From 21bc2065163924acd329061f59b31a6a399ae5bf Mon Sep 17 00:00:00 2001 From: Myryk Date: Thu, 6 Jun 2024 03:32:27 +0200 Subject: [PATCH 3/4] new search user options --- .config/ags/modules/.configuration/user_options.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.config/ags/modules/.configuration/user_options.js b/.config/ags/modules/.configuration/user_options.js index a0c228df5..3aa9bb9b8 100644 --- a/.config/ags/modules/.configuration/user_options.js +++ b/.config/ags/modules/.configuration/user_options.js @@ -93,6 +93,12 @@ let configOptions = { }, 'search': { + 'enableActions': true, + 'enableCommands': true, + 'enableMathResults': true, + 'enableDirectorySearch': true, + 'enableAiSearch': true, + 'enableWebSearch': true, 'engineBaseUrl': "https://www.google.com/search?q=", 'excludedSites': ["quora.com"], }, From b42ca22ecf1839a67093aaadf1817dc286ed40ef Mon Sep 17 00:00:00 2001 From: Myryk Date: Thu, 6 Jun 2024 21:02:59 +0200 Subject: [PATCH 4/4] deduplicated code in windowcontent and searchbuttons --- .config/ags/modules/overview/windowcontent.js | 52 +------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/.config/ags/modules/overview/windowcontent.js b/.config/ags/modules/overview/windowcontent.js index 564df9355..95026f72b 100644 --- a/.config/ags/modules/overview/windowcontent.js +++ b/.config/ags/modules/overview/windowcontent.js @@ -94,57 +94,7 @@ export const SearchAndWindows = () => { className: 'overview-search-box txt-small txt', hpack: 'center', onAccept: (self) => { // This is when you hit Enter - const text = self.text; - if (text.length == 0) return; - const isAction = text.startsWith('>'); - const isDir = (['/', '~'].includes(entry.text[0])); - - if (userOptions.search.enableMathResults && couldBeMath(text)) { // Eval on typing is dangerous, this is a workaround - try { - const fullResult = eval(text.replace(/\^/g, "**")); - // copy - execAsync(['wl-copy', `${fullResult}`]).catch(print); - App.closeWindow('overview'); - return; - } catch (e) { - // console.log(e); - } - } - if (userOptions.search.enableDirectorySearch && isDir) { - App.closeWindow('overview'); - execAsync(['bash', '-c', `xdg-open "${expandTilde(text)}"`, `&`]).catch(print); - return; - } - if (_appSearchResults.length > 0) { - App.closeWindow('overview'); - _appSearchResults[0].launch(); - return; - } - else if (userOptions.search.enableActions && text[0] == '>') { // Custom commands - App.closeWindow('overview'); - launchCustomCommand(text); - return; - } - // Fallback: Execute command - if (userOptions.search.enableCommands && !isAction && exec(`bash -c "command -v ${text.split(' ')[0]}"`) != '') { - if (text.startsWith('sudo')) - execAndClose(text, true); - else - execAndClose(text, false); - } - else if (userOptions.search.enableAiSearch) { - GeminiService.send(text); - App.closeWindow('overview'); - App.openWindow('sideleft'); - } - else if (userOptions.search.enableWebSearch) { - App.closeWindow('overview'); - let search = userOptions.search.engineBaseUrl + text; - for (let site of userOptions.search.excludedSites) { - if (site) search += ` -site:${site}`; - } - execAsync(['bash', '-c', `xdg-open '${search}' &`]).catch(print); - } + resultsBox.children[0].onClicked(); }, onChange: (entry) => { // this is when you type const isAction = entry.text[0] == '>';