Skip to content

Commit

Permalink
chore: add more strict types in electron directory (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
cino authored Jun 25, 2022
1 parent 8a450a5 commit af814d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
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

0 comments on commit af814d7

Please sign in to comment.