configure watchdog to accept a list of dirs to watch

- fix PlayingFrom component not working with album
- fix types issues on PlayingFrom component
This commit is contained in:
geoffrey45 2022-07-15 15:40:11 +03:00
parent 97b61970c5
commit 3882317cb6
11 changed files with 73 additions and 41 deletions

View File

@ -60,7 +60,6 @@ class RemoveDuplicates:
for t in self.tracklist
if t.uniq_hash not in uniq_hashes
]
pprint(uniq_hashes[:5])
tracks = UseBisection(self.tracklist, "uniq_hash", uniq_hashes)()
return tracks

View File

@ -3,6 +3,7 @@ This library contains the classes and functions related to the watchdog file wat
"""
import os
import time
from typing import List
from app import instances
from app.helpers import create_hash
@ -19,29 +20,39 @@ class OnMyWatch:
Contains the methods for initializing and starting watchdog.
"""
directory = os.path.expanduser("~")
home_dir = os.path.expanduser("~")
dirs = [home_dir]
observers: List[Observer] = []
def __init__(self):
self.observer = Observer()
def run(self):
event_handler = Handler()
self.observer.schedule(event_handler, self.directory, recursive=True)
for dir in self.dirs:
print("something")
self.observer.schedule(event_handler, os.path.realpath(dir), recursive=True)
self.observers.append(self.observer)
try:
self.observer.start()
print("something something")
except OSError:
log.error("Could not start watchdog.")
return
try:
while True:
time.sleep(5)
except:
self.observer.stop()
time.sleep(1)
except KeyboardInterrupt:
for o in self.observers:
o.unschedule_all()
o.stop()
print("Observer Stopped")
self.observer.join()
for o in self.observers:
o.join()
def add_track(filepath: str) -> None:
@ -82,6 +93,7 @@ class Handler(PatternMatchingEventHandler):
"""
Fired when a supported file is created.
"""
print("💠 created file 💠")
self.files_to_process.append(event.src_path)
def on_deleted(self, event):

View File

@ -1,7 +1,6 @@
"""
Contains all the models for objects generation and typing.
"""
import random
from dataclasses import dataclass
from dataclasses import field
from typing import List

View File

