Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Most of the Electron 25 migration work is done #73

Merged
merged 8 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

yarn format
yarn hook-commit
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

yarn chk
yarn hook-push
4 changes: 0 additions & 4 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
{
"files": ".prettierrc",
"options": { "parser": "json" }
},
{
"files": "*.json",
"options": { "parser": "json" }
}
]
}
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@
"${workspaceFolder}/node_modules/jest/bin/jest.js",
"--runInBand",
"--config",
"${workspaceFolder}/packages/audiofileindex/jestconfig.json"
"${workspaceFolder}/modules/audiofileindex/jestconfig.json"
],
"cwd": "${workspaceFolder}/packages/audiofileindex",
"cwd": "${workspaceFolder}/modules/audiofileindex",
"console": "integratedTerminal",
"internalConsoleOptions": "openOnSessionStart"
}
Expand Down
440 changes: 220 additions & 220 deletions .yarn/releases/yarn-3.6.0.cjs → .yarn/releases/yarn-3.6.3.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'

yarnPath: .yarn/releases/yarn-3.6.0.cjs
yarnPath: .yarn/releases/yarn-3.6.3.cjs
8 changes: 6 additions & 2 deletions about.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand All @@ -17,20 +17,24 @@
flex-direction: column;
font-family: Arial, Helvetica, sans-serif;
}

#title {
font-weight: bold;
font-size: x-large;
}

#version {
font-weight: lighter;
font-size: smaller;
}

#source-code {
font-weight: bolder;
font-size: large;
}
</style>
</head>

