Skip to content

Commit

Permalink
Improve linting
Browse files Browse the repository at this point in the history
  • Loading branch information
martpie committed Dec 24, 2020
1 parent 621c38f commit 9aaef05
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/main/lib/modules-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Module from '../modules/module';

export const init = async (...modules: Module[]) => {
export const init = async (...modules: Module[]): Promise<void> => {
await Promise.all(
modules.map((module) =>
module.init().catch((err) => {
Expand Down
8 changes: 4 additions & 4 deletions src/main/modules/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class ConfigModule extends Module {
this.workArea = electron.screen.getPrimaryDisplay().workArea;
}

async load() {
const defaultConfig: Record<string, any> = this.getDefaultConfig();
async load(): Promise<void> {
const defaultConfig: Partial<Config> = this.getDefaultConfig();
const pathUserData = app.getPath('userData');

this.conf = new teeny(path.join(pathUserData, 'config.json'), defaultConfig);
Expand Down Expand Up @@ -78,15 +78,15 @@ class ConfigModule extends Module {
return this.conf.get() as Config; // Maybe possible to type TeenyConf with Generics?
}

get(key: keyof Config) {
get<T extends keyof Config>(key: T): Config[T] {
if (!this.conf) {
throw new Error('Config not loaded');
}

return this.conf.get(key);
}

reload() {
reload(): void {
if (!this.conf) {
throw new Error('Config not loaded');
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/modules/dock-menu-darwin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DockMenuDarwinModule extends ModuleWindow {
this.pauseToggle = [];
}

async load() {
async load(): Promise<void> {
this.songDetails = [
{
label: 'Not playing',
Expand Down Expand Up @@ -84,13 +84,13 @@ class DockMenuDarwinModule extends ModuleWindow {
this.setDockMenu(PlayerStatus.PAUSE);
}

setDockMenu(state: PlayerStatus) {
setDockMenu(state: PlayerStatus): void {
const playPauseItem = state === 'play' ? this.pauseToggle : this.playToggle;
const menuTemplate = [...this.songDetails, ...playPauseItem, ...this.menu];
app.dock.setMenu(Menu.buildFromTemplate(menuTemplate));
}

updateTrayMetadata(metadata: TrackModel) {
updateTrayMetadata(metadata: TrackModel): void {
this.songDetails = [
{
label: `${metadata.title}`,
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/global-shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { globalShortcut } from 'electron';
import ModuleWindow from './module-window';

class GlobalShortcutsModule extends ModuleWindow {
async load() {
async load(): Promise<void> {
globalShortcut.register('MediaPlayPause', () => {
this.window.webContents.send('playback:playpause');
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/modules/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class IpcModule extends ModuleWindow {
this.forceQuit = false;
}

async load() {
async load(): Promise<void> {
ipcMain.on('app:restart', () => {
app.relaunch({ args: ['process.argv.slice(1)', '--relaunch'] });
app.exit(0);
Expand All @@ -49,7 +49,7 @@ class IpcModule extends ModuleWindow {
});
}

close(e: Event) {
close(e: Event): void {
this.config.reload(); // HACKY
const minimizeToTray = this.config.get('minimizeToTray');

Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Menu, shell } from 'electron';
import ModuleWindow from './module-window';

class MenuModule extends ModuleWindow {
async load() {
async load(): Promise<void> {
const template: Electron.MenuItemConstructorOptions[] = [
{ role: 'appMenu' },
{ role: 'fileMenu' },
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/module-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ModuleWindow extends Module {
this.window = window;
}

getWindow() {
getWindow(): Electron.BrowserWindow {
return this.window;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/modules/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Module {
}

// To not be overriden
async init() {
async init(): Promise<void> {
if (this.loaded) throw new TypeError(`Module ${this.constructor.name} is already loaded`);

if (this.platforms.includes(os.platform())) {
Expand All @@ -28,7 +28,7 @@ class Module {
}

// Can (now) be an asynchronous method
async load() {
async load(): Promise<void> {
throw new TypeError(`Module ${this.constructor.name} should have a load() method`);
// Do whatever you want here :)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/mpris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MprisModule extends ModuleWindow {
this.platforms = ['linux'];
}

async load() {
async load(): Promise<void> {
this.player = mpris({
name: 'museeks',
identity: 'Museeks',
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/power-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as electron from 'electron';
import ModuleWindow from './module-window';

class PowerMonitorModule extends ModuleWindow {
async load() {
async load(): Promise<void> {
const { powerMonitor } = electron;
const { window } = this;

Expand Down
8 changes: 4 additions & 4 deletions src/main/modules/sleep-blocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ class SleepBlocker extends ModuleWindow {
this.platforms = ['win32', 'darwin', 'linux'];
}

onStartPlayback = (_event: Event) => {
onStartPlayback = (_event: Event): void => {
if (this.enabled && !powerSaveBlocker.isStarted(this.sleepBlockerId)) {
// or 'prevent-display-sleep'
this.sleepBlockerId = powerSaveBlocker.start('prevent-app-suspension');
}
};

onStopPlayback = (_event: Event) => {
onStopPlayback = (_event: Event): void => {
if (powerSaveBlocker.isStarted(this.sleepBlockerId)) {
powerSaveBlocker.stop(this.sleepBlockerId);
}
};

toggleSleepBlocker = (_event: Event, value: boolean) => {
toggleSleepBlocker = (_event: Event, value: boolean): void => {
this.enabled = value;
};

async load() {
async load(): Promise<void> {
ipcMain.on('settings:toggleSleepBlocker', this.toggleSleepBlocker);
ipcMain.on('playback:play', this.onStartPlayback);
ipcMain.on('playback:pause', this.onStopPlayback);
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/thumbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ThumbarModule extends ModuleWindow {
this.platforms = ['win32'];
}

async load() {
async load(): Promise<void> {
const { window } = this;

const icons = {
Expand Down
12 changes: 6 additions & 6 deletions src/main/modules/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TrayModule extends ModuleWindow {
else if (os.platform() === 'darwin') this.trayIcon = trayIcons['tray-darwin-dark'];
}

async load() {
async load(): Promise<void> {
// Fix for gnome-shell and high-dpi
if (os.platform() === 'linux') {
ps.lookup(
Expand Down Expand Up @@ -165,7 +165,7 @@ class TrayModule extends ModuleWindow {
});
}

create() {
create(): void {
this.tray = new Tray(this.trayIcon);
this.tray.setToolTip('Museeks');

Expand All @@ -184,13 +184,13 @@ class TrayModule extends ModuleWindow {
this.setContextMenu(this.status);
}

destroy() {
destroy(): void {
if (this.tray) {
this.tray.destroy();
}
}

setContextMenu(state: PlayerStatus) {
setContextMenu(state: PlayerStatus): void {
const playPauseItem = state === 'play' ? this.pauseToggle : this.playToggle;
const menuTemplate = [...this.songDetails, ...playPauseItem, ...this.menu];

Expand All @@ -199,13 +199,13 @@ class TrayModule extends ModuleWindow {
}
}

refreshTrayIcon() {
refreshTrayIcon(): void {
if (this.tray) {
this.tray.setImage(this.trayIcon);
}
}

updateTrayMetadata(track: TrackModel) {
updateTrayMetadata(track: TrackModel): void {
this.songDetails = [
{
label: `${track.title}`,
Expand Down

0 comments on commit 9aaef05

Please sign in to comment.