Skip to content

Commit

Permalink
Merge pull request #22 from rolandbernard/devel
Browse files Browse the repository at this point in the history
v0.0.13
  • Loading branch information
rolandbernard committed Dec 29, 2020
2 parents b30ca91 + b65dfa4 commit 1a6627a
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 26 deletions.
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.12",
"version": "0.0.13",
"license": "MIT",
"scripts": {
"dev": "electron-webpack dev",
Expand Down
1 change: 1 addition & 0 deletions src/common/local/english.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const translation_english = {

history: 'History',
history_description: 'This module allows you to execute recent options again',
searchable: 'Searchable',

color: 'Color',
color_description: 'This module allows you to convert colors between hex/rgb/hsl',
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 @@ -100,6 +100,7 @@ const translation_german = {

history: 'Verlauf',
history_description: 'Dieses Modul erlaub es Optionen erneut auszuführen',
searchable: 'Durchsuchbar',

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 @@ -100,6 +100,7 @@ const translation_italian = {

history: 'Cronologia',
history_description: 'Questo modulo consente di eseguire nuovamente le opzioni',
searchable: 'Cercabile',

color: 'Colori',
color_description: 'Questo modulo ti consente di convertite colori tra hex/rgb/hsl',
Expand Down
20 changes: 12 additions & 8 deletions src/common/util.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@

export function stringMatchQuality(text, pattern) {
const text_upper = text.toUpperCase();
const pattern_upper = pattern.toUpperCase();
if (text_upper === pattern_upper) {
return (text === pattern ? 1.0 : 0.9);
} else if (pattern_upper.startsWith(text_upper)) {
return 0.7 + 0.2 * (text_upper.length / pattern_upper.length);
} else if (pattern_upper.includes(text_upper)) {
return 0.5 + 0.4 * (text_upper.length / pattern_upper.length);
if(typeof text === "string" && typeof pattern === "string") {
const text_upper = text.toUpperCase();
const pattern_upper = pattern.toUpperCase();
if (text_upper === pattern_upper) {
return (text === pattern ? 1.0 : 0.9);
} else if (pattern_upper.startsWith(text_upper)) {
return 0.7 + 0.2 * (text_upper.length / pattern_upper.length);
} else if (pattern_upper.includes(text_upper)) {
return 0.5 + 0.4 * (text_upper.length / pattern_upper.length);
} else {
return 0;
}
} else {
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export let config_default = {
},
history: {
active: false,
searchable: true,
prefix: '',
quality: 0.1,
maximum_history: 1000,
Expand All @@ -132,6 +133,7 @@ export function loadConfig() {
config = mergeDeep(config, JSON.parse(readFileSync(config_path, { encoding: 'utf8' })));
} catch (e) { }
}
config.version = app.getVersion();
writeFileSync(config_path, JSON.stringify(config), { encoding: 'utf8' });
}

Expand Down
12 changes: 11 additions & 1 deletion src/main/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,21 @@ export function searchQuery(query, callback) {
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)
.slice(0, config.general.max_results);
.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);
}
Expand Down
26 changes: 24 additions & 2 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ async function toggleMain(op) {

let last_loading = null;

const MAX_TRANSFER_LEN = 1000;

async function startApp() {
const gotSingleInstanceLock = app.requestSingleInstanceLock();
if (gotSingleInstanceLock) {
Expand All @@ -95,17 +97,37 @@ async function startApp() {
createMainWindow();
createSettingsWindow();

const original_option = new Map();
ipcMain.on('input-change', (_, query) => {
clearTimeout(last_loading);
last_loading = setTimeout(() => main_window.webContents.send('update-options', null), config.general.debounce_time + 100);
searchQuery(query, (results) => {
clearTimeout(last_loading);
main_window.webContents.send('update-options', results);
original_option.clear();
main_window.webContents.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) + '...';
}
if (new_opt.primary?.length > MAX_TRANSFER_LEN) {
new_opt.primary = new_opt.primary.substr(0, MAX_TRANSFER_LEN) + '...';
}
if (new_opt.secondary?.length > MAX_TRANSFER_LEN) {
new_opt.secondary = new_opt.secondary.substr(0, MAX_TRANSFER_LEN) + '...';
}
original_option.set(JSON.stringify(new_opt), opt);
return new_opt;
}));
});
});
ipcMain.on('execute-option', (_, option) => {
if (option && option.executable) {
executeOption(option);
const key = JSON.stringify(option);
if(original_option.has(key)) {
executeOption(original_option.get(key));
} else {
executeOption(option);
}
if(!option.stay_open) {
toggleMain(false);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/modules/calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ const CalculatorModule = {
executable: true,
});
} catch(e) { }
return ret.filter((val, index) => val.primary.substr(2).trim() != query.trim() && ret.findIndex((v) => v.primary === val.primary) === index);
return ret.filter((val, index) =>
val.primary.substr(2).replace(/ /g, '').trim() !== query.replace(/ /g, '').trim()
&& ret.findIndex((v) => v.primary === val.primary) === index
);
},
execute: async (option) => {
clipboard.writeText(option.primary.substr(2));
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/folders.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function generateFilePreview(path) {
slashes: true,
}),
};
} else if(extname(path).match(/\.(mp3|wav|flac|mpeg)/i)) {
} else if(extname(path).match(/\.(mp3|wav|mpeg)/i)) {
return {
type: 'audio',
url: format({
Expand Down
25 changes: 20 additions & 5 deletions src/main/modules/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,28 @@ const HistoryModule = {
}
},
valid: (query) => {
return query.trim().length == 0;
return query.trim().length == 0 || config.modules.history.searchable;
},
search: async (query) => {
return execute_history.map((option) => ({
...option,
quality: config.modules.history.quality,
}));
if(query === "") {
return execute_history.map((option) => ({
...option,
quality: config.modules.history.quality
}));
} else {
return execute_history.map((option, i) => {
let quality = Math.max(
stringMatchQuality(query, option.primary),
stringMatchQuality(query, option.text),
stringMatchQuality(query, option.html),
stringMatchQuality(query, option.secondary)
);
return {
...option,
quality: Math.min(1.0, quality + quality / (i + 1))
};
});
}
},
globalExecute: async (option) => {
if (config.modules.history.active) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/locate.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function generateFilePreview(path) {
slashes: true,
}),
};
} else if(extname(path).match(/\.(mp3|wav|flac|mpeg)/i)) {
} else if(extname(path).match(/\.(mp3|wav|mpeg)/i)) {
return {
type: 'audio',
url: format({
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/main/display/icon-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function IconText(props) {
display: 'flex',
flexFlow: 'row nowrap',
padding: '0.5rem',
alignItems: 'center',
},
avatar_wrap: {
flex: '0 0 auto',
Expand All @@ -19,8 +20,6 @@ function IconText(props) {
},
text: {
flex: '1 1 auto',
display: 'flex',
flexFlow: 'column',
overflow: 'hidden',
textOverflow: 'ellipsis',
fontSize: '1rem',
Expand All @@ -29,7 +28,6 @@ function IconText(props) {
wordBreak: 'break-word',
padding: '0.25rem 0',
maxHeight: '15rem',
justifyContent: '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 @@ -113,6 +113,7 @@ const config_definition = [
], type: 'page', description: 'duckduckgo_description' },
{ name: 'history', active: 'active', options: [
{ name: 'active', type: 'boolean' },
{ name: 'searchable', type: 'boolean' },
{ name: 'prefix', type: 'text' },
{ name: 'quality', type: 'quality' },
{ name: 'maximum_history', type: 'size' },
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4228,9 +4228,9 @@ inherits@2.0.3:
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=

ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:
version "1.3.5"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==
version "1.3.8"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

internal-ip@^4.3.0:
version "4.3.0"
Expand Down

0 comments on commit 1a6627a

Please sign in to comment.