@ -86,7 +86,12 @@ function updateQueue(track: Track) {
queue.play(index);
break;
case "AlbumView":
queue.playFromAlbum(track.album, track.albumartist, props.tracks);
queue.playFromAlbum(
track.album,
track.albumartist,
track.albumhash,
props.tracks
);
queue.play(index);
break;
case "PlaylistView":
@ -148,7 +153,7 @@ function getTracks() {
display: none;
}
.context-on {
.contexton {
background-color: $gray4;
color: $white !important;
}

View File

@ -2,7 +2,7 @@
<div id="playing-from" class="rounded" @click="goTo">
<div class="h">
<div class="icon image" :class="from.icon"></div>
Playing from
Playing from
</div>
<div class="name">
<div id="to">
@ -13,7 +13,12 @@
</template>
<script setup lang="ts">
import { fromFolder, fromAlbum, fromPlaylist, fromSearch } from "../../../interfaces";
import {
fromFolder,
fromAlbum,
fromPlaylist,
fromSearch,
} from "../../../interfaces";
import { FromOptions } from "../../../composables/enums";
import { useRouter } from "vue-router";
import { computed } from "@vue/reactivity";
@ -42,7 +47,7 @@ const from = computed((): from => {
case FromOptions.album:
return {
icon: "album",
text: props.from.name,
text: `${props.from.name} - ${props.from.albumartist}`,
};
case FromOptions.playlist:
return {
@ -52,37 +57,36 @@ const from = computed((): from => {
case FromOptions.search:
return {
icon: "search",
text: `Search results for: "${props.from.query}"`
}
text: `Search results for: "${props.from.query}"`,
};
}
});
const router = useRouter();
function goToAlbum() {
function goToAlbum(from: fromAlbum) {
router.push({
name: "AlbumView",
params: {
album: props.from.name,
artist: props.from.albumartist,
hash: from.hash,
},
});
}
function goToFolder() {
function goToFolder(from: fromFolder) {
router.push({
name: "FolderView",
params: {
path: props.from.path,
path: from.path,
},
});
}
function goToPlaylist() {
function goToPlaylist(from: fromPlaylist) {
router.push({
name: "PlaylistView",
params: {
pid: props.from.playlistid,
pid: from.playlistid,
},
});
}
@ -90,13 +94,13 @@ function goToPlaylist() {
function goTo() {
switch (props.from.type) {
case FromOptions.folder:
goToFolder();
goToFolder(props.from);
break;
case FromOptions.album:
goToAlbum();
goToAlbum(props.from);
break;
case FromOptions.playlist:
goToPlaylist();
goToPlaylist(props.from);
break;
}
}
@ -108,7 +112,7 @@ function goTo() {
padding: 0.75rem;
cursor: pointer;
position: relative;
transition: all .2s ease;
transition: all 0.2s ease;
background-color: $black;
&:hover {
@ -121,7 +125,7 @@ function goTo() {
}
.h {
font-size: .9rem;
font-size: 0.9rem;
margin-bottom: $small;
display: flex;
align-items: center;

View File

@ -3,7 +3,7 @@
class="songlist-item rounded"
:class="[
{ current: isCurrent },
{ 'context-on': context_on },
{ contexton: context_on },
{
highlighted: isHighlighted,
},
@ -134,7 +134,6 @@ function emitUpdate(track: Track) {
text-align: left;
gap: $small;
user-select: none;
text-transform: capitalize;
@include tablet-landscape {
grid-template-columns: 1.5rem 1.5fr 1fr 1fr 2.5rem;

View File

@ -6,7 +6,7 @@
{
currentInQueue: props.isCurrent,
},
{ 'context-on': context_on },
{ contexton: context_on },
]"
@contextmenu="showContextMenu"
>
@ -87,7 +87,7 @@ const playThis = (track: Track) => {
background-color: $gray3;
}
.context-on {
.contexton {
background-color: $gray4;
color: $white !important;
}

View File

@ -29,9 +29,14 @@ export default function play(
break;
case playSources.album:
store = store as typeof album;
const a = store();
const a_store = store();
useQueue.playFromAlbum(a.info.title, a.info.artist, a.tracks);
useQueue.playFromAlbum(
a_store.info.title,
a_store.info.artist,
a_store.info.hash,
a_store.tracks
);
useQueue.play();
break;
case playSources.playlist:

View File

@ -74,23 +74,24 @@ export interface Notif {
}
export interface fromFolder {
type: FromOptions;
type: FromOptions.folder;
path: string;
name: string;
}
export interface fromAlbum {
type: FromOptions;
type: FromOptions.album;
name: string;
hash: string;
albumartist: string;
}
export interface fromPlaylist {
type: FromOptions;
type: FromOptions.playlist;
name: string;
playlistid: string;
}
export interface fromSearch {
type: FromOptions;
type: FromOptions.search;
query: string;
}

View File

@ -7,12 +7,12 @@ import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import useCustomTransitions from "./transitions";
import CustomTransitions from "./transitions";
const app = createApp(App);
app.use(createPinia());
app.use(router);
app.use(MotionPlugin, useCustomTransitions);
app.use(MotionPlugin, CustomTransitions);
app.mount("#app");

View File

@ -46,6 +46,8 @@ const defaultTrack = <Track>{
image: "",
};
type From = fromFolder | fromAlbum | fromPlaylist | fromSearch;
export default defineStore("Queue", {
state: () => ({
progressElem: HTMLElement,
@ -59,7 +61,7 @@ export default defineStore("Queue", {
prev: 0,
currentid: "",
playing: false,
from: <fromFolder>{} || <fromAlbum>{} || <fromPlaylist>{},
from: <From>{},
tracks: <Track[]>[defaultTrack],
}),
actions: {
@ -178,10 +180,16 @@ export default defineStore("Queue", {
};
this.setNewQueue(tracks);
},
playFromAlbum(aname: string, albumartist: string, tracks: Track[]) {
playFromAlbum(
aname: string,
albumartist: string,
albumhash: string,
tracks: Track[]
) {
this.from = <fromAlbum>{
type: FromOptions.album,
name: aname,
hash: albumhash,
albumartist: albumartist,
};