diff options
author | Ricardo Cino <ricardo@cino.io> | 2022-06-26 01:21:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-25 23:21:07 +0000 |
commit | af814d7cfff7e1ca3c27f8a25d498d3439debabb (patch) | |
tree | e56ec1ef4efdb2c07ac37884b0a629ab7756632b | |
parent | Update 'CHANGELOG.md' for '6.0.0-beta.2' release [skip ci] (diff) | |
download | ferdium-app-af814d7cfff7e1ca3c27f8a25d498d3439debabb.tar.gz ferdium-app-af814d7cfff7e1ca3c27f8a25d498d3439debabb.tar.zst ferdium-app-af814d7cfff7e1ca3c27f8a25d498d3439debabb.zip |
chore: add more strict types in electron directory (#367)
-rw-r--r-- | src/electron/Settings.ts | 22 | ||||
-rw-r--r-- | src/electron/deepLinking.ts | 7 | ||||
-rw-r--r-- | src/electron/macOSPermissions.ts | 6 | ||||
-rw-r--r-- | src/electron/windowUtils.ts | 2 |
4 files changed, 22 insertions, 15 deletions
diff --git a/src/electron/Settings.ts b/src/electron/Settings.ts index de010b9a3..d09ac7fb6 100644 --- a/src/electron/Settings.ts +++ b/src/electron/Settings.ts | |||
@@ -5,11 +5,11 @@ import { userDataPath } from '../environment-remote'; | |||
5 | const debug = require('../preload-safe-debug')('Ferdium:Settings'); | 5 | const debug = require('../preload-safe-debug')('Ferdium:Settings'); |
6 | 6 | ||
7 | export default class Settings { | 7 | export default class Settings { |
8 | type = ''; | 8 | type: string = ''; |
9 | 9 | ||
10 | defaultState: {}; | 10 | defaultState: object; |
11 | 11 | ||
12 | @observable store = {}; | 12 | @observable store: object = {}; |
13 | 13 | ||
14 | constructor(type: string, defaultState = {}) { | 14 | constructor(type: string, defaultState = {}) { |
15 | this.type = type; | 15 | this.type = type; |
@@ -23,41 +23,41 @@ export default class Settings { | |||
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
26 | set(settings) { | 26 | set(settings: object): void { |
27 | this.store = this._merge(settings); | 27 | this.store = this._merge(settings); |
28 | 28 | ||
29 | this._writeFile(); | 29 | this._writeFile(); |
30 | } | 30 | } |
31 | 31 | ||
32 | get all() { | 32 | get all(): object { |
33 | return this.store; | 33 | return this.store; |
34 | } | 34 | } |
35 | 35 | ||
36 | get allSerialized() { | 36 | get allSerialized(): object { |
37 | return toJS(this.store); | 37 | return toJS(this.store); |
38 | } | 38 | } |
39 | 39 | ||
40 | get(key: string | number) { | 40 | get(key: string | number): any { |
41 | return this.store[key]; | 41 | return this.store[key]; |
42 | } | 42 | } |
43 | 43 | ||
44 | _merge(settings) { | 44 | _merge(settings: object): object { |
45 | return Object.assign(this.defaultState, this.store, settings); | 45 | return Object.assign(this.defaultState, this.store, settings); |
46 | } | 46 | } |
47 | 47 | ||
48 | _hydrate() { | 48 | _hydrate(): void { |
49 | this.store = this._merge(readJsonSync(this.settingsFile)); | 49 | this.store = this._merge(readJsonSync(this.settingsFile)); |
50 | debug('Hydrate store', this.type, this.allSerialized); | 50 | debug('Hydrate store', this.type, this.allSerialized); |
51 | } | 51 | } |
52 | 52 | ||
53 | _writeFile() { | 53 | _writeFile(): void { |
54 | outputJsonSync(this.settingsFile, this.store, { | 54 | outputJsonSync(this.settingsFile, this.store, { |
55 | spaces: 2, | 55 | spaces: 2, |
56 | }); | 56 | }); |
57 | debug('Write settings file', this.type, this.allSerialized); | 57 | debug('Write settings file', this.type, this.allSerialized); |
58 | } | 58 | } |
59 | 59 | ||
60 | get settingsFile() { | 60 | get settingsFile(): string { |
61 | return userDataPath( | 61 | return userDataPath( |
62 | 'config', | 62 | 'config', |
63 | `${this.type === 'app' ? 'settings' : this.type}.json`, | 63 | `${this.type === 'app' ? 'settings' : this.type}.json`, |
diff --git a/src/electron/deepLinking.ts b/src/electron/deepLinking.ts index 532bdd6fb..36de1b143 100644 --- a/src/electron/deepLinking.ts +++ b/src/electron/deepLinking.ts | |||
@@ -1,4 +1,9 @@ | |||
1 | export default function handleDeepLink(window, rawUrl) { | 1 | import { BrowserWindow } from 'electron'; |
2 | |||
3 | export default function handleDeepLink( | ||
4 | window: BrowserWindow, | ||
5 | rawUrl: string, | ||
6 | ): void { | ||
2 | const url = rawUrl.replace('ferdium://', ''); | 7 | const url = rawUrl.replace('ferdium://', ''); |
3 | 8 | ||
4 | if (!url) return; | 9 | if (!url) return; |
diff --git a/src/electron/macOSPermissions.ts b/src/electron/macOSPermissions.ts index 2415534e5..c9f22aecb 100644 --- a/src/electron/macOSPermissions.ts +++ b/src/electron/macOSPermissions.ts | |||
@@ -35,7 +35,7 @@ function hasScreenCapturePermissionAlreadyBeenGranted(): boolean { | |||
35 | return screenCaptureStatus === 'granted'; | 35 | return screenCaptureStatus === 'granted'; |
36 | } | 36 | } |
37 | 37 | ||
38 | function createStatusFile() { | 38 | function createStatusFile(): void { |
39 | try { | 39 | try { |
40 | writeFileSync(filePath, ''); | 40 | writeFileSync(filePath, ''); |
41 | } catch (error) { | 41 | } catch (error) { |
@@ -48,7 +48,9 @@ function createStatusFile() { | |||
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | export const askFormacOSPermissions = async (mainWindow: BrowserWindow) => { | 51 | export const askFormacOSPermissions = async ( |
52 | mainWindow: BrowserWindow, | ||
53 | ): Promise<void> => { | ||
52 | debug('Checking camera & microphone permissions'); | 54 | debug('Checking camera & microphone permissions'); |
53 | systemPreferences.askForMediaAccess('camera'); | 55 | systemPreferences.askForMediaAccess('camera'); |
54 | systemPreferences.askForMediaAccess('microphone'); | 56 | systemPreferences.askForMediaAccess('microphone'); |
diff --git a/src/electron/windowUtils.ts b/src/electron/windowUtils.ts index 1db1ff246..9c9fd1b77 100644 --- a/src/electron/windowUtils.ts +++ b/src/electron/windowUtils.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { screen } from 'electron'; | 1 | import { screen } from 'electron'; |
2 | 2 | ||
3 | export function isPositionValid(position: { x: number; y: number }) { | 3 | export function isPositionValid(position: { x: number; y: number }): boolean { |
4 | const displays = screen.getAllDisplays(); | 4 | const displays = screen.getAllDisplays(); |
5 | const { x, y } = position; | 5 | const { x, y } = position; |
6 | return displays.some( | 6 | return displays.some( |