Skip to content

Commit

Permalink
Merge pull request #24 from rolandbernard/devel
Browse files Browse the repository at this point in the history
v0.0.15
  • Loading branch information
rolandbernard committed Jan 9, 2021
2 parents 38ce861 + 766d33f commit 30e9e15
Show file tree
Hide file tree
Showing 25 changed files with 1,052 additions and 33 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,23 @@ This module allows you to add an alias for a certail option, that allows you to

![screenshot](assets/alias.png)

#### Currency converter
This module allows you to quickly convert between currencies.

![screenshot](assets/currency_converter.png)

#### Dictionary
This module allows you to quickly lookup definitions and synonyms for words.

![screenshot](assets/dictionary.png)

#### Bookmarks
This module allows you to search through your Firefox, Midori and Chromium/Google Chrome bookmarks.

![screenshot](assets/bookmarks.png)

#### Email
This module allows one to quickly start writing a new email.

![screenshot](assets/email.png)

Binary file added assets/bookmarks.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/currency_converter.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/dictionary.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/email.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marvin",
"version": "0.0.14",
"version": "0.0.15",
"license": "MIT",
"scripts": {
"dev": "electron-webpack dev",
Expand All @@ -26,6 +26,7 @@
"react": "^16.13.1",
"react-dom": "^16.13.1",
"source-map-support": "^0.5.16",
"sqlite3": "^5.0.0",
"style-loader": "^1.2.1",
"styled-components": "^5.1.1",
"typeface-roboto": "^0.0.75"
Expand Down
13 changes: 13 additions & 0 deletions src/common/local/english.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ const translation_english = {
aliases: 'Aliases',
option: 'Option',
prefix_text: 'Add name as prefix',

currency_converter: 'Currency converter',
currency_converter_description: 'This module allows you to quickly convert between currencies',

dictionary: 'Dictionary',
dictionary_description: 'This module allows you to quickly lookup definitions and synonyms for words',

bookmarks: 'Bookmarks',
bookmarks_description: 'This module allows you to search through your Firefox, Midori and Chromium/Google Chrome bookmarks',

email: 'Email',
email_description: 'This module allows one to quickly start writing a new email',
open_new_emial: 'Open new email',
};

export default translation_english;
13 changes: 13 additions & 0 deletions src/common/local/german.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ const translation_german = {
aliases: 'Aliase',
option: 'Option',
prefix_text: 'Name als Präfix hinzufügen',

currency_converter: 'Währungsumrechner',
currency_converter_description: 'Mit diesem Modul ist es möglich schnell zwischen Wahrungen umzurechnen',

dictionary: 'Wörterbuch',
dictionary_description: 'Mit diesem Modul können schnell Definitionen und Synonyme für Wörter nachgeschlagen werden',

bookmarks: 'Lesezeichen',
bookmarks_description: 'Mit diesem Modul ist es möglich Lesezeichen von Firefox, Midori und Chromium/Google Chrome zu durchsuchen',

email: 'E-Mail',
email_description: 'Mit diesem Modul ist es möglich schnell eine neue E-Mail zu beginnen',
open_new_emial: 'Neue E-Mail öffnen',
};

export default translation_german;
13 changes: 13 additions & 0 deletions src/common/local/italian.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ const translation_italian = {
aliases: 'Alias',
option: 'Opzione',
prefix_text: 'Aggiungi il nome come prefisso',

currency_converter: 'Convertitore di valuta',
currency_converter_description: 'Questo modulo consente di convertire rapidamente tra valute',

dictionary: 'Dizionario',
dictionary_description: 'Questo modulo può essere utilizzato per cercare rapidamente definizioni e sinonimi di parole',

bookmarks: 'Segnalibri',
bookmarks_description: 'Con questo modulo è possibile cercare tra i segnalibri di Firefox, Midori e Chromium/Google Chrome',

email: 'E-mail',
email_description: 'Con questo modulo è possibile avviare rapidamente una nuova e-mail',
open_new_emial: 'Apri una nuova e-mail',
};

export default translation_italian;
26 changes: 26 additions & 0 deletions src/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export let config_default = {
command: {
active: true,
prefix: '$',
quality: 1.0,
},
scripts: {
active: false,
Expand All @@ -90,6 +91,7 @@ export let config_default = {
deepl: {
active: false,
prefix: '',
quality: 1.0,
},
linux_windows: {
active: false,
Expand All @@ -98,6 +100,7 @@ export let config_default = {
google_translate: {
active: false,
prefix: '',
quality: 1.0,
},
duckduckgo: {
active: false,
Expand Down Expand Up @@ -130,13 +133,36 @@ export let config_default = {
{ prefix: 's?', url_pattern: 'https://stackoverflow.com/search?q=$' },
],
url_preview: false,
quality: 1.0,
},
alias: {
active: false,
prefix: '',
aliases: [ ],
prefix_text: true,
},
currency_converter: {
active: false,
prefix: '',
refresh_interval_min: 60,
quality: 1.0,
},
dictionary: {
active: false,
prefix: 'dict?',
debounce_time: 500,
quality: 1.0,
},
bookmarks: {
active: false,
prefix: '',
url_preview: false,
},
email: {
active: false,
prefix: '',
quality: 1.0,
},
},
};

Expand Down
8 changes: 8 additions & 0 deletions src/main/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import HistoryModule from "./modules/history";
import ColorModule from "./modules/color";
import WebSearchModule from "./modules/web-search";
import AliasModule from "./modules/alias";
import CurrencyConverterModule from "./modules/currency-converter";
import DictionaryModule from "./modules/dictionary";
import BookmarksModule from "./modules/bookmarks";
import EmailModule from "./modules/email";

const modules = {
settings: SettingsModule,
Expand All @@ -43,6 +47,10 @@ const modules = {
color: ColorModule,
web_search: WebSearchModule,
alias: AliasModule,
currency_converter: CurrencyConverterModule,
dictionary: DictionaryModule,
bookmarks: BookmarksModule,
email: EmailModule,
};

export function initModules() {
Expand Down
153 changes: 153 additions & 0 deletions src/main/modules/bookmarks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@

import { stringMatchQuality } from "../../common/util";
import { config } from "../config";
import { exec } from 'child_process';
import { getTranslation } from "../../common/local/locale";
import { Database, OPEN_READONLY } from 'sqlite3';
import { readFileSync, existsSync, readdirSync } from 'fs';
import { join } from 'path';
import { app } from 'electron';

function recursiveChromiumBookmarkSearch(bookmarks) {
if (bookmarks instanceof Object) {
if (bookmarks.type === 'url') {
return [{
title: bookmarks.name,
url: bookmarks.url,
}];
} else {
let ret = [];
Object.values(bookmarks).forEach((child) => {
ret = ret.concat(recursiveChromiumBookmarkSearch(child));
});
return ret;
}
} else {
return [];
}
}

async function getChromiumBookmarks() {
const files = [
join(app.getPath('home'), '.config/chromium/Default/Bookmarks'),
join(app.getPath('home'), '.config/google-chrome/Default/Bookmarks'),
].filter((file) => existsSync(file));
let ret = []
for (const file of files) {
const bookmarks = JSON.parse(readFileSync(file, { encoding: 'utf8' }));
ret = ret.concat(recursiveChromiumBookmarkSearch(bookmarks));
}
return ret;
}

let midori_bookmark_cache = null;

async function getMidoriBookmarks() {
if (midori_bookmark_cache) {
return midori_bookmark_cache;
} else {
const files = [
join(app.getPath('home'), '.config/midori/bookmarks.db'),
].filter((file) => existsSync(file));
return (await Promise.all(files.map((file) => {
return new Promise((res) => {
const db = new Database(file, OPEN_READONLY, (err) => {
if (err) {
res([]);
} else {
db.all(`
Select title, uri url
From bookmarks;
`, (err, rows) => {
if (err) {
return res([]);
} else {
midori_bookmark_cache = rows;
return res(midori_bookmark_cache);
}
});
}
db.close();
});
});
}))).flat();
}
}

let firefox_bookmark_cache = null;

async function getFirefoxBookmarks() {
if (firefox_bookmark_cache) {
return firefox_bookmark_cache;
} else {
const firefox_dir = join(app.getPath('home'), '.mozilla/firefox');
const files = readdirSync(firefox_dir)
.filter((file) => file.endsWith('.default'))
.map((file) => join(firefox_dir, file, 'places.sqlite'))
.filter((file) => existsSync(file));
return (await Promise.all(files.map((file) => {
return new Promise((res) => {
const db = new Database(file, OPEN_READONLY, (err) => {
if (err) {
res([]);
} else {
db.all(`
Select bm.title, pl.url
From moz_bookmarks bm
Join moz_places pl On (bm.fk = pl.id);
`, (err, rows) => {
if (err) {
return res([]);
} else {
firefox_bookmark_cache = rows;
return res(firefox_bookmark_cache);
}
});
}
db.close();
});
});
}))).flat();
}
}

const BookmarksModule = {
init: async () => {
// TODO: Find another solution
getFirefoxBookmarks(); // Cache for future use (Database will most likely be locked)
getMidoriBookmarks();
},
valid: (query) => {
return query.trim().length >= 1;
},
search: async (query) => {
const bookmarks = [
...(await getChromiumBookmarks()),
...(await getMidoriBookmarks()),
...(await getFirefoxBookmarks())
];
const bookmark_match = stringMatchQuality(query, getTranslation(config, 'bookmarks'));
return bookmarks.map((bookmark) => ({
type: 'icon_list_item',
material_icon: 'bookmark',
primary: bookmark.title,
secondary: getTranslation(config, 'open_in_browser') + ': ' + bookmark.url,
executable: true,
quality: Math.max(
stringMatchQuality(query, bookmark.title),
stringMatchQuality(query, bookmark.title),
bookmark_match
),
url: bookmark.url,
preview: config.modules.bookmarks.url_preview && {
type: 'iframe',
url: bookmark.url,
},
}));
},
execute: async (option) => {
exec(`xdg-open ${option.url}`);
},
}

export default BookmarksModule;
4 changes: 2 additions & 2 deletions src/main/modules/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CommandModule = {
primary: query.replace(config.modules.command.prefix, '').trim(),
secondary: getTranslation(config, 'execute') + ': `' + query.replace(config.modules.command.prefix, '').trim() + '`',
executable: true,
quality: 1.0,
quality: config.modules.command.quality,
command: query.replace(config.modules.command.prefix, '').trim(),
},
{
Expand All @@ -24,7 +24,7 @@ const CommandModule = {
primary: query.replace(config.modules.command.prefix, '').trim(),
secondary: getTranslation(config, 'execute_in_terminal') + ': `' + query.replace(config.modules.command.prefix, '').trim() + '`',
executable: true,
quality: 1.0,
quality: config.modules.command.quality,
command: `xterm -e '${query.replace(config.modules.command.prefix, '').trim().replace(/\'/g, "'\\''")}'`,
},
];
Expand Down
Loading

0 comments on commit 30e9e15

Please sign in to comment.