Skip to content

Commit

Permalink
Merge pull request #8 from rolandbernard/devel
Browse files Browse the repository at this point in the history
0.0.6
  • Loading branch information
rolandbernard committed Aug 1, 2020
2 parents 11fcb40 + 0c329db commit d19cb54
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 33 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.5",
"version": "0.0.6",
"license": "MIT",
"scripts": {
"dev": "electron-webpack dev",
Expand Down
3 changes: 3 additions & 0 deletions src/common/local/english.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const translation_english = {
max_height: 'Maximum height [px]',
max_results: 'Maximum results',
incremental_results: 'Incremental results',
smooth_scrolling: 'Smooth scrolling',

theme: 'Color theme',
background_color: 'Background color',
Expand Down Expand Up @@ -46,6 +47,8 @@ const translation_english = {

calculator: 'Calculator',
calculator_description: 'This module allows you to do calculations using mathjs',
simplified: 'simplified',
rationalized: 'rationalized',

linux_applications: 'Linux applications',
linux_applications_description: 'This module allows you to start applications on linux',
Expand Down
3 changes: 3 additions & 0 deletions src/common/local/german.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const translation_german = {
max_height: 'Maximale Höhe [px]',
max_results: 'Maximale Ergebnisse',
incremental_results: 'Inkrementelle Ergebnisse',
smooth_scrolling: 'Flüssiges Scrollen',

theme: 'Farbschema',
background_color: 'Hintergundfarbe',
Expand Down Expand Up @@ -46,6 +47,8 @@ const translation_german = {

calculator: 'Taschenrechner',
calculator_description: 'Mit diesem Modul können Sie Berechnungen mithilfe von mathjs durchführen',
simplified: 'vereinfacht',
rationalized: 'rationalisiert',

linux_applications: 'Linux Anwendungen',
linux_applications_description: 'Mit diesem Modul können Sie Anwendungen unter Linux starten',
Expand Down
3 changes: 3 additions & 0 deletions src/common/local/italian.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const translation_italian = {
max_height: 'Altezza massima [px]',
max_results: 'Risultati massimi',
incremental_results: 'Risultati incrementali',
smooth_scrolling: 'Scorrimento regolare',

theme: 'Combinazione di colori',
background_color: 'Colore di sfondo',
Expand Down Expand Up @@ -46,6 +47,8 @@ const translation_italian = {

calculator: 'Calcolatore',
calculator_description: 'Questo modulo ti permette di fare calcoli usando mathjs',
simplified: 'semplificato',
rationalized: 'razionalizzato',

linux_applications: 'Applicazioni Linux',
linux_applications_description: 'Questo modulo consente di avviare applicazioni su Linux',
Expand Down
1 change: 1 addition & 0 deletions src/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export let config = {
max_height: 500,
max_results: 200,
incremental_results: true,
smooth_scrolling: true,
},
theme: {
background_color: 'black',
Expand Down
38 changes: 32 additions & 6 deletions src/main/modules/calculator.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@

import { config } from "../config";
import * as math from 'mathjs';
import { clipboard } from 'electron';
import { getTranslation } from '../../common/local/locale';

const CalculatorModule = {
valid: (query) => {
return config.modules.calculator.active && query.trim().length >= 1;
},
search: async (query) => {
const ret = [];
try {
return [{
ret.push({
type: 'icon_list_item',
material_icon: 'functions',
primary: '= ' + math.evaluate(query),
primary: '= ' + math.evaluate(query).toString(),
secondary: query,
quality: config.modules.calculator.quality,
}];
} catch(e) {
return [];
}
executable: true,
});
} catch(e) { }
try {
ret.push({
type: 'icon_list_item',
material_icon: 'functions',
primary: '= ' + math.simplify(query).toString(),
secondary: query + ' ' + getTranslation(config, 'simplified'),
quality: config.modules.calculator.quality,
executable: true,
});
} catch(e) { }
try {
ret.push({
type: 'icon_list_item',
material_icon: 'functions',
primary: '= ' + math.rationalize(query).toString(),
secondary: query + ' ' + getTranslation(config, 'rationalized'),
quality: config.modules.calculator.quality,
executable: true,
});
} catch(e) { }
return ret.filter((val, index) => val.primary.substr(2).trim() != query.trim() && ret.findIndex((v) => v.primary === val.primary) === index);
},
execute: async (option) => {
clipboard.writeText(option.primary.substr(2));
},
}

Expand Down
30 changes: 20 additions & 10 deletions src/main/modules/deepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,25 @@ const DeeplModule = {
height: 1000,
resizable: false,
});
const url = 'https://www.deepl.com/translator';
await window.loadURL(url);;
while(!browser) {
await new Promise((res) => setTimeout(() => res(), 100));
}
page = await pie.getPage(browser, window);
try {
await page.click('.dl_cookieBanner--buttonSelected');
} catch (e) { }
(async () => {
const url = 'https://www.deepl.com/translator';
let success = false;
while (!success) {
try {
await window.loadURL(url);;
success = true;
} catch (e) {
await new Promise(res => setTimeout(() => res(), 500));
}
}
while (!browser) {
await new Promise((res) => setTimeout(() => res(), 100));
}
page = await pie.getPage(browser, window);
try {
await page.click('.dl_cookieBanner--buttonSelected');
} catch (e) { }
})()
}
},
update: async (old_config) => {
Expand All @@ -58,7 +68,7 @@ const DeeplModule = {
}
},
valid: (query) => {
if (config.modules.deepl.active) {
if (config.modules.deepl.active && page) {
if (cancel_last) {
cancel_last();
cancel_last = null;
Expand Down
36 changes: 23 additions & 13 deletions src/main/modules/google-translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,27 @@ const GoogleTranslateModule = {
height: 1000,
resizable: false,
});
const url = 'https://translate.google.com/';
await window.loadURL(url);;
while(!browser) {
await new Promise((res) => setTimeout(() => res(), 100));
}
page = await pie.getPage(browser, window);
try {
await page.click('.tlid-open-source-language-list');
await page.waitFor(100);
await page.click('.language-list-unfiltered-langs-sl_list .language_list_item_wrapper-auto');
} catch (e) { }
(async () => {
const url = 'https://translate.google.com/';
let success = false;
while (!success) {
try {
await window.loadURL(url);;
success = true;
} catch (e) {
await new Promise(res => setTimeout(() => res(), 500));
}
}
while (!browser) {
await new Promise((res) => setTimeout(() => res(), 100));
}
page = await pie.getPage(browser, window);
try {
await page.click('.tlid-open-source-language-list');
await page.waitFor(100);
await page.click('.language-list-unfiltered-langs-sl_list .language_list_item_wrapper-auto');
} catch (e) { }
})();
}
},
update: async (old_config) => {
Expand All @@ -158,7 +168,7 @@ const GoogleTranslateModule = {
}
},
valid: (query) => {
if (config.modules.google_translate.active) {
if (config.modules.google_translate.active && page) {
if (cancel_last) {
cancel_last();
cancel_last = null;
Expand Down Expand Up @@ -246,7 +256,7 @@ const GoogleTranslateModule = {
resolve();
return;
}
await page.waitFor(100);
await page.waitFor(500);
if (stop) {
resolve();
return;
Expand Down
23 changes: 21 additions & 2 deletions src/main/modules/linux-applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,36 @@ function createIconIndex(theme, fallback_theme) {
if (!icon_index[path.basename(value)]) {
icon_index[path.basename(value)] = value;
}
if (!icon_index[path.basename(value).toLowerCase()]) {
icon_index[path.basename(value).toLowerCase()] = value;
}
});
exec(`find -L ${icon_path}/${fallback_theme}/ -type f`, { maxBuffer: 1024 * 1024 * 500 }, (_, stdout, __) => {
stdout.split('\n').forEach((value) => {
if (!icon_index[path.basename(value)]) {
icon_index[path.basename(value)] = value;
}
if (!icon_index[path.basename(value).toLowerCase()]) {
icon_index[path.basename(value).toLowerCase()] = value;
}
});
exec(`find -L ${icon_path}/ -type f`, { maxBuffer: 1024 * 1024 * 500 }, (_, stdout, __) => {
stdout.split('\n').forEach((value) => {
if (!icon_index[path.basename(value)]) {
icon_index[path.basename(value)] = value;
}
if (!icon_index[path.basename(value).toLowerCase()]) {
icon_index[path.basename(value).toLowerCase()] = value;
}
});
exec(`find -L ${icon_path_pixmaps}/ -type f`, { maxBuffer: 1024 * 1024 * 500 }, (_, stdout, __) => {
stdout.split('\n').forEach((value) => {
if (!icon_index[path.basename(value)]) {
icon_index[path.basename(value)] = value;
}
if (!icon_index[path.basename(value).toLowerCase()]) {
icon_index[path.basename(value).toLowerCase()] = value;
}
});
resolve();
});
Expand All @@ -88,7 +100,14 @@ function findIconPath(name) {
if(exist) {
resolve(name);
} else {
const possible = [`${name}`, `${name}.svg`, `${name}.png`];
const possible = [
`${name}`,
`${name}.svg`,
`${name}.png`,
`${name.toLowerCase()}`,
`${name.toLowerCase()}.svg`,
`${name.toLowerCase()}.png`
];
for(let file of possible) {
if(icon_index[file]) {
resolve(icon_index[file]);
Expand Down Expand Up @@ -182,7 +201,7 @@ async function loadApplications() {
const path = await findIconPath(getProp(value, 'Icon'), theme, fallback_theme);
if (path) {
icons[getProp(value, 'Icon')] = await pathToDataUrl(path);
}
}
}
}));
}));
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/main/output-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OutputList extends React.Component {

componentDidUpdate() {
if(this.selected.current) {
this.selected.current.scrollIntoView({ behavior: 'smooth', block: '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 @@ -8,6 +8,7 @@ const config_definition = [
{ name: 'max_height', type: 'size' },
{ name: 'max_results', type: 'size' },
{ name: 'incremental_results', type: 'boolean' },
{ name: 'smooth_scrolling', type: 'boolean' },
], type: 'page' },
{ name: 'theme', icon: 'palette', options: [
{ name: 'background_color', type: 'color' },
Expand Down

0 comments on commit d19cb54

Please sign in to comment.