Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Plextora/osu-radio
Browse files Browse the repository at this point in the history
  • Loading branch information
Plextora committed Oct 1, 2024
2 parents 8c2db5a + 57c3670 commit 87759fe
Show file tree
Hide file tree
Showing 38 changed files with 665 additions and 387 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @CaptSiro
13 changes: 4 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 31 additions & 12 deletions src/@types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,10 @@ export type Resource = {
export type AudioSource = {
songID: ResourceID;
volume?: number;

//todo audio file waveform
} & Resource

export type ImageSource = {
songID: ResourceID;

//todo prominent colors of image
} & Resource

export type Song = {
Expand All @@ -66,6 +62,7 @@ export type Song = {
title: string,
artist: string,
creator: string,
// For the life of me I can't remember why is it 2D array
bpm: number[][],
duration: number,
beatmapSetID?: number,
Expand All @@ -78,25 +75,34 @@ export type Song = {
diffs: string[],
} & Resource

// Serialization is in JSON that's why properties are only single letter
export type SongIndex = {
id: string,
t: string, // title
a: string, // artist
c: string, // creator
m?: number, // mode
d: number, // duration
// title
t: string,
// artist
a: string,
// artist
c: string,
// mode
m?: number,
// duration
d: number,
tags?: string[],
// beatmap difficulty names
diffs: string[],
bpm: number
}



// System table definition
export type System = {
"songDir.mtime": string,
indexes: SongIndex[],
allTags: { [key: string]: string[] },
}

// Settings table definition
export type Settings = {
volume: number,
osuSongsDir: string,
Expand All @@ -107,7 +113,7 @@ export type Settings = {
}



// Key is a name of a table. This name is passed to Storage.getTable(name) function to retrieve whole table as an object
export type TableMap = {
'songs': { [key: ResourceID]: Song },
'audio': { [key: ResourceID]: AudioSource },
Expand All @@ -117,6 +123,14 @@ export type TableMap = {
'system': System,
}

// I guess this is definition of all binary blob files that can be access from the database code?
export type BlobMap = {
'times'
}



// Tables that work on ID -> Record relation
export type ResourceTables = "songs" | "audio" | "images";


Expand All @@ -125,12 +139,14 @@ type OmitPropsWithReturnType<O extends { [K: string]: (...args: any[]) => any },
[K in keyof O as ReturnType<O[K]> extends V ? never : K]: O[K]
}

// Types as functions for type
type OmitPropsWithoutReturnType<O extends { [K: string]: (...args: any[]) => any }, V> = {
[K in keyof O as ReturnType<O[K]> extends V ? K : never]: O[K]
}


export type APIFunction<F extends (...args: any) => any> = (evt: Electron.IpcMainInvokeEvent, ...args: Parameters<F>) => ReturnType<F> | Promise<ReturnType<F>>
export type APIFunction<F extends (...args: any) => any> = (evt: Electron.IpcMainInvokeEvent, ...args: Parameters<F>)
=> ReturnType<F> | Promise<ReturnType<F>>

export type PacketType = 'DATA' | 'ERROR'

Expand All @@ -148,6 +164,7 @@ export type APIListener<F extends (...args: any) => any> = (...args: Parameters<

export type Tag = {
name: string,
// Is excluded. Name should be changed to isExcluded in future version
isSpecial?: boolean
}

Expand All @@ -158,12 +175,14 @@ export type SongsQueryPayload = {
order: string,
}

// Context for backend to use proper database (all songs, current queue, playlist(s))
export type QueueView = SongViewProps & { playlists?: string[] };

export type QueueCreatePayload = {
view: QueueView,
searchQuery?: SearchQuerySuccess,
tags: Tag[],
// The format is: OsuSearchAbleProperties:(asc|desc) -> bpm:asc
order: string,
startSong: ResourceID,
}
Expand Down
2 changes: 2 additions & 0 deletions src/RequestAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ export type RequestAPI = {
"query::queue": (request: InfiniteScrollerRequest) => InfiniteScrollerResponse<Song>,

"save::localVolume": (volume: number, song: ResourceID) => void,

"dev::storeLocation": () => string,
}
3 changes: 2 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ async function createWindow() {
});

// HMR for renderer base on electron-vite cli.
// Load the remote URL for development or the local html file for production.
// Load the remote URL for hot reloading or the local html file for production.
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
await window.loadURL(process.env['ELECTRON_RENDERER_URL']);
} else {
await window.loadFile(join(__dirname, '../renderer/index.html'));
}

// Launch main app logic
await main(window)
.catch(error => {
if (error === null || error === undefined) {
Expand Down
23 changes: 0 additions & 23 deletions src/main/lib/Signal.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/main/lib/delay-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ export type DelayCancel = () => void;



/**
* Provided `fn` is wrapped and calling returned wrapped function will cause that all calls to that function will be
* delayed. If function is called while it is being delayed the delay timer will reset and start over
* @param fn
* @param ms
*/
export function delay<F extends (...args: any[]) => any>(fn: F, ms: number): [DelayedFunction<F>, DelayCancel] {
let timeout: NodeJS.Timeout | undefined = undefined;

Expand Down
6 changes: 3 additions & 3 deletions src/main/lib/fs-promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function access(path, mode: number | undefined = undefined): Promise<bool



export function getSubDirs(dirPath): Promise<string[]> {
export function getSubDirs(dirPath: string): Promise<string[]> {
return new Promise((resolve, reject) => {
fs.opendir(dirPath, { encoding: "utf8" }, async (err, dir) => {
if (err !== null) {
Expand All @@ -35,7 +35,7 @@ export function getSubDirs(dirPath): Promise<string[]> {



export function getFiles(dirPath, ext?): Promise<string[]> {
export function getFiles(dirPath: string, ext?: string): Promise<string[]> {
return new Promise((resolve, reject) => {
fs.opendir(dirPath, { encoding: "utf8" }, async (err, dir) => {
if (err !== null) {
Expand Down Expand Up @@ -63,7 +63,7 @@ export function getFiles(dirPath, ext?): Promise<string[]> {



export function stat(path): Promise<fs.Stats> {
export function stat(path: string): Promise<fs.Stats> {
return new Promise((resolve, reject) => {
fs.stat(path, (err, stats) => {
if (err !== null) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/lib/route-pass/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,32 @@ ipcMain.on("communication/main", (_evt, packet: Packet<any>) => {


export class Router {
/**
* Client - Server - Client
*
* Respond to `event` that was dispatched from client and send data back to client. The data that are send is the
* value returned from closure `fn`. Client may send data to server. The data is passed as arguments to closure `fn`
*
* Wrapper for `ipcMain.handle(...)`
*
* @param event
* @param fn
*/
static respond<E extends keyof RequestAPI>(event: E, fn: APIFunction<RequestAPI[E]>): void {
ipcMain.handle(event, fn as any);
}

/**
* Server - Client
*
* Send data to client. Provide client (`window`), `event`, and `data` that shall be delivered to client.
*
* @param window
* @param channel
* @param data
* @returns {Promise<any>} The data the Promise is resolved with should be return value of client-side listener
* function
*/
static dispatch<E extends keyof ListenAPI>(window: BrowserWindow, channel: E, ...data: Parameters<ListenAPI[E]>): Promise<any> {
const packet = cratePacket(channel, tokens.create(), data);

Expand Down
5 changes: 4 additions & 1 deletion src/main/lib/search-parser/@search-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type SearchQuery = SearchQueryError | SearchQuerySuccess

export type SearchConfig = {
tokenDelimiter: string,
// Relation symbol provides meaning between two tokens. Example: bpm=200 - relation symbol is `=`
relationSymbols: string[],
propertyMap: SearchPropertyMap
}
Expand All @@ -52,11 +53,13 @@ export type SearchPropertyValidation = {
},
} | {
isValid: true,
parsed: any
parsed: any // Represents value that is serialized in string. Example: value = String("727") -> parsed = Number(727)
}

// Function that shall validate user input
export type SearchPropertyValidator = (value: string, symbol: string) => SearchPropertyValidation

// All available tokens for searching. Example: "bpm": num()
export type SearchPropertyMap = {
[key: string]: SearchPropertyValidator
}
Loading

0 comments on commit 87759fe

Please sign in to comment.