Skip to content

Commit

Permalink
Merge pull request #23 from rolandbernard/devel
Browse files Browse the repository at this point in the history
v0.0.14
  • Loading branch information
rolandbernard committed Jan 4, 2021
2 parents 31a984d + d360b76 commit 38ce861
Show file tree
Hide file tree
Showing 32 changed files with 421 additions and 133 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
dist/
node_modules/
thumbs.db
.idea/
.idea/

todo.md
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,13 @@ This module allows you to convert colors between hex/rgb/hsl.

![screenshot](assets/color.png)

#### Web search
This module allows you to quicky do a web search. It will open a URL, by inserting the query at a specific location.

![screenshot](assets/web_search.png)

#### Alias
This module allows you to add an alias for a certail option, that allows you to search it under a different name.

![screenshot](assets/alias.png)

Binary file added assets/alias.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/web_search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marvin",
"version": "0.0.13",
"version": "0.0.14",
"license": "MIT",
"scripts": {
"dev": "electron-webpack dev",
Expand Down
11 changes: 11 additions & 0 deletions src/common/local/english.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ const translation_english = {
color: 'Color',
color_description: 'This module allows you to convert colors between hex/rgb/hsl',
color_preview: 'Color preview',

web_search: 'Web search',
web_search_description: 'This module allows you to quicky do a web search',
patterns: 'Patterns',
url_pattern: 'URL',

alias: 'Alias',
alias_description: 'This module allows you to add an alias for a certail option, that allows you to search it under a different name',
aliases: 'Aliases',
option: 'Option',
prefix_text: 'Add name as prefix',
};

export default translation_english;
11 changes: 11 additions & 0 deletions src/common/local/german.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ const translation_german = {
color: 'Farben',
color_description: 'Mit diesem Modul ist es möglich Farben zwischen hex/rgb/hsl unzuwandeln',
color_preview: 'Farben-Vorschau',

web_search: 'Web-Suche',
web_search_description: 'Mit diesem Modul ist es möglich schnell Websuchen durchzuführen',
patterns: 'Muster',
url_pattern: 'URL',

alias: 'Alias',
alias_description: 'Mit diesem Modul können Sie einen Alias für eine bestimmte Option hinzufügen, mit welchem dann nach der Option gesucht werden kann',
aliases: 'Aliase',
option: 'Option',
prefix_text: 'Name als Präfix hinzufügen',
};

export default translation_german;
11 changes: 11 additions & 0 deletions src/common/local/italian.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ const translation_italian = {
color: 'Colori',
color_description: 'Questo modulo ti consente di convertite colori tra hex/rgb/hsl',
color_preview: 'Anteprima colore',

web_search: 'Ricerca sul web',
web_search_description: 'Questo modulo consente di effettuare rapidamente una ricerca sul web',
patterns: 'Modelli',
url_pattern: 'URL',

alias: 'Alias',
alias_description: 'Con questo modulo è possibile aggiungere un alias per un\'opzione specifica, che può poi essere utilizzato per cercare l\'opzione',
aliases: 'Alias',
option: 'Opzione',
prefix_text: 'Aggiungi il nome come prefisso',
};

export default translation_italian;
6 changes: 3 additions & 3 deletions src/common/local/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export const supported_languages = {
};

const transalations = {
'en': translation_english,
'it': translation_italian,
'de': translation_german,
'en': { ...translation_english, ...supported_languages },
'it': { ...translation_italian, ...supported_languages },
'de': { ...translation_german, ...supported_languages },
};

export function getTranslation(config, text) {
Expand Down
18 changes: 18 additions & 0 deletions src/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ export let config_default = {
quality: 1,
color_preview: false,
},
web_search: {
active: false,
prefix: '',
patterns: [
{ prefix: 'd?', url_pattern: 'https://duckduckgo.com/?q=$' },
{ prefix: 'g?', url_pattern: 'https://www.google.com/search?q=$' },
{ prefix: 'b?', url_pattern: 'https://www.bing.com/search?q=$' },
{ prefix: 'w?', url_pattern: 'https://en.wikipedia.org/wiki/Special:Search?search=$' },
{ prefix: 's?', url_pattern: 'https://stackoverflow.com/search?q=$' },
],
url_preview: false,
},
alias: {
active: false,
prefix: '',
aliases: [ ],
prefix_text: true,
},
},
};

Expand Down
80 changes: 43 additions & 37 deletions src/main/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import GoogleTranslateModule from "./modules/google-translate";
import DuckduckgoModule from "./modules/duckduckgo";
import HistoryModule from "./modules/history";
import ColorModule from "./modules/color";
import WebSearchModule from "./modules/web-search";
import AliasModule from "./modules/alias";

