From 1bfa3a62e5c418b929de0fa182906ae0ee2f3be6 Mon Sep 17 00:00:00 2001 From: Izaak Kuipers Date: Wed, 21 Feb 2024 21:13:05 +0100 Subject: [PATCH] Automated codebase refactor --- App.svelte | 11 ++--- Components/Bar.svelte | 5 +-- Components/Controls/Forward.svelte | 4 +- Components/Controls/Rewind.svelte | 4 +- Components/Controls/Seek.svelte | 8 +--- ts/accelerators.ts | 8 ++-- ts/altmenu.ts | 7 +--- ts/altmenu/Audio.ts | 18 ++++----- ts/altmenu/File.ts | 18 ++++----- ts/app.ts | 12 +++--- ts/handler.ts | 4 +- ts/runtime.ts | 65 ++++++++++++++++-------------- ts/types.ts | 2 +- 13 files changed, 76 insertions(+), 90 deletions(-) diff --git a/App.svelte b/App.svelte index dc391aa..165b561 100644 --- a/App.svelte +++ b/App.svelte @@ -1,11 +1,10 @@ - + {#if $State && $path} {#if !$isVideo}
diff --git a/Components/Bar.svelte b/Components/Bar.svelte index 121357f..17521a9 100644 --- a/Components/Bar.svelte +++ b/Components/Bar.svelte @@ -7,8 +7,5 @@
-
+
diff --git a/Components/Controls/Forward.svelte b/Components/Controls/Forward.svelte index 2b24fda..26f6e02 100644 --- a/Components/Controls/Forward.svelte +++ b/Components/Controls/Forward.svelte @@ -8,6 +8,4 @@ } - + diff --git a/Components/Controls/Rewind.svelte b/Components/Controls/Rewind.svelte index b05b18b..f9ff0ac 100644 --- a/Components/Controls/Rewind.svelte +++ b/Components/Controls/Rewind.svelte @@ -8,6 +8,4 @@ } - + diff --git a/Components/Controls/Seek.svelte b/Components/Controls/Seek.svelte index b3a6323..4a588bb 100644 --- a/Components/Controls/Seek.svelte +++ b/Components/Controls/Seek.svelte @@ -13,10 +13,6 @@
- - + +
diff --git a/ts/accelerators.ts b/ts/accelerators.ts index ef03b12..eb4926a 100644 --- a/ts/accelerators.ts +++ b/ts/accelerators.ts @@ -9,14 +9,14 @@ export const MediaPlayerAccelerators: (runtime: Runtime) => AppKeyCombinations = shift: true, action() { runtime.openFileLocation(); - } + }, }, { key: "o", alt: true, action() { runtime.openFile(); - } + }, }, - ] -} \ No newline at end of file + ]; +}; diff --git a/ts/altmenu.ts b/ts/altmenu.ts index cfbb230..418d904 100644 --- a/ts/altmenu.ts +++ b/ts/altmenu.ts @@ -4,8 +4,5 @@ import { FileMenu } from "./altmenu/File"; import { Runtime } from "./runtime"; export function MediaPlayerAltMenu(runtime: Runtime): ContextMenuItem[] { - return [ - FileMenu(runtime), - AudioMenu(runtime) - ] -} \ No newline at end of file + return [FileMenu(runtime), AudioMenu(runtime)]; +} diff --git a/ts/altmenu/Audio.ts b/ts/altmenu/Audio.ts index 5f6759f..6f3cd07 100644 --- a/ts/altmenu/Audio.ts +++ b/ts/altmenu/Audio.ts @@ -10,24 +10,24 @@ export function AudioMenu(runtime: Runtime): ContextMenuItem { caption: "Play", icon: "play_arrow", action() { - runtime.Play() - } + runtime.Play(); + }, }, { caption: "Pause", icon: "pause", action() { - runtime.Pause() - } + runtime.Pause(); + }, }, SEP_ITEM, { caption: "Stop", icon: "stop", action() { - runtime.Stop() - } + runtime.Stop(); + }, }, - ] - } -} \ No newline at end of file + ], + }; +} diff --git a/ts/altmenu/File.ts b/ts/altmenu/File.ts index 791b46c..255abf5 100644 --- a/ts/altmenu/File.ts +++ b/ts/altmenu/File.ts @@ -11,9 +11,9 @@ export function FileMenu(runtime: Runtime): ContextMenuItem { caption: "Open...", icon: "file_open", action() { - runtime.openFile() + runtime.openFile(); }, - accelerator: "Alt+O" + accelerator: "Alt+O", }, { caption: "Open file location", @@ -22,17 +22,17 @@ export function FileMenu(runtime: Runtime): ContextMenuItem { runtime.openFileLocation(); }, disabled: () => !runtime.path.get(), - accelerator: "Alt+Shift+O" + accelerator: "Alt+Shift+O", }, SEP_ITEM, { caption: "Exit", action: () => { - runtime.closeApp() + runtime.closeApp(); }, image: ShutdownIcon, - accelerator: "Alt+Q" - } - ] - } -} \ No newline at end of file + accelerator: "Alt+Q", + }, + ], + }; +} diff --git a/ts/app.ts b/ts/app.ts index cb07589..0ffa493 100644 --- a/ts/app.ts +++ b/ts/app.ts @@ -9,7 +9,7 @@ export const MediaPlayer: App = { description: "Play audio files", author: "Izaak Kuipers", version: "3.0.0", - icon: MediaPlayerIcon + icon: MediaPlayerIcon, }, runtime: Runtime, content: AppSvelte, @@ -23,16 +23,16 @@ export const MediaPlayer: App = { maximized: false, headless: false, fullscreen: false, - resizable: true + resizable: true, }, controls: { minimize: true, maximize: true, - close: true + close: true, }, acceleratorDescriptions: { "alt+o": "Open an audio file", - "alt+shift+o": "Open file location of audio file" + "alt+shift+o": "Open file location of audio file", }, - glass: true -} \ No newline at end of file + glass: true, +}; diff --git a/ts/handler.ts b/ts/handler.ts index e61e1e8..e7cc8f7 100644 --- a/ts/handler.ts +++ b/ts/handler.ts @@ -11,5 +11,5 @@ export const MediaPlayerHandler: FileHandler = { image: MediaPlayerIcon, handler(file) { openFileWithApp("MediaPlayer", file); - } -} \ No newline at end of file + }, +}; diff --git a/ts/runtime.ts b/ts/runtime.ts index a34de36..d0988b9 100644 --- a/ts/runtime.ts +++ b/ts/runtime.ts @@ -27,8 +27,8 @@ export class Runtime extends AppRuntime { constructor(app: App, mutator: AppMutator, process: Process) { super(app, mutator, process); - this.loadAltMenu(...MediaPlayerAltMenu(this)) - this.process.accelerator.store.push(...MediaPlayerAccelerators(this)) + this.loadAltMenu(...MediaPlayerAltMenu(this)); + this.process.accelerator.store.push(...MediaPlayerAccelerators(this)); this.openedFile.subscribe(async (v) => { if (!v) return; @@ -36,7 +36,7 @@ export class Runtime extends AppRuntime { }); if (process.args.length && typeof process.args[0] === "string") { - this.handleOpenFile(process.args[0]) + this.handleOpenFile(process.args[0]); } } @@ -56,16 +56,15 @@ export class Runtime extends AppRuntime { this.Loaded.set(true); - return; } const ext = parseExtension(file.path); - this.isVideo.set(MimeTypeIcons[VideoMimeIcon].includes(ext)) + this.isVideo.set(MimeTypeIcons[VideoMimeIcon].includes(ext)); this.url.set(URL.createObjectURL(file.data)); - this.setWindowTitle(pathToFriendlyName(v), false) - this.setWindowIcon(getMimeIcon(v)) + this.setWindowTitle(pathToFriendlyName(v), false); + this.setWindowIcon(getMimeIcon(v)); this.Reset(); @@ -74,7 +73,6 @@ export class Runtime extends AppRuntime { setTimeout(() => { this.player.play(); this.Loaded.set(true); - }); } @@ -113,24 +111,25 @@ export class Runtime extends AppRuntime { } public Stop() { - if (!this.player) return + if (!this.player) return; this.player.pause(); this.player.currentTime = 0; } public updateState() { - if (!this.player) return { - paused: true, - current: 0, - duration: 0, - }; + if (!this.player) + return { + paused: true, + current: 0, + duration: 0, + }; const state = { paused: this.player.paused, current: this.player.currentTime, - duration: this.player.duration - } + duration: this.player.duration, + }; this.State.set(state); } @@ -144,12 +143,12 @@ export class Runtime extends AppRuntime { public openFileLocation() { const path = this.path.get(); - if (!path) return + if (!path) return; const split = path.split("/"); const filename = split[split.length - 1]; - spawnApp("FileManager", 0, [path.replace(filename, "") || ".", path]) + spawnApp("FileManager", 0, [path.replace(filename, "") || ".", path]); } public openFile() { @@ -158,22 +157,26 @@ export class Runtime extends AppRuntime { title: "Select an audio or video file to open", icon: MediaPlayerIcon, startDir: getParentDirectory(this.path.get() || "./"), - extensions: [...MimeTypeIcons[AudioMimeIcon], ...MimeTypeIcons[VideoMimeIcon]] + extensions: [...MimeTypeIcons[AudioMimeIcon], ...MimeTypeIcons[VideoMimeIcon]], }, ]); } public async LoadProgress(v: string = this.path.get()) { - return await FileProgress({ - caption: "Loading this amazing file...", - subtitle: `Home/${pathToFriendlyPath(v)}`, - icon: MediaPlayerIcon, - max: 1, - done: 0, - type: "quantity", - waiting: false, - working: true, - errors: 0 - }, this.pid, false) + return await FileProgress( + { + caption: "Loading this amazing file...", + subtitle: `Home/${pathToFriendlyPath(v)}`, + icon: MediaPlayerIcon, + max: 1, + done: 0, + type: "quantity", + waiting: false, + working: true, + errors: 0, + }, + this.pid, + false + ); } -} \ No newline at end of file +} diff --git a/ts/types.ts b/ts/types.ts index e452c15..df7f4f3 100644 --- a/ts/types.ts +++ b/ts/types.ts @@ -2,4 +2,4 @@ export interface PlayerState { paused: boolean; current: number; duration: number; -} \ No newline at end of file +}