Skip to content

Commit

Permalink
fix: apply fix from eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyBrick committed Oct 13, 2024
1 parent f42f20f commit cb1381b
Show file tree
Hide file tree
Showing 85 changed files with 1,881 additions and 1,065 deletions.
4 changes: 2 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default tsEslint.config(
tsEslint.configs.eslintRecommended,
...tsEslint.configs.recommendedTypeChecked,
prettier,
{ ignores: ['dist', 'node_modules', '*.config.*js'] },
{ ignores: ['dist', 'node_modules', '*.config.*js', '*.test.*js'] },
{
plugins: {
stylistic,
Expand Down Expand Up @@ -54,7 +54,7 @@ export default tsEslint.config(
afterLineComment: false,
}],
'stylistic/max-len': 'off',
'stylistic/no-mixed-operators': 'error',
'stylistic/no-mixed-operators': 'warn', // prettier does not support no-mixed-operators
'stylistic/no-multi-spaces': ['error', { ignoreEOLComments: true }],
'stylistic/no-tabs': 'error',
'no-void': 'error',
Expand Down
38 changes: 19 additions & 19 deletions src/custom-electron-prompt.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,29 @@ declare module 'custom-electron-prompt' {
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;
? 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;
? 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 },
Expand Down
30 changes: 19 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,20 @@ async function createMainWindow() {
const display = screen.getDisplayNearestPoint(windowPosition);
const primaryDisplay = screen.getPrimaryDisplay();

const scaleFactor = is.windows() ? primaryDisplay.scaleFactor / display.scaleFactor : 1;
const scaleFactor = is.windows()
? primaryDisplay.scaleFactor / display.scaleFactor
: 1;
const scaledWidth = Math.floor(windowSize.width * scaleFactor);
const scaledHeight = Math.floor(windowSize.height * scaleFactor);

const scaledX = windowX;
const scaledY = windowY;

if (
scaledX + (scaledWidth / 2) < display.bounds.x - 8 || // Left
scaledX + (scaledWidth / 2) > display.bounds.x + display.bounds.width || // Right
scaledX + scaledWidth / 2 < display.bounds.x - 8 || // Left
scaledX + scaledWidth / 2 > display.bounds.x + display.bounds.width || // Right
scaledY < display.bounds.y - 8 || // Top
scaledY + (scaledHeight / 2) > display.bounds.y + display.bounds.height // Bottom
scaledY + scaledHeight / 2 > display.bounds.y + display.bounds.height // Bottom
) {
// Window is offscreen
if (is.dev()) {
Expand Down Expand Up @@ -442,7 +444,7 @@ async function createMainWindow() {
...defaultTitleBarOverlayOptions,
height: Math.floor(
defaultTitleBarOverlayOptions.height! *
win.webContents.getZoomFactor(),
win.webContents.getZoomFactor(),
),
});
}
Expand All @@ -455,7 +457,7 @@ async function createMainWindow() {
event.preventDefault();

win.webContents.loadURL(
'https://accounts.google.com/ServiceLogin?ltmpl=music&service=youtube&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26next%3Dhttps%253A%252F%252Fmusic.youtube.com%252F'
'https://accounts.google.com/ServiceLogin?ltmpl=music&service=youtube&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26next%3Dhttps%253A%252F%252Fmusic.youtube.com%252F',
);
}
});
Expand All @@ -479,8 +481,8 @@ app.once('browser-window-created', (_event, win) => {
const updatedUserAgent = is.macOS()
? userAgents.mac
: is.windows()
? userAgents.windows
: userAgents.linux;
? userAgents.windows
: userAgents.linux;

win.webContents.userAgent = updatedUserAgent;
app.userAgentFallback = updatedUserAgent;
Expand Down Expand Up @@ -642,7 +644,9 @@ app.whenReady().then(async () => {
// In dev mode, get string from process.env.VITE_DEV_SERVER_URL, else use fs.readFileSync
if (is.dev() && process.env.ELECTRON_RENDERER_URL) {
// HACK: to make vite work with electron renderer (supports hot reload)
event.returnValue = [null, `
event.returnValue = [
null,
`
console.log('${LoggerPrefix}', 'Loading vite from dev server');
(async () => {
await new Promise((resolve) => {
Expand All @@ -663,7 +667,8 @@ app.whenReady().then(async () => {
document.body.appendChild(rendererScript);
})();
0
`];
`,
];
} else {
const rendererPath = path.join(__dirname, '..', 'renderer');
const indexHTML = parse(
Expand All @@ -675,7 +680,10 @@ app.whenReady().then(async () => {
scriptSrc.getAttribute('src')!,
);
const scriptString = fs.readFileSync(scriptPath, 'utf-8');
event.returnValue = [url.pathToFileURL(scriptPath).toString(), scriptString + ';0'];
event.returnValue = [
url.pathToFileURL(scriptPath).toString(),
scriptString + ';0',
];
}
});

Expand Down
27 changes: 14 additions & 13 deletions src/loader/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ const createContext = (
win.webContents.send(event, ...args);
},
handle: (event: string, listener: CallableFunction) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
ipcMain.handle(event, (_, ...args: unknown[]) => listener(...args));
},
on: (event: string, listener: CallableFunction) => {
ipcMain.on(event, (_, ...args: unknown[]) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
listener(...args);
});
},
Expand Down Expand Up @@ -75,19 +76,19 @@ export const forceUnloadMainPlugin = async (
);
return;
} else {
console.log(
LoggerPrefix,
t('common.console.plugins.unload-failed', { pluginName: id }),
);
return Promise.reject();
const message = t('common.console.plugins.unload-failed', {
pluginName: id,
});
console.log(LoggerPrefix, message);
return Promise.reject(new Error(message));
}
} catch (err) {
console.error(
LoggerPrefix,
t('common.console.plugins.unload-failed', { pluginName: id }),
);
console.trace(err);
return Promise.reject(err);
return Promise.reject(err as Error);
}
};

Expand All @@ -111,19 +112,19 @@ export const forceLoadMainPlugin = async (
) {
loadedPluginMap[id] = plugin;
} else {
console.log(
LoggerPrefix,
t('common.console.plugins.load-failed', { pluginName: id }),
);
return Promise.reject();
const message = t('common.console.plugins.load-failed', {
pluginName: id,
});
console.log(LoggerPrefix, message);
return Promise.reject(new Error(message));
}
} catch (err) {
console.error(
LoggerPrefix,
t('common.console.plugins.initialize-failed', { pluginName: id }),
);
console.trace(err);
return Promise.reject(err);
return Promise.reject(err as Error);
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/loader/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const loadedPluginMap: Record<
export const createContext = <Config extends PluginConfig>(
id: string,
): RendererContext<Config> => ({
getConfig: async () => window.ipcRenderer.invoke('ytmd:get-config', id),
getConfig: async () =>
window.ipcRenderer.invoke('ytmd:get-config', id) as Promise<Config>,
setConfig: async (newConfig) => {
await window.ipcRenderer.invoke('ytmd:set-config', id, newConfig);
},
Expand All @@ -30,6 +31,7 @@ export const createContext = <Config extends PluginConfig>(
window.ipcRenderer.invoke(event, ...args),
on: (event: string, listener: CallableFunction) => {
window.ipcRenderer.on(event, (_, ...args: unknown[]) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
listener(...args);
});
},
Expand Down
Loading

0 comments on commit cb1381b

Please sign in to comment.