Skip to content

Commit

Permalink
feat: run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyBrick committed Nov 30, 2023
1 parent 44c4231 commit a3104fd
Show file tree
Hide file tree
Showing 116 changed files with 2,933 additions and 1,259 deletions.
4 changes: 2 additions & 2 deletions src/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export interface DefaultConfig {
startingPage: string;
overrideUserAgent: boolean;
themes: string[];
},
plugins: Record<string, unknown>,
};
plugins: Record<string, unknown>;
}

const defaultConfig: DefaultConfig = {
Expand Down
17 changes: 14 additions & 3 deletions src/config/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export function getPlugins() {
}

export function isEnabled(plugin: string) {
const pluginConfig = deepmerge(allPlugins[plugin].config ?? { enabled: false }, (store.get('plugins') as Record<string, PluginConfig>)[plugin] ?? {});
const pluginConfig = deepmerge(
allPlugins[plugin].config ?? { enabled: false },
(store.get('plugins') as Record<string, PluginConfig>)[plugin] ?? {},
);
return pluginConfig !== undefined && pluginConfig.enabled;
}

Expand All @@ -22,7 +25,11 @@ export function isEnabled(plugin: string) {
* @param options Options to set
* @param exclude Options to exclude from the options object
*/
export function setOptions<T>(plugin: string, options: T, exclude: string[] = ['enabled']) {
export function setOptions<T>(
plugin: string,
options: T,
exclude: string[] = ['enabled'],
) {
const plugins = store.get('plugins') as Record<string, T>;
// HACK: This is a workaround for preventing changed options from being overwritten
exclude.forEach((key) => {
Expand All @@ -39,7 +46,11 @@ export function setOptions<T>(plugin: string, options: T, exclude: string[] = ['
});
}

export function setMenuOptions<T>(plugin: string, options: T, exclude: string[] = ['enabled']) {
export function setMenuOptions<T>(
plugin: string,
options: T,
exclude: string[] = ['enabled'],
) {
setOptions(plugin, options, exclude);
if (store.get('options.restartOnConfigChanges')) {
restart();
Expand Down
36 changes: 24 additions & 12 deletions src/config/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ import { DefaultPresetList, type Preset } from '@/plugins/downloader/types';

const migrations = {
'>=3.0.0'(store: Conf<Record<string, unknown>>) {
const discordConfig = store.get('plugins.discord') as Record<string, unknown>;
const discordConfig = store.get('plugins.discord') as Record<
string,
unknown
>;
if (discordConfig) {
const oldActivityTimoutEnabled = store.get('plugins.discord.activityTimoutEnabled') as boolean | undefined;
const oldActivityTimoutTime = store.get('plugins.discord.activityTimoutTime') as number | undefined;
const oldActivityTimoutEnabled = store.get(
'plugins.discord.activityTimoutEnabled',
) as boolean | undefined;
const oldActivityTimoutTime = store.get(
'plugins.discord.activityTimoutTime',
) as number | undefined;
if (oldActivityTimoutEnabled !== undefined) {
discordConfig.activityTimeoutEnabled = oldActivityTimoutEnabled;
store.set('plugins.discord', discordConfig);
Expand Down Expand Up @@ -93,18 +100,23 @@ const migrations = {
}
},
'>=1.12.0'(store: Conf<Record<string, unknown>>) {
const options = store.get('plugins.shortcuts') as Record<
string,
| {
action: string;
shortcut: unknown;
}[]
| Record<string, unknown>
> | undefined;
const options = store.get('plugins.shortcuts') as
| Record<
string,
| {
action: string;
shortcut: unknown;
}[]
| Record<string, unknown>
>
| undefined;
if (options) {
let updated = false;
for (const optionType of ['global', 'local']) {
if (Object.hasOwn(options, optionType) && Array.isArray(options[optionType])) {
if (
Object.hasOwn(options, optionType) &&
Array.isArray(options[optionType])
) {
const optionsArray = options[optionType] as {
action: string;
shortcut: unknown;
Expand Down
50 changes: 31 additions & 19 deletions src/custom-electron-prompt.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,45 @@ declare module 'custom-electron-prompt' {
export interface CounterPromptOptions extends BasePromptOptions<'counter'> {
counterOptions: CounterOptions;
}
export interface MultiInputPromptOptions extends BasePromptOptions<'multiInput'> {
export interface MultiInputPromptOptions
extends BasePromptOptions<'multiInput'> {
multiInputOptions: InputOptions[];
}
export interface KeybindPromptOptions extends BasePromptOptions<'keybind'> {
keybindOptions: KeybindOptions[];
}

export type PromptOptions<T extends string> = (
T extends 'input' ? InputPromptOptions :
T extends 'select' ? SelectPromptOptions :
T extends 'counter' ? CounterPromptOptions :
T extends 'keybind' ? KeybindPromptOptions :
T extends 'multiInput' ? MultiInputPromptOptions :
never
);
export type PromptOptions<T extends string> = T extends 'input'
? InputPromptOptions
: T extends 'select'
? SelectPromptOptions
: T extends 'counter'
? CounterPromptOptions
: T extends 'keybind'
? KeybindPromptOptions
: T extends 'multiInput'
? MultiInputPromptOptions
: never;

type PromptResult<T extends string> = T extends 'input' ? string :
T extends 'select' ? string :
T extends 'counter' ? number :
T extends 'keybind' ? {
value: string;
accelerator: string
}[] :
T extends 'multiInput' ? string[] :
never;
type PromptResult<T extends string> = T extends 'input'
? string
: T extends 'select'
? string
: T extends 'counter'
? number
: T extends 'keybind'
? {
value: string;
accelerator: string;
}[]
: T extends 'multiInput'
? string[]
: never;

const prompt: <T extends Type>(options?: PromptOptions<T> & { type: T }, parent?: BrowserWindow) => Promise<PromptResult<T> | null>;
const prompt: <T extends Type>(
options?: PromptOptions<T> & { type: T },
parent?: BrowserWindow,
) => Promise<PromptResult<T> | null>;

export default prompt;
}
84 changes: 42 additions & 42 deletions src/error.html
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<head>
<meta charset="utf-8" />
<title>Cannot load YouTube Music</title>
<style>
body {
background: #000;
}
body {
background: #000;
}

.container {
margin: 0;
font-family: Roboto, Arial, sans-serif;
font-size: 20px;
font-weight: 500;
color: rgba(255, 255, 255, 0.5);
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
text-align: center;
}
.container {
margin: 0;
font-family: Roboto, Arial, sans-serif;
font-size: 20px;
font-weight: 500;
color: rgba(255, 255, 255, 0.5);
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
text-align: center;
}

.button {
background: #065fd4;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: white;
font: inherit;
text-transform: uppercase;
text-decoration: none;
border-radius: 2px;
font-size: 16px;
font-weight: normal;
text-align: center;
padding: 8px 22px;
display: inline-block;
}
.button {
background: #065fd4;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: white;
font: inherit;
text-transform: uppercase;
text-decoration: none;
border-radius: 2px;
font-size: 16px;
font-weight: normal;
text-align: center;
padding: 8px 22px;
display: inline-block;
}
</style>
</head>
</head>

<body>
<div class="container">
<p>Cannot load YouTube Music… Internet disconnected?</p>
<a class="button" href="#" onclick="reload()">Retry</a>
</div>
</body>
<body>
<div class="container">
<p>Cannot load YouTube Music… Internet disconnected?</p>
<a class="button" href="#" onclick="reload()">Retry</a>
</div>
</body>
</html>
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ const initHook = (win: BrowserWindow) => {
const mainPlugin = getAllLoadedMainPlugins()[id];
if (mainPlugin) {
if (config.enabled && typeof mainPlugin.backend !== 'function') {
mainPlugin.backend?.onConfigChange?.call(mainPlugin.backend, config);
mainPlugin.backend?.onConfigChange?.call(
mainPlugin.backend,
config,
);
}
}

Expand Down Expand Up @@ -282,7 +285,6 @@ async function createMainWindow() {

await loadAllMainPlugins(win);


if (windowPosition) {
const { x: windowX, y: windowY } = windowPosition;
const winSize = win.getSize();
Expand Down Expand Up @@ -317,7 +319,6 @@ async function createMainWindow() {
}
}


if (windowMaximized) {
win.maximize();
}
Expand Down
40 changes: 20 additions & 20 deletions src/loader/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils';
import type { PluginConfig, PluginDef } from '@/types/plugins';
import type { BackendContext } from '@/types/contexts';

const loadedPluginMap: Record<string, PluginDef<unknown, unknown, unknown>> = {};
const loadedPluginMap: Record<
string,
PluginDef<unknown, unknown, unknown>
> = {};

const createContext = (id: string, win: BrowserWindow): BackendContext<PluginConfig> => ({
const createContext = (
id: string,
win: BrowserWindow,
): BackendContext<PluginConfig> => ({
getConfig: () =>
deepmerge(
allPlugins[id].config ?? { enabled: false },
Expand All @@ -36,7 +42,7 @@ const createContext = (id: string, win: BrowserWindow): BackendContext<PluginCon
},
removeHandler: (event: string) => {
ipcMain.removeHandler(event);
}
},
},

window: win,
Expand All @@ -56,19 +62,15 @@ export const forceUnloadMainPlugin = async (
});
if (
hasStopped ||
(
hasStopped === null &&
typeof plugin.backend !== 'function' && plugin.backend
)
(hasStopped === null &&
typeof plugin.backend !== 'function' &&
plugin.backend)
) {
delete loadedPluginMap[id];
console.log(LoggerPrefix, `"${id}" plugin is unloaded`);
return;
} else {
console.log(
LoggerPrefix,
`Cannot unload "${id}" plugin`,
);
console.log(LoggerPrefix, `Cannot unload "${id}" plugin`);
return Promise.reject();
}
} catch (err) {
Expand All @@ -92,21 +94,17 @@ export const forceLoadMainPlugin = async (
});
if (
hasStarted ||
(
hasStarted === null &&
typeof plugin.backend !== 'function' && plugin.backend
)
(hasStarted === null &&
typeof plugin.backend !== 'function' &&
plugin.backend)
) {
loadedPluginMap[id] = plugin;
} else {
console.log(LoggerPrefix, `Cannot load "${id}" plugin`);
return Promise.reject();
}
} catch (err) {
console.error(
LoggerPrefix,
`Cannot initialize "${id}" plugin: `,
);
console.error(LoggerPrefix, `Cannot initialize "${id}" plugin: `);
console.trace(err);
return Promise.reject(err);
}
Expand Down Expand Up @@ -135,7 +133,9 @@ export const unloadAllMainPlugins = async (win: BrowserWindow) => {
}
};

export const getLoadedMainPlugin = (id: string): PluginDef<unknown, unknown, unknown> | undefined => {
export const getLoadedMainPlugin = (
id: string,
): PluginDef<unknown, unknown, unknown> | undefined => {
return loadedPluginMap[id];
};

Expand Down
Loading

0 comments on commit a3104fd

Please sign in to comment.