<body>
<div id="title">Electron Music Player</div>
<br />
Expand All @@ -39,7 +43,7 @@
</div>
<br />
<!-- This line gets read & written by the config/set-version.js script -->
<div id="version">Version 0.8.8</div>
<div id="version">Version 0.8.9</div>
<br />
<div id="source-code">
<a href="https://github.com/kevinfrei/EMP">Source code</a>
Expand Down
2 changes: 1 addition & 1 deletion config/jest.jsdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = {
moduleDirectories: [
'node_modules',
'<rootDir>/../shared',
'<rootDir>/../packages',
'<rootDir>/../modules',
],

// An array of file extensions your modules use
Expand Down
6 changes: 3 additions & 3 deletions config/set-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ async function readJSONFile(filename) {

async function writeJSONFile(filename, json, options) {
const text = JSON.stringify(json);
const formatted = prettier.format(text, { ...options, parser: 'json' });
const formatted = await prettier.format(text, { ...options, parser: 'json' });
await fsp.writeFile(filename, formatted, 'utf-8');
}

async function writeHTMLFile(filename, html, options) {
const text = html.join('\n');
const formatted = prettier.format(text, { ...options, parser: 'html' });
const formatted = await prettier.format(text, { ...options, parser: 'html' });
await fsp.writeFile(filename, formatted, 'utf-8');
}

Expand All @@ -114,7 +114,7 @@ async function main() {
const curDir = process.cwd();
const pkgPath = path.join(curDir, 'package.json');
const pkg = await readJSONFile(pkgPath);
const aboutPath = path.join(curDir, 'public', 'about.html');
const aboutPath = path.join(curDir, 'about.html');
const about = await getAboutVersion(aboutPath);
const aboutVer = about.version;
const packageVer = pkg.version;
Expand Down
4 changes: 2 additions & 2 deletions electron/Communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ export function CommsSetup(): void {
}

// This is for one-way comms to the UI process
export function SendToUI(name: IpcId, data: unknown) {
const obj: { [key: string]: unknown } = {};
export function SendToUI<T>(name: IpcId, data: T) {
const obj: { [key: string]: T } = {};
obj[name] = data;
log(`Sending ${name} with data:`);
log(data);
Expand Down
7 changes: 6 additions & 1 deletion electron/Startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { isString } from '@freik/typechk';
import { app } from 'electron';
import { UpdateLocations } from './AudioDatabase';
import { CommsSetup } from './Communication';
import { RegisterListeners, RegisterProtocols } from './protocols';
import {
RegisterListeners,
RegisterPrivileges,
RegisterProtocols,
} from './protocols';

const { wrn } = MakeLog('EMP:main:Startup');

Expand All @@ -13,6 +17,7 @@ const { wrn } = MakeLog('EMP:main:Startup');
*/
export function InitBeforeAnythingElse(): void {
CommsSetup();
RegisterPrivileges();
app.whenReady().then(RegisterProtocols).catch(wrn);
RegisterListeners();
}
Expand Down
13 changes: 7 additions & 6 deletions electron/Transcoding.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
IpcId,
TranscodeInfo,
TranscodeSourceType,
TranscodeState,
} from '@freik/emp-shared';
import { MakeLog } from '@freik/logger';
import type { Attributes } from '@freik/media-core';
import { Encode, Metadata as MD } from '@freik/media-utils';
Expand All @@ -16,12 +22,6 @@ import { promises as fsp } from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { rimraf } from 'rimraf';
import {
IpcId,
TranscodeInfo,
TranscodeSourceType,
TranscodeState,
} from '@freik/emp-shared';
import { GetAudioDB } from './AudioDatabase';
import { SendToUI } from './Communication';
import { LoadPlaylist } from './playlists';
Expand Down Expand Up @@ -91,6 +91,7 @@ export async function toMp4Async(
hasFieldType(res.error, 'toString', isFunction)
) {
// MediaInfo failed: no continue, sorry
// eslint-disable-next-line @typescript-eslint/no-base-to-string
const resStr = asString(res.error.toString(), 'Unknown error');
return tr(
XcodeResCode.mediaInfoFailure,
Expand Down
27 changes: 16 additions & 11 deletions electron/cover-art.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ import {
isSetOfString,
} from '@freik/typechk';
import albumArt from 'album-art';
import { ProtocolRequest } from 'electron';
import Jimp from 'jimp';
import { promises as fs } from 'node:fs';
import https from 'node:https';
import path from 'node:path';
import { GetAudioDB } from './AudioDatabase';
import {
BufferResponse,
GetDefaultAlbumPicBuffer,
GetDefaultAlbumPicResponse,
GetDefaultAlbumPicUri,
GetDefaultArtistPicBuffer,
// GetDefaultAlbumPicUri,
GetDefaultArtistPicResponse,
} from './protocols';

const { log, wrn } = MakeLog('EMP:main:cover-art');
log.enabled = true;

async function shouldDownloadAlbumArtwork(): Promise<boolean> {
return (await Persistence.getItemAsync('downloadAlbumArtwork')) === 'true';
Expand Down Expand Up @@ -271,27 +271,32 @@ async function TryToGetPic(id: MediaKey): Promise<PicData | undefined> {
}
}

export async function PictureHandler(
req: ProtocolRequest,
id: MediaKey,
): Promise<BufferResponse> {
export async function PictureHandler(req: Request): Promise<Response> {
// Check to see if there's a song in the album that has a cover image
const { pathname } = new URL(req.url);
let id = pathname.substring(1);
try {
log(`Got a request for ${id}`);
if (id.lastIndexOf('#') !== -1) {
id = id.substring(0, id.lastIndexOf('#'));
}
const d = await TryToGetPic(id);
if (isDefined(d)) {
return d;
log(`Sending data for ${id}`);
return new Response(
d.data.buffer.slice(
d.data.byteOffset,
d.data.byteOffset + d.data.byteLength,
),
);
}
} catch (error) {
wrn(`Error while trying to get picture for ${id}`);
wrn(error);
}
return isArtistKey(id)
? GetDefaultArtistPicBuffer()
: GetDefaultAlbumPicBuffer();
? GetDefaultArtistPicResponse()
: GetDefaultAlbumPicResponse();
}

async function SavePicForAlbum(
Expand Down
16 changes: 8 additions & 8 deletions electron/menu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Persistence } from '@freik/electron-main';
import { CurrentView, IpcId, Keys } from '@freik/emp-shared';
import { isFunction, isString } from '@freik/typechk';
import {
BrowserWindow,
Expand All @@ -9,7 +10,6 @@ import {
shell,
} from 'electron';
import { KeyboardEvent } from 'electron/main';
import { CurrentView, IpcId, Keys } from '@freik/emp-shared';
import { ShowAbout } from './About.js';
import { SendToUI } from './Communication.js';
import { ToggleMiniPlayer } from './window.js';
Expand All @@ -27,12 +27,12 @@ const isMac = process.platform === 'darwin';
// eslint-disable-next-line
const ___: MenuItemConstructorOptions = { type: 'separator' };

function getClick(handler?: ClickHandler | unknown): ClickHandler | undefined {
function getClick<T>(handler?: ClickHandler | T): ClickHandler | undefined {
if (!handler) {
return;
}
if (isFunction(handler)) {
return handler as ClickHandler;
return handler;
}
return () => SendToUI(IpcId.MenuAction, handler);
}
Expand All @@ -42,10 +42,10 @@ function getId(lbl: string): string {
}

// TODO: Add an action to be taken, with a quick x-plat shortcut key
function xaction(
function xaction<T>(
label: string,
accelerator: string,
handler?: ClickHandler | unknown,
handler?: ClickHandler | T,
): MenuItemConstructorOptions {
return {
label,
Expand All @@ -56,10 +56,10 @@ function xaction(
}

// Typescript Method Overloading is kinda weird...
function action(
function action<T>(
label: string,
accOrHdlr: string | ClickHandler | unknown | void,
handler?: ClickHandler | unknown,
accOrHdlr: string | ClickHandler | T,
handler?: ClickHandler | T,
): MenuItemConstructorOptions {
if (isString(accOrHdlr)) {
return {
Expand Down
Loading