Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add more strict types in electron directory #367

Merged
merged 2 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/electron/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { userDataPath } from '../environment-remote';
const debug = require('../preload-safe-debug')('Ferdium:Settings');

export default class Settings {
type = '';
type: string = '';

defaultState: {};
defaultState: object;

@observable store = {};
@observable store: object = {};

constructor(type: string, defaultState = {}) {
this.type = type;
Expand All @@ -23,41 +23,41 @@ export default class Settings {
}
}

set(settings) {
set(settings: object): void {
this.store = this._merge(settings);

this._writeFile();
}

get all() {
get all(): object {
return this.store;
}

get allSerialized() {
get allSerialized(): object {
return toJS(this.store);
}

get(key: string | number) {
get(key: string | number): any {
return this.store[key];
}

_merge(settings) {
_merge(settings: object): object {
return Object.assign(this.defaultState, this.store, settings);
}

_hydrate() {
_hydrate(): void {
this.store = this._merge(readJsonSync(this.settingsFile));
debug('Hydrate store', this.type, this.allSerialized);
}

_writeFile() {
_writeFile(): void {
outputJsonSync(this.settingsFile, this.store, {
spaces: 2,
});
debug('Write settings file', this.type, this.allSerialized);
}

get settingsFile() {
get settingsFile(): string {
return userDataPath(
'config',
`${this.type === 'app' ? 'settings' : this.type}.json`,
Expand Down
7 changes: 6 additions & 1 deletion src/electron/deepLinking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export default function handleDeepLink(window, rawUrl) {
import { BrowserWindow } from 'electron';

export default function handleDeepLink(
window: BrowserWindow,
rawUrl: string,
): void {
const url = rawUrl.replace('ferdium://', '');

if (!url) return;
Expand Down
6 changes: 4 additions & 2 deletions src/electron/macOSPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function hasScreenCapturePermissionAlreadyBeenGranted(): boolean {
return screenCaptureStatus === 'granted';
}

function createStatusFile() {
function createStatusFile(): void {
try {
writeFileSync(filePath, '');
} catch (error) {
Expand All @@ -48,7 +48,9 @@ function createStatusFile() {
}
}

export const askFormacOSPermissions = async (mainWindow: BrowserWindow) => {
export const askFormacOSPermissions = async (
mainWindow: BrowserWindow,
): Promise<void> => {
debug('Checking camera & microphone permissions');
systemPreferences.askForMediaAccess('camera');
systemPreferences.askForMediaAccess('microphone');
Expand Down
2 changes: 1 addition & 1 deletion src/electron/windowUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { screen } from 'electron';

export function isPositionValid(position: { x: number; y: number }) {
export function isPositionValid(position: { x: number; y: number }): boolean {
const displays = screen.getAllDisplays();
const { x, y } = position;
return displays.some(
Expand Down