forked from Shinonome/dots-hyprland
Search customizing (#587)
This commit is contained in:
@@ -93,6 +93,12 @@ let configOptions = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
'search': {
|
'search': {
|
||||||
|
'enableActions': true,
|
||||||
|
'enableCommands': true,
|
||||||
|
'enableMathResults': true,
|
||||||
|
'enableDirectorySearch': true,
|
||||||
|
'enableAiSearch': true,
|
||||||
|
'enableWebSearch': true,
|
||||||
'engineBaseUrl': "https://www.google.com/search?q=",
|
'engineBaseUrl': "https://www.google.com/search?q=",
|
||||||
'excludedSites': ["quora.com"],
|
'excludedSites': ["quora.com"],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,6 +7,15 @@ import { searchItem } from './searchitem.js';
|
|||||||
import { execAndClose, couldBeMath, launchCustomCommand } from './miscfunctions.js';
|
import { execAndClose, couldBeMath, launchCustomCommand } from './miscfunctions.js';
|
||||||
import GeminiService from '../../services/gemini.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 }) => {
|
export const DirectoryButton = ({ parentPath, name, type, icon }) => {
|
||||||
const actionText = Widget.Revealer({
|
const actionText = Widget.Revealer({
|
||||||
revealChild: false,
|
revealChild: false,
|
||||||
@@ -159,7 +168,11 @@ export const SearchButton = ({ text = '' }) => searchItem({
|
|||||||
content: `${text}`,
|
content: `${text}`,
|
||||||
onActivate: () => {
|
onActivate: () => {
|
||||||
App.closeWindow('overview');
|
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);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const { execAsync, exec } = Utils;
|
|||||||
import { execAndClose, expandTilde, hasUnterminatedBackslash, couldBeMath, launchCustomCommand, ls } from './miscfunctions.js';
|
import { execAndClose, expandTilde, hasUnterminatedBackslash, couldBeMath, launchCustomCommand, ls } from './miscfunctions.js';
|
||||||
import {
|
import {
|
||||||
CalculationResultButton, CustomCommandButton, DirectoryButton,
|
CalculationResultButton, CustomCommandButton, DirectoryButton,
|
||||||
DesktopEntryButton, ExecuteCommandButton, SearchButton, AiButton
|
DesktopEntryButton, ExecuteCommandButton, SearchButton, AiButton, NoResultButton,
|
||||||
} from './searchbuttons.js';
|
} from './searchbuttons.js';
|
||||||
import { checkKeybind } from '../.widgetutils/keybind.js';
|
import { checkKeybind } from '../.widgetutils/keybind.js';
|
||||||
import GeminiService from '../../services/gemini.js';
|
import GeminiService from '../../services/gemini.js';
|
||||||
@@ -94,50 +94,7 @@ export const SearchAndWindows = () => {
|
|||||||
className: 'overview-search-box txt-small txt',
|
className: 'overview-search-box txt-small txt',
|
||||||
hpack: 'center',
|
hpack: 'center',
|
||||||
onAccept: (self) => { // This is when you hit Enter
|
onAccept: (self) => { // This is when you hit Enter
|
||||||
const text = self.text;
|
resultsBox.children[0].onClicked();
|
||||||
if (text.length == 0) return;
|
|
||||||
const isAction = text.startsWith('>');
|
|
||||||
const isDir = (['/', '~'].includes(entry.text[0]));
|
|
||||||
|
|
||||||
if (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 (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 (text[0] == '>') { // Custom commands
|
|
||||||
App.closeWindow('overview');
|
|
||||||
launchCustomCommand(text);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Fallback: Execute command
|
|
||||||
if (!isAction && exec(`bash -c "command -v ${text.split(' ')[0]}"`) != '') {
|
|
||||||
if (text.startsWith('sudo'))
|
|
||||||
execAndClose(text, true);
|
|
||||||
else
|
|
||||||
execAndClose(text, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
GeminiService.send(text);
|
|
||||||
App.closeWindow('overview');
|
|
||||||
App.openWindow('sideleft');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onChange: (entry) => { // this is when you type
|
onChange: (entry) => { // this is when you type
|
||||||
const isAction = entry.text[0] == '>';
|
const isAction = entry.text[0] == '>';
|
||||||
@@ -162,7 +119,7 @@ export const SearchAndWindows = () => {
|
|||||||
_appSearchResults = Applications.query(text);
|
_appSearchResults = Applications.query(text);
|
||||||
|
|
||||||
// Calculate
|
// 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 {
|
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 }));
|
||||||
@@ -170,14 +127,14 @@ export const SearchAndWindows = () => {
|
|||||||
// console.log(e);
|
// console.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isDir) {
|
if (userOptions.search.enableDirectorySearch && 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 (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 }));
|
resultsBox.add(CustomCommandButton({ text: entry.text }));
|
||||||
}
|
}
|
||||||
// Add application entries
|
// Add application entries
|
||||||
@@ -190,13 +147,16 @@ export const SearchAndWindows = () => {
|
|||||||
|
|
||||||
// Fallbacks
|
// Fallbacks
|
||||||
// if the first word is an actual command
|
// 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') }));
|
resultsBox.add(ExecuteCommandButton({ command: entry.text, terminal: entry.text.startsWith('sudo') }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add fallback: search
|
// Add fallback: search
|
||||||
resultsBox.add(AiButton({ text: entry.text }));
|
if (userOptions.search.enableAiSearch)
|
||||||
resultsBox.add(SearchButton({ text: entry.text }));
|
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();
|
resultsBox.show_all();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user