From dafd89222f0117f157e987ece1068059aa6f2b08 Mon Sep 17 00:00:00 2001 From: Ricardo Cino Date: Sat, 25 Jun 2022 17:39:43 +0200 Subject: [PATCH 1/2] chore: add more strict types in electron directory --- src/electron/Settings.ts | 22 +++++++++++----------- src/electron/deepLinking.ts | 7 ++++++- src/electron/macOSPermissions.ts | 7 ++++--- src/electron/windowUtils.ts | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/electron/Settings.ts b/src/electron/Settings.ts index de010b9a3a..d09ac7fb62 100644 --- a/src/electron/Settings.ts +++ b/src/electron/Settings.ts @@ -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; @@ -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`, diff --git a/src/electron/deepLinking.ts b/src/electron/deepLinking.ts index 532bdd6fb0..36de1b1436 100644 --- a/src/electron/deepLinking.ts +++ b/src/electron/deepLinking.ts @@ -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; diff --git a/src/electron/macOSPermissions.ts b/src/electron/macOSPermissions.ts index 2415534e56..c074d7d6a3 100644 --- a/src/electron/macOSPermissions.ts +++ b/src/electron/macOSPermissions.ts @@ -2,7 +2,6 @@ import { systemPreferences, BrowserWindow, dialog } from 'electron'; import { pathExistsSync, mkdirSync, writeFileSync } from 'fs-extra'; import macosVersion from 'macos-version'; import { dirname } from 'path'; -// @ts-ignore import { askForScreenCaptureAccess } from 'node-mac-permissions'; import { userDataPath } from '../environment-remote'; @@ -35,7 +34,7 @@ function hasScreenCapturePermissionAlreadyBeenGranted(): boolean { return screenCaptureStatus === 'granted'; } -function createStatusFile() { +function createStatusFile(): void { try { writeFileSync(filePath, ''); } catch (error) { @@ -48,7 +47,9 @@ function createStatusFile() { } } -export const askFormacOSPermissions = async (mainWindow: BrowserWindow) => { +export const askFormacOSPermissions = async ( + mainWindow: BrowserWindow, +): Promise => { debug('Checking camera & microphone permissions'); systemPreferences.askForMediaAccess('camera'); systemPreferences.askForMediaAccess('microphone'); diff --git a/src/electron/windowUtils.ts b/src/electron/windowUtils.ts index 1db1ff2464..9c9fd1b77c 100644 --- a/src/electron/windowUtils.ts +++ b/src/electron/windowUtils.ts @@ -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( From b0c97d4e82394fb623d9c052f8c24aa202f68367 Mon Sep 17 00:00:00 2001 From: Ricardo Cino Date: Sat, 25 Jun 2022 17:48:30 +0200 Subject: [PATCH 2/2] chore: put the ts-ignore back :( --- src/electron/macOSPermissions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/electron/macOSPermissions.ts b/src/electron/macOSPermissions.ts index c074d7d6a3..c9f22aecbd 100644 --- a/src/electron/macOSPermissions.ts +++ b/src/electron/macOSPermissions.ts @@ -2,6 +2,7 @@ import { systemPreferences, BrowserWindow, dialog } from 'electron'; import { pathExistsSync, mkdirSync, writeFileSync } from 'fs-extra'; import macosVersion from 'macos-version'; import { dirname } from 'path'; +// @ts-ignore import { askForScreenCaptureAccess } from 'node-mac-permissions'; import { userDataPath } from '../environment-remote';