const modules = {
settings: SettingsModule,
Expand All @@ -39,6 +41,8 @@ const modules = {
duckduckgo: DuckduckgoModule,
history: HistoryModule,
color: ColorModule,
web_search: WebSearchModule,
alias: AliasModule,
};

export function initModules() {
Expand Down Expand Up @@ -71,44 +75,46 @@ export function searchQuery(query, callback) {
to_eval = Object.keys(modules).filter((id) => config.modules[id]
? config.modules[id].active && !config.modules[id].prefix : true);
}
await Promise.all(to_eval.filter((id) => config.modules[id]?.prefix
? modules[id].valid(query.replace(config.modules[id].prefix, '').trim()) : modules[id].valid(query))
.map((id) => {
return new Promise(async (resolv) => {
try {
let result = (await modules[id].search(config.modules[id]?.prefix ? query.replace(config.modules[id].prefix, '').trim() : query));
lock.acquire('results', () => {
if (exec_id === begin_id) {
let existing = new Set();
results = results
.concat(result.map((option) => ({ module: id, ...option })))
.filter((option) => option.quality > 0)
.sort((a, b) => b.quality - a.quality)
.filter((el) => {
let value = (el.type || "") + (el.text || "") + (el.primary || "") + (el.secondary || "") + (el.html || "");
if (!existing.has(value)) {
existing.add(value);
return true;
} else {
return false;
}
})
.slice(0, config.general.max_results)
if (config.general.incremental_results && results.length > 0) {
callback(results);
await Promise.all(
to_eval.filter((id) => (
config.modules[id]?.prefix ? modules[id].valid(query.replace(config.modules[id].prefix, '').trim()) : modules[id].valid(query)
))
.map((id) => {
return new Promise(async (resolv) => {
try {
let result = (await modules[id].search(config.modules[id]?.prefix ? query.replace(config.modules[id].prefix, '').trim() : query));
await lock.acquire('results', () => {
if (exec_id === begin_id) {
let existing = new Set();
results = results
.concat(result.map((option) => ({ module: id, ...option })))
.filter((option) => option.quality > 0)
.sort((a, b) => b.quality - a.quality)
.filter((el) => {
let value = (el.type || "") + (el.text || "") + (el.primary || "") + (el.secondary || "") + (el.html || "");
if (!existing.has(value)) {
existing.add(value);
return true;
} else {
return false;
}
})
.slice(0, config.general.max_results)
if (config.general.incremental_results && results.length > 0) {
callback(results);
}
} else {
resolve();
}
} else {
resolve();
}
});
} catch(e) {
console.error(e);
resolve();
} finally {
resolv();
}
});
}));
});
} catch(e) {
console.error(e);
} finally {
resolv();
}
});
})
);
if(exec_id === begin_id) {
callback(results);
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ function createMainWindow() {

async function toggleMain(op) {
if (main_window && !main_window.isDestroyed()) {
main_window.webContents.send('reset', config);
main_window.webContents.send('update-config', config);
main_window.webContents.send('reset');
if ((op === undefined || !op ) && main_window.isVisible()) {
await new Promise(res => setTimeout(() => res(), 50));
main_window.hide();
Expand Down Expand Up @@ -98,13 +99,13 @@ async function startApp() {
createSettingsWindow();

const original_option = new Map();
ipcMain.on('input-change', (_, query) => {
ipcMain.on('search-options', (msg, query) => {
clearTimeout(last_loading);
last_loading = setTimeout(() => main_window.webContents.send('update-options', null), config.general.debounce_time + 100);
last_loading = setTimeout(() => msg.sender.send('update-options', null), config.general.debounce_time + 100);
searchQuery(query, (results) => {
clearTimeout(last_loading);
original_option.clear();
main_window.webContents.send('update-options', results.map((opt) => {
msg.sender.send('update-options', results.map((opt) => {
const new_opt = { ...opt };
if (new_opt.text?.length > MAX_TRANSFER_LEN) {
new_opt.text = new_opt.text.substr(0, MAX_TRANSFER_LEN) + '...';
Expand Down Expand Up @@ -133,7 +134,7 @@ async function startApp() {
}
}
});
ipcMain.on('config-update', async (_, new_config) => {
ipcMain.on('update-config', async (_, new_config) => {
if (config.general.global_shortcut !== new_config.general.global_shortcut) {
try {
const ret = globalShortcut.register(new_config.general.global_shortcut, toggleMain);
Expand Down
26 changes: 26 additions & 0 deletions src/main/modules/alias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import { stringMatchQuality } from "../../common/util";
import { config } from "../config";

const AliasModule = {
valid: () => {
return true;
},
search: async (query) => {
if (config.modules.alias.prefix_text) {
return config.modules.alias.aliases.filter((entry) => entry.option).map((entry) => ({
...entry.option,
primary: (entry.name + ': ' + entry.option.primary),
text: (entry.name + ': ' + entry.option.text),
quality: query.length >= 1 ? stringMatchQuality(query, entry.name) : entry.default_quality,
}));
} else {
return config.modules.alias.aliases.map((entry) => ({
...entry.option,
quality: query.length >= 1 ? stringMatchQuality(query, entry.name) : entry.default_quality,
}));
}
},
}

export default AliasModule;
Loading

0 comments on commit 38ce861

Please sign in to comment.