Skip to content

Commit

Permalink
v0.0.8
Browse files Browse the repository at this point in the history
v0.0.8
  • Loading branch information
rolandbernard committed Sep 15, 2020
2 parents 915498b + dc8041c commit 480ce48
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 10 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ This module allows you to translate text by using Google Translate in a headless
This module gives you the DuckDuckGo Instant Answers for your query.

![screenshot](assets/duckduckgo.png)

#### History
This module allows you to execute recent options again.

![screenshot](assets/history.png)

Binary file added assets/history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marvin",
"version": "0.0.7",
"version": "0.0.8",
"license": "MIT",
"scripts": {
"dev": "electron-webpack dev",
Expand All @@ -20,7 +20,7 @@
"material-icons": "^0.3.1",
"material-ui-color": "^0.4.4",
"mathjs": "^7.0.2",
"node-fetch": "^2.6.0",
"node-fetch": "^2.6.1",
"puppeteer-core": "^5.2.0",
"puppeteer-in-electron": "^3.0.3",
"react": "^16.13.1",
Expand Down
4 changes: 4 additions & 0 deletions src/common/local/english.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const translation_english = {

linux_applications: 'Linux applications',
linux_applications_description: 'This module allows you to start applications on linux',
refresh_interval_min: 'Refresh interval [min]',

url: 'URL module',
url_description: 'This module allows you to open urls',
Expand Down Expand Up @@ -88,6 +89,9 @@ const translation_english = {

duckduckgo: 'DuckDuckGo Instant Answer',
duckduckgo_description: 'This module gives you the DuckDuckGo Instant Answers for your query',

history: 'History',
history_description: 'This module allows you to execute recent options again',
};

export default translation_english;
4 changes: 4 additions & 0 deletions src/common/local/german.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const translation_german = {

linux_applications: 'Linux Anwendungen',
linux_applications_description: 'Mit diesem Modul können Sie Anwendungen unter Linux starten',
refresh_interval_min: 'Aktualisierungsintervall [min]',

url: 'URL Modul',
url_description: 'Mit diesem Modul ist es möglich URLs zu öffnen',
Expand Down Expand Up @@ -88,6 +89,9 @@ const translation_german = {

duckduckgo: 'DuckDuckGo Instant Answer',
duckduckgo_description: 'Dieses Modul gibt Ihnen die DuckDuckGo-Sofortantworten für Ihre Anfrage',

history: 'Verlauf',
history_description: 'Dieses Modul erlaub es Optionen erneut auszuführen',
};

export default translation_german;
4 changes: 4 additions & 0 deletions src/common/local/italian.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const translation_italian = {

linux_applications: 'Applicazioni Linux',
linux_applications_description: 'Questo modulo consente di avviare applicazioni su Linux',
refresh_interval_min: 'Intervallo di aggiornamento [min]',

url: 'URL modulo',
url_description: 'Questo modulo ti consente di aprire gli URL',
Expand Down Expand Up @@ -88,6 +89,9 @@ const translation_italian = {

duckduckgo: 'DuckDuckGo Instant Answer',
duckduckgo_description: 'Questo modulo fornisce le risposte istantanee DuckDuckGo per la tua query',

history: 'Cronologia',
history_description: 'Questo modulo consente di eseguire nuovamente le opzioni',
};

export default translation_italian;
4 changes: 2 additions & 2 deletions src/common/local/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const transalations = {

export function getTranslation(config, text) {
if(config && config.general && config.general.language) {
return transalations[config.general.language][text] || transalations['en'][text];
return transalations[config.general.language][text] || transalations['en'][text] || text;
} else {
return transalations['en'][text];
return transalations['en'][text] || text;
}
}
6 changes: 6 additions & 0 deletions src/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export let config = {
linux_applications: {
active: true,
directories: [ "/usr/share/applications/", path.join(app.getPath('home'), '.local/share/applications/') ],
refresh_interval_min: 30,
},
url: {
active: true,
Expand Down Expand Up @@ -80,6 +81,11 @@ export let config = {
debounce_time: 500,
quality: 0.1,
},
history: {
active: false,
quality: 0.1,
maximum_history: 1000,
},
},
};

Expand Down
5 changes: 4 additions & 1 deletion src/main/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import DeeplModule from "./modules/deepl";
import LinuxWindowsModule from "./modules/linux-windows";
import GoogleTranslateModule from "./modules/google-translate";
import DuckduckgoModule from "./modules/duckduckgo";
import HistoryModule from "./modules/history";

const modules = {
settings: SettingsModule,
Expand All @@ -35,6 +36,7 @@ const modules = {
linux_windows: LinuxWindowsModule,
google_translate: GoogleTranslateModule,
duckduckgo: DuckduckgoModule,
history: HistoryModule,
};

export function initModules() {
Expand Down Expand Up @@ -67,7 +69,7 @@ export function searchQuery(query, callback) {
lock.acquire('results', () => {
if (exec_id === begin_id) {
results = results
.concat(result.map((option) => ({ ...option, module: id })))
.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);
Expand Down Expand Up @@ -95,5 +97,6 @@ export function searchQuery(query, callback) {
}

export function executeOption(option) {
Object.values(modules).forEach((module) => module.globalExecute && module.globalExecute(option));
return modules[option.module].execute(option);
}
60 changes: 60 additions & 0 deletions src/main/modules/history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

import { existsSync, readFileSync, writeFileSync } from "fs";
import { app } from 'electron';
import { config } from '../config';
import { stringMatchQuality } from '../../common/util';
import { getTranslation } from '../../common/local/locale';
import path from 'path';

let execute_history = [];

const history_filename = 'history.json';

function loadHistory() {
const history_path = path.join(app.getPath('userData'), history_filename);
if (existsSync(history_path)) {
try {
execute_history = JSON.parse(readFileSync(history_path, { encoding: 'utf8' }));
} catch (e) { }
}
writeFileSync(history_path, JSON.stringify(execute_history), { encoding: 'utf8' });
}

function updateHistory() {
const history_path = path.join(app.getPath('userData'), history_filename);
writeFileSync(history_path, JSON.stringify(execute_history), { encoding: 'utf8' });
}

const HistoryModule = {
init: async () => {
if (config.modules.history.active) {
loadHistory();
}
},
valid: (query) => {
return config.modules.history.active && query.trim().length == 0;
},
search: async (query) => {
return execute_history.map((option) => ({
...option,
quality: config.modules.history.quality,
}));
},
globalExecute: async (option) => {
if (config.modules.history.active) {
let existing = new Set();
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;
} else {
return false;
}
}).slice(0, config.modules.history.maximum_history);
updateHistory();
}
},
}

export default HistoryModule;
11 changes: 10 additions & 1 deletion src/main/modules/linux-applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,22 @@ async function loadApplications() {
}));
}

let update_interval = null;

const LinuxApplicationModule = {
init: async () => {
if(config.modules.linux_applications.active) {
await loadApplications();
update_interval = setInterval(() => loadApplications(), 60 * 1000 * config.modules.linux_applications.refresh_interval_min);
}
},
update: async () => {
await LinuxApplicationModule.deinit();
await LinuxApplicationModule.init();
},
deinit: async () => {
clearInterval(update_interval);
},
valid: (query) => {
return config.modules.linux_applications.active && query.trim().length >= 1;
},
Expand All @@ -234,7 +241,9 @@ const LinuxApplicationModule = {
0.75 * stringMatchQuality(query, desc),
0.75 * stringMatchQuality(query, getProp(app.desktop, 'Keywords', '')),
0.75 * stringMatchQuality(query, getProp(app.desktop, 'Categories', '')),
0.75 * stringMatchQuality(query, getProp(app.desktop, 'GenericName', ''))),
0.75 * stringMatchQuality(query, app.application.replace('.desktop', '')),
0.75 * stringMatchQuality(query, getProp(app.desktop, 'GenericName', '')),
0.25 * stringMatchQuality(query, getProp(value, 'Name', name))),
app: value,
}));
}).reduce((a, b) => a.concat(b));
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/settings/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const config_definition = [
{ name: 'linux_applications', active: 'active', options: [
{ name: 'active', type: 'boolean' },
{ name: 'directories', type: 'array', base: { name: 'path', type: 'path' }, default: '/' },
{ name: 'refresh_interval_min', type: 'size' },
], type: 'page', description: 'linux_applications_description' },
{ name: 'url', active: 'active', options: [
{ name: 'active', type: 'boolean' },
Expand Down Expand Up @@ -86,6 +87,11 @@ const config_definition = [
{ name: 'debounce_time', type: 'size' },
{ name: 'quality', type: 'quality' },
], type: 'page', description: 'duckduckgo_description' },
{ name: 'history', active: 'active', options: [
{ name: 'active', type: 'boolean' },
{ name: 'quality', type: 'quality' },
{ name: 'maximum_history', type: 'size' },
], type: 'page', description: 'history_description' },
], type: 'subheader' }
];

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5099,10 +5099,10 @@ no-case@^3.0.3:
lower-case "^2.0.1"
tslib "^1.10.0"

node-fetch@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
node-fetch@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==

node-forge@0.9.0:
version "0.9.0"
Expand Down

0 comments on commit 480ce48

Please sign in to comment.