Skip to content

Commit

Permalink
Merge pull request #65 from rolandbernard/devel
Browse files Browse the repository at this point in the history
Version 0.4.4 changes
  • Loading branch information
rolandbernard committed Aug 26, 2022
2 parents 9734829 + f34f885 commit f238111
Show file tree
Hide file tree
Showing 17 changed files with 458 additions and 487 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.4.3",
"version": "0.4.4",
"description": "This is a keystroke launcher for Linux",
"repository": "https://github.com/rolandbernard/marvin/",
"author": "Roland Bernard",
Expand Down
2 changes: 1 addition & 1 deletion src/common/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function multiplyColor([a, b, c, d]: Color, [e, f, g, h]: Color): Color {

function parseValue(string: string, max = 1.0): number {
if (string.endsWith('%')) {
const value = parseFloat(string.substr(0, string.length - 1));
const value = parseFloat(string.substring(0, string.length - 1));
return value / 100;
} else {
const value = parseFloat(string);
Expand Down
8 changes: 4 additions & 4 deletions src/common/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function parseHtml(text: string): HtmlElement {
let attr_match: RegExpExecArray | null;
while (attr_match = ATTR_REGEX.exec(match[2])) {
const value = attr_match[3] ?? '""';
attributes[attr_match[1]] = value.substr(1, value.length - 2);
attributes[attr_match[1]] = value.substring(1, value.length - 1);
}
const value = {
tag: tag,
Expand Down Expand Up @@ -95,7 +95,7 @@ function matchesSelectors(element: HtmlElement, query: string[]): boolean {
return false;
} else if (match = selector.match(/\[\s*([-\w]+)\s*(([~|^$*]?=)\s*("[^"]*"|'[^']*'))?\s*\]/)) {
if (match[2]) {
const value = match[4].substr(1, match[4].length - 2);
const value = match[4].substring(1, match[4].length - 1);
if (match[3] === '=') {
return element.attributes[match[1]] !== value;
} else if (match[3] === '~=') {
Expand All @@ -114,9 +114,9 @@ function matchesSelectors(element: HtmlElement, query: string[]): boolean {
return !(match[1] in element.attributes);
}
} else if (selector[0] === '#') {
return element.attributes['id'] !== selector.substr(1);
return element.attributes['id'] !== selector.substring(1);
} else if (selector[0] === '.') {
return !element.attributes['class']?.split(/\s+/)?.includes(selector.substr(1));
return !element.attributes['class']?.split(/\s+/)?.includes(selector.substring(1));
} else {
return selector !== element.tag;
}
Expand Down
6 changes: 4 additions & 2 deletions src/common/local/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export type Translation = typeof TRANSLATIONS[Language];
export type Translatable = keyof Translation;

export function getTranslation(text: Translatable, config?: GlobalConfig): string {
return TRANSLATIONS[config?.general.language ?? 'en'][text] ?? TRANSLATIONS['en'][text] ?? text;
const lang_preference: Language = config?.general.language ?? Language.English;
return TRANSLATIONS[lang_preference][text] ?? TRANSLATIONS['en'][text] ?? text;
}

export function hasTranslation(text?: string, config?: GlobalConfig): text is Translatable {
return (text && TRANSLATIONS[config?.general.language ?? 'en'][text as Translatable]) ? true : false;
const lang_preference: Language = config?.general.language ?? Language.English;
return (text && TRANSLATIONS[lang_preference][text as Translatable]) ? true : false;
}

export function getAllTranslations(text: keyof Translation): string[] {
Expand Down
10 changes: 5 additions & 5 deletions src/common/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Query {
}

escapeRegex(text: string, map?: (c: string) => string, join = '') {
return this.normalizeString(text.substr(0, MAX_MATCH_LENGTH))
return this.normalizeString(text.substring(0, MAX_MATCH_LENGTH))
.split('').map((ch) => {
// Escape special regex characters
if ([
Expand Down Expand Up @@ -54,7 +54,7 @@ export class Query {
}

bestMatch(text: string): string | undefined {
text = text.substr(0, MAX_MATCH_LENGTH);
text = text.substring(0, MAX_MATCH_LENGTH);
let best: string | undefined;
for (let match of text.matchAll(this.regex)) {
if (!best || match[1].length < best.length) {
Expand All @@ -65,7 +65,7 @@ export class Query {
}

matchText(full_text: string): number {
const text = full_text.substr(0, MAX_MATCH_LENGTH);
const text = full_text.substring(0, MAX_MATCH_LENGTH);
if (text.length > 0 && this.text.length > 0) {
const best_match = this.bestMatch(text);
if (best_match) {
Expand Down Expand Up @@ -97,9 +97,9 @@ export class Query {
if (match && match.length !== 0) {
const groups = this.regex.exec(match)!;
return [
text.substr(0, text.indexOf(match)),
text.substring(0, text.indexOf(match)),
...groups.slice(2),
text.substr(text.indexOf(match) + match.length),
text.substring(text.indexOf(match) + match.length),
];
} else {
return [ text ];
Expand Down
6 changes: 3 additions & 3 deletions src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export function isInEnum<Type extends string>(type: { [k: string]: Type }, value

export function copyCase(text: string, template: string): string {
if (text.length < template.length) {
return copyCase(text, template.substr(0, text.length));
return copyCase(text, template.substring(0, text.length));
} else if (text.toLowerCase().startsWith(template.toLowerCase())) {
const change = [...text.substr(0, template.length)];
const change = [...text.substring(0, template.length)];
return change.map((ch, i) => {
const temp = template.charAt(i);
if (temp.toUpperCase() !== temp.toLowerCase()) {
Expand All @@ -75,7 +75,7 @@ export function copyCase(text: string, template: string): string {
} else {
return ch;
}
}).join('') + text.substr(template.length);
}).join('') + text.substring(template.length);
} else {
return text;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/adapters/applications/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ function parseDesktopFile(data: string) {
entry = 'desktop';
application[entry] = {};
} else if (line.startsWith('[Desktop Action')) {
entry = line.substr(16).trim().replace(']', '');
entry = line.substring(16).trim().replace(']', '');
application[entry] = {};
}
} else if (entry) {
let option;
if (line.includes('=')) {
const split = line.indexOf('=');
option = [ line.substr(0, split).trim(), line.substr(split + 1).trim() ];
option = [ line.substring(0, split).trim(), line.substring(split + 1).trim() ];
} else {
option = [ line.trim() ];
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getPlatform, isDevelopment, Platform } from 'common/platform';
import { runMatch } from 'common/util';

import { loadConfig } from 'main/config';
import { initModules, deinitModules, moduleForId } from 'main/modules';
import { initModules, deinitModules } from 'main/modules';
import { initGlobalIpc, GlobalIpcCommand } from 'main/global-ipc';
import { invokeModule } from 'main/execution/workers';

Expand Down
4 changes: 2 additions & 2 deletions src/main/modules/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class CalculatorModule implements Module<SimpleResult> {
}
return results.filter((val, index) =>
!['', 'nil', 'null', 'undefined'].includes(val.primary.replace('=', '').trim())
&& val.primary.substr(2).replaceAll(' ', '').trim() !== query.text.replaceAll(' ', '').trim()
&& val.primary.substring(2).replaceAll(' ', '').trim() !== query.text.replaceAll(' ', '').trim()
&& results.findIndex((v) => v.primary.replaceAll(' ', '').trim() === val.primary.replaceAll(' ', '').trim()) === index
);
} else {
Expand All @@ -74,7 +74,7 @@ export class CalculatorModule implements Module<SimpleResult> {
}

async execute(result: SimpleResult) {
clipboard.writeText(result.primary.substr(2));
clipboard.writeText(result.primary.substring(2));
}
}

2 changes: 1 addition & 1 deletion src/main/modules/currency-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class CurrencyConverterModule implements Module<SimpleResult> {
}

async execute(result: SimpleResult) {
clipboard.writeText(result.primary.substr(2));
clipboard.writeText(result.primary.substring(2));
}
}

7 changes: 3 additions & 4 deletions src/main/modules/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class EmailConfig extends ModuleConfig {
}
}

const MAIL_PATTERN = /^mailto:.*$|^[^@]+@(\w|-)+(\.(\w|-)+)*\.[a-z]{2,}$/iu;

@module(MODULE_ID)
export class EmailModule implements Module<EmailResult> {
readonly configs = EmailConfig;
Expand All @@ -34,10 +36,7 @@ export class EmailModule implements Module<EmailResult> {
}

isValidEmail(str: string): boolean {
const pattern = new RegExp('^(mailto:)?' +
'[^@]+@' +
'(([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}$', 'i');
return pattern.test(str);
return MAIL_PATTERN.test(str);
}

completeEmail(str: string): string {
Expand Down
1 change: 1 addition & 0 deletions src/main/modules/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class MainModule implements Module<SimpleResult> {
}

showWindow() {
this.window?.webContents.setZoomFactor(config.general.zoom);
this.window?.webContents.send(IpcChannels.SHOW_WINDOW, config, config.getDescription());
this.window?.show();
if (config.general.recenter_on_show) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class SettingsModule implements Module<SimpleResult> {
}

showWindow() {
this.window?.webContents.send(IpcChannels.SHOW_WINDOW, config, config.getDescription());
this.update();
this.window?.show();
this.window?.focus();
}
Expand Down
14 changes: 5 additions & 9 deletions src/main/modules/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface UrlResult extends SimpleResult {

class UrlConfig extends ModuleConfig {
@configKind('quality')
quality = 1;
quality = 0.75;

@configKind('boolean')
url_preview = false;
Expand All @@ -28,6 +28,8 @@ class UrlConfig extends ModuleConfig {
}
}

const URL_PATTERN = /^https?:\/\/.*$|^(\w|-)+(\.(\w|-)+)*\.[a-z]{2,}(\/.*)?$/iu;

@module(MODULE_ID)
export class UrlModule implements Module<UrlResult> {
readonly configs = UrlConfig;
Expand All @@ -37,13 +39,7 @@ export class UrlModule implements Module<UrlResult> {
}

isValidUrl(str: string): boolean {
const pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
return pattern.test(str);
return URL_PATTERN.test(str);
}

completeUrl(str: string): string {
Expand All @@ -62,7 +58,7 @@ export class UrlModule implements Module<UrlResult> {
icon: { material: 'language' },
primary: url,
secondary: getTranslation('open_in_browser', config),
quality: this.config.quality,
quality: query.text === url ? 1 : this.config.quality,
url: url,
preview: this.config.url_preview ? {
kind: 'iframe-preview',
Expand Down
10 changes: 5 additions & 5 deletions src/main/renderer-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ function transformResultArray(results: Result[]): RunnerResult[] {
const reduced_option: RunnerResult = { ...opt, id: id };
if (reduced_option.kind === 'text-result') {
if (reduced_option.text.length > MAX_TRANSFER_LEN) {
reduced_option.text = reduced_option.text.substr(0, MAX_TRANSFER_LEN) + '...';
reduced_option.text = reduced_option.text.substring(0, MAX_TRANSFER_LEN) + '...';
}
} else if (reduced_option.kind === 'simple-result') {
if (reduced_option.primary?.length > MAX_TRANSFER_LEN) {
reduced_option.primary = reduced_option.primary.substr(0, MAX_TRANSFER_LEN) + '...';
if ((reduced_option.primary?.length ?? 0) > MAX_TRANSFER_LEN) {
reduced_option.primary = reduced_option.primary.substring(0, MAX_TRANSFER_LEN) + '...';
}
if ((reduced_option.secondary?.length ?? 0) > MAX_TRANSFER_LEN) {
reduced_option.secondary = reduced_option.secondary?.substr(0, MAX_TRANSFER_LEN) + '...';
reduced_option.secondary = reduced_option.secondary?.substring(0, MAX_TRANSFER_LEN) + '...';
}
}
if ((reduced_option.autocomplete?.length ?? 0) > MAX_TRANSFER_LEN) {
reduced_option.autocomplete = reduced_option.autocomplete?.substr(0, MAX_TRANSFER_LEN);
reduced_option.autocomplete = reduced_option.autocomplete?.substring(0, MAX_TRANSFER_LEN);
}
original_option[id] = opt;
return reduced_option;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"lib": [
"dom",
"dom.iterable",
"esnext"
"es2021"
],
"allowJs": true,
"sourceMap": true,
Expand Down
Loading

0 comments on commit f238111

Please sign in to comment.