Skip to content

Commit

Permalink
Merge pull request #34 from rolandbernard/devel
Browse files Browse the repository at this point in the history
v0.0.24
  • Loading branch information
rolandbernard committed Mar 30, 2021
2 parents 276d1ec + 0b5e821 commit 261ed8e
Show file tree
Hide file tree
Showing 10 changed files with 671 additions and 1,230 deletions.
29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marvin",
"version": "0.0.23",
"version": "0.0.24",
"license": "MIT",
"scripts": {
"dev": "electron-webpack dev",
Expand All @@ -13,32 +13,31 @@
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.55",
"algebrite": "^1.3.1",
"async-lock": "^1.2.4",
"lz4js": "^0.2.0",
"material-icons": "^0.3.1",
"material-ui-color": "^0.4.4",
"mathjs": "^7.0.2",
"material-icons": "^0.5.4",
"material-ui-color": "^1.1.0",
"mathjs": "^9.3.0",
"node-fetch": "^2.6.1",
"puppeteer-core": "^5.2.0",
"puppeteer-core": "^8.0.0",
"puppeteer-in-electron": "^3.0.3",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"source-map-support": "^0.5.16",
"sqlite3": "5.0.0",
"sqlite3": "^5.0.2",
"styled-components": "^5.1.1",
"typeface-roboto": "^0.0.75"
"typeface-roboto": "^1.1.13"
},
"devDependencies": {
"@babel/core": "^7.10.3",
"@babel/preset-react": "^7.10.1",
"babel-loader": "^8.1.0",
"css-loader": "^3.6.0",
"electron": "^11.0.0",
"electron-builder": "^22.4.1",
"css-loader": "^5.2.0",
"electron": "^12.0.2",
"electron-builder": "^22.10.5",
"electron-webpack": "^2.8.2",
"file-loader": "^6.0.0",
"style-loader": "^1.2.1",
"webpack": "~4.42.1"
"style-loader": "^2.0.0",
"webpack": "^5.28.0"
},
"electronWebpack": {
"renderer": {
Expand Down
7 changes: 4 additions & 3 deletions src/common/local/english.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const TRANSLATION_ENGLISH = {
quality: 'Priority',

linux_system: 'Linux system',
linux_system_description: 'This module will provide some fundamantal linux system commands',
linux_system_description: 'This module will provide some fundamental linux system commands',
reboot: 'Reboot',
shutdown: 'Shutdown',

Expand Down Expand Up @@ -116,18 +116,19 @@ const TRANSLATION_ENGLISH = {
history_description: 'This module allows you to execute recent options again',
searchable: 'Searchable',
sort_by_frequency: 'Sort by frequency',
weight_by_frequency: 'Weighted by frequency',

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',
web_search_description: 'This module allows you to quickly 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',
alias_description: 'This module allows you to add an alias for a certain option, that allows you to search it under a different name',
aliases: 'Aliases',
option: 'Option',
prefix_text: 'Add name as prefix',
Expand Down
1 change: 1 addition & 0 deletions src/common/local/german.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const TRANSLATION_GERMAN = {
history_description: 'Dieses Modul erlaub es Optionen erneut auszuführen',
searchable: 'Durchsuchbar',
sort_by_frequency: 'Sortieren nach Häufigkeit',
weight_by_frequency: 'Gewichtet nach Häufigkeit',

color: 'Farben',
color_description: 'Mit diesem Modul ist es möglich Farben zwischen hex/rgb/hsl unzuwandeln',
Expand Down
1 change: 1 addition & 0 deletions src/common/local/italian.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const TRANSLATION_ITALIAN = {
history_description: 'Questo modulo consente di eseguire nuovamente le opzioni',
searchable: 'Cercabile',
sort_by_frequency: 'Ordina per frequenza',
weight_by_frequency: 'Ponderato secondo la frequenza',

color: 'Colori',
color_description: 'Questo modulo ti consente di convertite colori tra hex/rgb/hsl',
Expand Down
1 change: 1 addition & 0 deletions src/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const CONFIG_DEFAULT = {
quality: 0.1,
maximum_history: 1000,
sort_by_frequency: false,
weight_by_frequency: false,
},
color: {
active: false,
Expand Down
66 changes: 32 additions & 34 deletions src/main/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { config } from "./config";
import MainModule from "./modules/main";
import SettingsModule from "./modules/settings";
import LinuxSystemModule from './modules/linux-system';
import AsyncLock from "async-lock";
import FoldersModule from "./modules/folders";
import HtmlModule from "./modules/html";
import CalculatorModule from "./modules/calculator";
Expand Down Expand Up @@ -77,7 +76,6 @@ export function searchQuery(query, callback) {
last_query_timeout = setTimeout(async () => {
query = query.trim();
let results = [];
let lock = new AsyncLock();
let to_eval;
if (config.general.exclusive_module_prefix) {
let prefix = '';
Expand All @@ -99,51 +97,51 @@ export function searchQuery(query, callback) {
? config.modules[id].active && !config.modules[id].prefix : true);
}
const query_regex = generateSearchRegex(query);
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 {
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, reject) => {
try {
let result = (await MODULES[id].search(
config.modules[id]?.prefix ? query.replace(config.modules[id].prefix, '').trim() : query,
config.modules[id]?.prefix
? generateSearchRegex(query.replace(config.modules[id].prefix, '').trim())
: query_regex
? generateSearchRegex(query.replace(config.modules[id].prefix, '').trim())
: query_regex
));
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();
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();
reject();
}
} catch (e) {
console.error(e);
} finally {
resolv();
}
});
})
);
);
} catch (e) { }
if (exec_id === begin_id) {
callback(results);
}
Expand Down
38 changes: 22 additions & 16 deletions src/main/modules/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,43 @@ const HistoryModule = {
quality: config.modules.history.quality
})).sort((a, b) => config.modules.history.sort_by_frequency ? b.history_frequency - a.history_frequency : 0);
} else {
return execute_history.map((option, i) => {
return execute_history.map((option) => {
let quality = Math.max(
stringMatchQuality(query, option.primary, regex),
stringMatchQuality(query, option.text, regex),
0.75 * stringMatchQuality(query, option.secondary, regex),
0.5 * stringMatchQuality(query, option.html, regex)
);
) * (config.modules.history.weight_by_frequency ? (2 * Math.atan(option.history_frequency)) : 1);
return {
...option,
quality: Math.min(1.0, quality + quality / (i + 1)),
quality: Math.min(1.0, quality),
};
}).sort((a, b) => config.modules.history.sort_by_frequency ? b.history_frequency - a.history_frequency : 0);
}
},
globalExecute: async (option) => {
function getOptionKey(el) {
return (el.type || "")
+ "---" + (el.text || "")
+ "---" + (el.primary || "")
+ "---" + (el.secondary || "")
+ "---" + (el.html || "");
}
if (config.modules.history.active) {
let existing = new Set();
execute_history.forEach((option) => {
// Making old information less important
option.history_frequency *= 0.99;
});
option.history_frequency = 1 + (option.history_frequency || 0);
execute_history = [option].concat(execute_history).filter((el) => {
let value = (el.type || "") + (el.text || "") + (el.primary || "") + (el.secondary || "") + (el.html || "");
if (!existing.has(value)) {
existing.add(value);
return true;
let key = getOptionKey(option);
let old_frequency = 0;
for (let i = 0; i < execute_history.length;) {
if (key === getOptionKey(execute_history[i])) {
old_frequency = execute_history[i].history_frequency;
execute_history.splice(i, 1);
} else {
return false;
execute_history[i].history_frequency *= 0.99;
i++;
}
}).slice(0, config.modules.history.maximum_history);
}
option.history_frequency = old_frequency + 1;
execute_history.unshift(option);
execute_history.splice(config.modules.history.maximum_history);
updateHistory();
}
},
Expand Down
7 changes: 2 additions & 5 deletions src/renderer/common/output-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ class OutputList extends React.Component {
}

componentDidUpdate() {
if (this.selected.current) {
this.selected.current.scrollIntoView({
behavior: this.props.config.general.smooth_scrolling ? 'smooth' : 'instant',
block: this.props.center ? 'center' : 'nearest'
});
if (this.selected.current && this.props.center) {
this.selected.current.scrollIntoView({ behavior: this.props.config.general.smooth_scrolling ? 'smooth' : 'instant', block: 'center' });
}
}

Expand Down
1 change: 1 addition & 0 deletions src/renderer/settings/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const CONFIG_DEFINITION = [
{ name: 'quality', type: 'quality' },
{ name: 'maximum_history', type: 'size' },
{ name: 'sort_by_frequency', type: 'boolean' },
{ name: 'weight_by_frequency', type: 'boolean' },
{ name: 'clear_history', type: 'button', warning: true, action: 'reset-history' },
], type: 'page', description: 'history_description'
},
Expand Down
Loading

0 comments on commit 261ed8e

Please sign in to comment.