Skip to content

Commit

Permalink
Automated codebase refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
IzKuipers committed Feb 21, 2024
1 parent 6d4ec74 commit 1bfa3a6
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 90 deletions.
11 changes: 4 additions & 7 deletions App.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<script lang="ts">
import { MediaPlayerIcon } from "$ts/images/apps";
import { onMount } from "svelte";
import Bar from "./Components/Bar.svelte";
import Controls from "./Components/Controls.svelte";
import "./css/main.css";
import { Runtime } from "./ts/runtime";
import Controls from "./Components/Controls.svelte";
import Bar from "./Components/Bar.svelte";
import File from "./Components/File.svelte";
import { MediaPlayerIcon } from "$ts/images/apps";
export let runtime: Runtime;
Expand All @@ -18,9 +17,7 @@
const { State, path, isVideo } = runtime;
</script>

<video bind:this={audio} class:show={$isVideo}>
<track kind="captions" /></video
>
<video bind:this={audio} class:show={$isVideo}> <track kind="captions" /></video>
{#if $State && $path}
{#if !$isVideo}
<div class="audio-visual">
Expand Down
5 changes: 1 addition & 4 deletions Components/Bar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
</script>

<div class="bar" class:bounce={!$Loaded}>
<div
class="inner"
style="--w: {(100 / $State.duration) * $State.current}%;"
/>
<div class="inner" style="--w: {(100 / $State.duration) * $State.current}%;" />
</div>
4 changes: 1 addition & 3 deletions Components/Controls/Forward.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
}
</script>

<button class="material-icons-round forward" on:click={forward}>
fast_forward
</button>
<button class="material-icons-round forward" on:click={forward}> fast_forward </button>
4 changes: 1 addition & 3 deletions Components/Controls/Rewind.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
}
</script>

<button class="material-icons-round reverse" on:click={rewind}>
fast_rewind
</button>
<button class="material-icons-round reverse" on:click={rewind}> fast_rewind </button>
8 changes: 2 additions & 6 deletions Components/Controls/Seek.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
</script>

<div class="group seek">
<button class="material-icons-round reverse" on:click={rewind}>
fast_rewind
</button>
<button class="material-icons-round forward" on:click={forward}>
fast_forward
</button>
<button class="material-icons-round reverse" on:click={rewind}> fast_rewind </button>
<button class="material-icons-round forward" on:click={forward}> fast_forward </button>
</div>
8 changes: 4 additions & 4 deletions ts/accelerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ export const MediaPlayerAccelerators: (runtime: Runtime) => AppKeyCombinations =
shift: true,
action() {
runtime.openFileLocation();
}
},
},
{
key: "o",
alt: true,
action() {
runtime.openFile();
}
},
},
]
}
];
};
7 changes: 2 additions & 5 deletions ts/altmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ import { FileMenu } from "./altmenu/File";
import { Runtime } from "./runtime";

export function MediaPlayerAltMenu(runtime: Runtime): ContextMenuItem[] {
return [
FileMenu(runtime),
AudioMenu(runtime)
]
}
return [FileMenu(runtime), AudioMenu(runtime)];
}
18 changes: 9 additions & 9 deletions ts/altmenu/Audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
},
]
}
}
],
};
}
18 changes: 9 additions & 9 deletions ts/altmenu/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
]
}
}
accelerator: "Alt+Q",
},
],
};
}
12 changes: 6 additions & 6 deletions ts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
glass: true,
};
4 changes: 2 additions & 2 deletions ts/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export const MediaPlayerHandler: FileHandler = {
image: MediaPlayerIcon,
handler(file) {
openFileWithApp("MediaPlayer", file);
}
}
},
};
65 changes: 34 additions & 31 deletions ts/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ 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;

await this.readFile(v);
});

if (process.args.length && typeof process.args[0] === "string") {
this.handleOpenFile(process.args[0])
this.handleOpenFile(process.args[0]);
}
}

Expand All @@ -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();

Expand All @@ -74,7 +73,6 @@ export class Runtime extends AppRuntime {
setTimeout(() => {
this.player.play();
this.Loaded.set(true);

});
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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() {
Expand All @@ -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
);
}
}
}
2 changes: 1 addition & 1 deletion ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export interface PlayerState {
paused: boolean;
current: number;
duration: number;
}
}

0 comments on commit 1bfa3a6

Please sign in to comment.