Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Dec 2, 2019
2 parents 1a8fdc7 + 783f6ef commit 6d3f835
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 725 deletions.
2 changes: 1 addition & 1 deletion src/common/helpers/file-path-validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const validWindowsFilePaths = [
"C:\\temp",
"D:\\hello\\spaces are allowed\\and.this.is.also.valid",
"C:/Users/Oliver",
"\\\\Share\\My Folder",
];

const invalidWindowsFilePaths = [
"\\Program Files",
"Program Files",
"C:Program Files",
"C::\\Program Files",
Expand Down
2 changes: 1 addition & 1 deletion src/common/helpers/file-path-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { win32 } from "path";

export function isValidWindowsFilePath(filePath: string): boolean {
filePath = win32.normalize(filePath);
return /^[a-zA-Z]:\\[\\\S|*\S]?.*$/.test(filePath);
return /^(([a-zA-Z]:\\)|(\\{2}))[\\\S|*\S]?.*$/.test(filePath);
}

export function isValidMacOsFilePath(filePath: string): boolean {
Expand Down
42 changes: 42 additions & 0 deletions src/common/helpers/url-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { isValidUrl } from "./url-helpers";

describe(isValidUrl.name, () => {
it("should return true when passing in a valid URL", () => {
const validUrls = [
"www.google.com",
"https://google.com",
"http://google.com",
"http://de.wikipedia.org/wiki/Uniform_Resource_Locator",
"http://www.example.com/verzeichnis/unterverzeichnis/datei.html",
];

validUrls.forEach((validUrl) => {
const actual = isValidUrl(validUrl);
expect(actual).toBe(true);
});
});

it("should return false when passing in an invalid URL", () => {
const invalidUrls = [
"",
" ",
" ",
".",
"gugus",
"shit",
"[email protected]",
"mailto:[email protected]",
"gug.",
"gooogle com",
"www google.com",
"www google com",
"https:google.com",
"https:/google.com",
];

invalidUrls.forEach((invalidUrl) => {
const actual = isValidUrl(invalidUrl);
expect(actual).toBe(false);
});
});
});
46 changes: 29 additions & 17 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ function registerGlobalKeyboardShortcut(toggleAction: () => void, newHotKey: Glo
globalShortcut.register(`${newHotKey.modifier ? `${newHotKey.modifier}+` : ``}${newHotKey.key}`, toggleAction);
}

function calculateX(display: Electron.Display): number {
return Math.round(Number(display.bounds.x + (display.bounds.width / 2) - (config.appearanceOptions.windowWidth / 2)));
}

function calculateY(display: Electron.Display): number {
return Math.round(Number(display.bounds.y + (display.bounds.height / 2) - (getMaxWindowHeight(
config.appearanceOptions.maxSearchResultsPerPage,
config.appearanceOptions.searchResultHeight,
config.appearanceOptions.userInputHeight) / 2)));
}

function onBlur() {
if (config.generalOptions.hideMainWindowOnBlur) {
hideMainWindow();
}
}

function showMainWindow() {
if (windowExists(mainWindow)) {
if (mainWindow.isVisible()) {
Expand All @@ -152,30 +169,17 @@ function showMainWindow() {
? lastWindowPosition.y
: calculateY(display),
};
if (isMacOs(platform())) {
app.show();
}
mainWindow.setBounds(windowBounds);
mainWindow.show();
mainWindow.focus();
}
mainWindow.webContents.send(IpcChannels.mainWindowHasBeenShown);
}
}

function calculateX(display: Electron.Display): number {
return Math.round(Number(display.bounds.x + (display.bounds.width / 2) - (config.appearanceOptions.windowWidth / 2)));
}

function calculateY(display: Electron.Display): number {
return Math.round(Number(display.bounds.y + (display.bounds.height / 2) - (getMaxWindowHeight(
config.appearanceOptions.maxSearchResultsPerPage,
config.appearanceOptions.searchResultHeight,
config.appearanceOptions.userInputHeight) / 2)));
}

function onBlur() {
if (config.generalOptions.hideMainWindowOnBlur) {
hideMainWindow();
}
}

function hideMainWindow() {
if (windowExists(mainWindow)) {
mainWindow.webContents.send(IpcChannels.mainWindowHasBeenHidden);
Expand All @@ -184,6 +188,14 @@ function hideMainWindow() {
updateMainWindowSize(0, config.appearanceOptions);
if (windowExists(mainWindow)) {
mainWindow.hide();

if (isMacOs(platform())) {
if (!settingsWindow
|| (settingsWindow && settingsWindow.isDestroyed())
|| (settingsWindow && !settingsWindow.isDestroyed() && !settingsWindow.isVisible())) {
app.hide();
}
}
}
}, 25);
}
Expand Down
Loading

0 comments on commit 6d3f835

Please sign in to comment.