mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
feat(refactor): PluginDefinition::platform (#3665)
This commit is contained in:
@ -56,7 +56,8 @@
|
|||||||
"vudio@2.1.1": "patches/vudio@2.1.1.patch",
|
"vudio@2.1.1": "patches/vudio@2.1.1.patch",
|
||||||
"@malept/flatpak-bundler@0.4.0": "patches/@malept__flatpak-bundler@0.4.0.patch",
|
"@malept/flatpak-bundler@0.4.0": "patches/@malept__flatpak-bundler@0.4.0.patch",
|
||||||
"kuromoji@0.1.2": "patches/kuromoji@0.1.2.patch",
|
"kuromoji@0.1.2": "patches/kuromoji@0.1.2.patch",
|
||||||
"file-type@16.5.4": "patches/file-type@16.5.4.patch"
|
"file-type@16.5.4": "patches/file-type@16.5.4.patch",
|
||||||
|
"electron-is": "patches/electron-is.patch"
|
||||||
},
|
},
|
||||||
"neverBuiltDependencies": []
|
"neverBuiltDependencies": []
|
||||||
},
|
},
|
||||||
|
|||||||
27
patches/electron-is.patch
Normal file
27
patches/electron-is.patch
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
diff --git a/is.d.ts b/is.d.ts
|
||||||
|
index fb861f7b401914f0f89cb4edf25c51df5cb05812..82144733cd34d88e2deb2e4713b104418e673f2e 100644
|
||||||
|
--- a/is.d.ts
|
||||||
|
+++ b/is.d.ts
|
||||||
|
@@ -5,6 +5,7 @@ declare namespace is {
|
||||||
|
export function macOS(): boolean;
|
||||||
|
export function windows(): boolean;
|
||||||
|
export function linux(): boolean;
|
||||||
|
+ export function freebsd(): boolean;
|
||||||
|
export function x86(): boolean;
|
||||||
|
export function x64(): boolean;
|
||||||
|
export function production(): boolean;
|
||||||
|
diff --git a/is.js b/is.js
|
||||||
|
index a76bb1755a2728bde185b35d847031d3b8ea4ab0..f6b03406c17342f5af078de069e5bbbd2246e152 100644
|
||||||
|
--- a/is.js
|
||||||
|
+++ b/is.js
|
||||||
|
@@ -39,6 +39,10 @@ module.exports = {
|
||||||
|
linux: function () {
|
||||||
|
return process.platform === 'linux'
|
||||||
|
},
|
||||||
|
+ // Checks if we are under FreeBSD OS
|
||||||
|
+ freebsd: function () {
|
||||||
|
+ return process.platform === "freebsd"
|
||||||
|
+ },
|
||||||
|
// Checks if we are the processor's arch is x86
|
||||||
|
x86: function () {
|
||||||
|
return process.arch === 'ia32'
|
||||||
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
@ -16,6 +16,9 @@ patchedDependencies:
|
|||||||
'@malept/flatpak-bundler@0.4.0':
|
'@malept/flatpak-bundler@0.4.0':
|
||||||
hash: c787371eeb2af011ea934e8818a0dad6d7dcb2df31bbb1686babc7231af0183c
|
hash: c787371eeb2af011ea934e8818a0dad6d7dcb2df31bbb1686babc7231af0183c
|
||||||
path: patches/@malept__flatpak-bundler@0.4.0.patch
|
path: patches/@malept__flatpak-bundler@0.4.0.patch
|
||||||
|
electron-is:
|
||||||
|
hash: 08664a5453f092fe45542f9005ffc07527b1f207447318374cba0f4d30f466a0
|
||||||
|
path: patches/electron-is.patch
|
||||||
file-type@16.5.4:
|
file-type@16.5.4:
|
||||||
hash: fa6e3546c096bc3579fd83808c2dfac1a64546eb2ce096bf838076bda630baf5
|
hash: fa6e3546c096bc3579fd83808c2dfac1a64546eb2ce096bf838076bda630baf5
|
||||||
path: patches/file-type@16.5.4.patch
|
path: patches/file-type@16.5.4.patch
|
||||||
@ -113,7 +116,7 @@ importers:
|
|||||||
version: 4.1.0
|
version: 4.1.0
|
||||||
electron-is:
|
electron-is:
|
||||||
specifier: 3.0.0
|
specifier: 3.0.0
|
||||||
version: 3.0.0
|
version: 3.0.0(patch_hash=08664a5453f092fe45542f9005ffc07527b1f207447318374cba0f4d30f466a0)
|
||||||
electron-localshortcut:
|
electron-localshortcut:
|
||||||
specifier: 3.2.1
|
specifier: 3.2.1
|
||||||
version: 3.2.1
|
version: 3.2.1
|
||||||
@ -6850,7 +6853,7 @@ snapshots:
|
|||||||
|
|
||||||
electron-is-dev@3.0.1: {}
|
electron-is-dev@3.0.1: {}
|
||||||
|
|
||||||
electron-is@3.0.0:
|
electron-is@3.0.0(patch_hash=08664a5453f092fe45542f9005ffc07527b1f207447318374cba0f4d30f466a0):
|
||||||
dependencies:
|
dependencies:
|
||||||
electron-is-dev: 0.3.0
|
electron-is-dev: 0.3.0
|
||||||
semver: 5.7.2
|
semver: 5.7.2
|
||||||
|
|||||||
@ -59,14 +59,7 @@ import ErrorHtmlAsset from '@assets/error.html?asset';
|
|||||||
|
|
||||||
import { defaultAuthProxyConfig } from '@/plugins/auth-proxy-adapter/config';
|
import { defaultAuthProxyConfig } from '@/plugins/auth-proxy-adapter/config';
|
||||||
|
|
||||||
import type { PluginConfig } from '@/types/plugins';
|
import { type PluginConfig } from '@/types/plugins';
|
||||||
|
|
||||||
if (!is.macOS()) {
|
|
||||||
delete (await allPlugins())['touchbar'];
|
|
||||||
}
|
|
||||||
if (!is.windows()) {
|
|
||||||
delete (await allPlugins())['taskbar-mediacontrol'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Catch errors and log them
|
// Catch errors and log them
|
||||||
unhandled({
|
unhandled({
|
||||||
|
|||||||
@ -14,11 +14,13 @@ import registerCallback, {
|
|||||||
} from '@/providers/song-info';
|
} from '@/providers/song-info';
|
||||||
import { mediaIcons } from '@/types/media-icons';
|
import { mediaIcons } from '@/types/media-icons';
|
||||||
import { t } from '@/i18n';
|
import { t } from '@/i18n';
|
||||||
|
import { Platform } from '@/types/plugins';
|
||||||
|
|
||||||
export default createPlugin({
|
export default createPlugin({
|
||||||
name: () => t('plugins.taskbar-mediacontrol.name'),
|
name: () => t('plugins.taskbar-mediacontrol.name'),
|
||||||
description: () => t('plugins.taskbar-mediacontrol.description'),
|
description: () => t('plugins.taskbar-mediacontrol.description'),
|
||||||
restartNeeded: true,
|
restartNeeded: true,
|
||||||
|
platform: Platform.Windows,
|
||||||
config: {
|
config: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -6,11 +6,13 @@ import registerCallback, { SongInfoEvent } from '@/providers/song-info';
|
|||||||
import { t } from '@/i18n';
|
import { t } from '@/i18n';
|
||||||
|
|
||||||
import youtubeMusicIcon from '@assets/youtube-music.png?asset&asarUnpack';
|
import youtubeMusicIcon from '@assets/youtube-music.png?asset&asarUnpack';
|
||||||
|
import { Platform } from '@/types/plugins';
|
||||||
|
|
||||||
export default createPlugin({
|
export default createPlugin({
|
||||||
name: () => t('plugins.touchbar.name'),
|
name: () => t('plugins.touchbar.name'),
|
||||||
description: () => t('plugins.touchbar.description'),
|
description: () => t('plugins.touchbar.description'),
|
||||||
restartNeeded: true,
|
restartNeeded: true,
|
||||||
|
platform: Platform.macOS,
|
||||||
config: {
|
config: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
|
|||||||
2
src/reset.d.ts
vendored
2
src/reset.d.ts
vendored
@ -19,6 +19,8 @@ declare global {
|
|||||||
'videodatachange': CustomEvent<VideoDataChanged>;
|
'videodatachange': CustomEvent<VideoDataChanged>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare var electronIs: typeof import('electron-is')
|
||||||
|
|
||||||
interface Window {
|
interface Window {
|
||||||
trustedTypes?: typeof trustedTypes;
|
trustedTypes?: typeof trustedTypes;
|
||||||
ipcRenderer: typeof electronIpcRenderer;
|
ipcRenderer: typeof electronIpcRenderer;
|
||||||
|
|||||||
@ -38,6 +38,13 @@ export type RendererPluginLifecycle<Config, Context, This> =
|
|||||||
| PluginLifecycleSimple<Context, This>
|
| PluginLifecycleSimple<Context, This>
|
||||||
| RendererPluginLifecycleExtra<Config, Context, This>;
|
| RendererPluginLifecycleExtra<Config, Context, This>;
|
||||||
|
|
||||||
|
export enum Platform {
|
||||||
|
Windows = 1 << 0,
|
||||||
|
macOS = 1 << 1,
|
||||||
|
Linux = 1 << 2,
|
||||||
|
Freebsd = 1 << 3
|
||||||
|
}
|
||||||
|
|
||||||
export interface PluginDef<
|
export interface PluginDef<
|
||||||
BackendProperties,
|
BackendProperties,
|
||||||
PreloadProperties,
|
PreloadProperties,
|
||||||
@ -49,6 +56,7 @@ export interface PluginDef<
|
|||||||
description?: () => string;
|
description?: () => string;
|
||||||
addedVersion?: string;
|
addedVersion?: string;
|
||||||
config?: Config;
|
config?: Config;
|
||||||
|
platform?: Platform;
|
||||||
|
|
||||||
menu?: (
|
menu?: (
|
||||||
ctx: MenuContext<Config>,
|
ctx: MenuContext<Config>,
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url';
|
|||||||
|
|
||||||
import { globSync } from 'glob';
|
import { globSync } from 'glob';
|
||||||
import { Project } from 'ts-morph';
|
import { Project } from 'ts-morph';
|
||||||
|
import { Platform } from '../src/types/plugins'
|
||||||
|
|
||||||
const kebabToCamel = (text: string) =>
|
const kebabToCamel = (text: string) =>
|
||||||
text.replace(/-(\w)/g, (_, letter: string) => letter.toUpperCase());
|
text.replace(/-(\w)/g, (_, letter: string) => letter.toUpperCase());
|
||||||
@ -73,6 +74,12 @@ export const pluginVirtualModuleGenerator = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writer.blankLine();
|
||||||
|
if (mode === "main" || mode === "preload") {
|
||||||
|
writer.writeLine("import * as is from 'electron-is';");
|
||||||
|
writer.writeLine('globalThis.electronIs = is;');
|
||||||
|
}
|
||||||
|
writer.write(supportsPlatform.toString());
|
||||||
writer.blankLine();
|
writer.blankLine();
|
||||||
|
|
||||||
// Context-specific exports
|
// Context-specific exports
|
||||||
@ -95,7 +102,7 @@ export const pluginVirtualModuleGenerator = (
|
|||||||
}
|
}
|
||||||
writer.writeLine(' ]);');
|
writer.writeLine(' ]);');
|
||||||
writer.writeLine(
|
writer.writeLine(
|
||||||
' resolve(pluginEntries.filter((entry) => entry).reduce((acc, [name, plg]) => { acc[name] = plg; return acc; }, {}));',
|
' resolve(pluginEntries.filter((entry) => entry && supportsPlatform(entry[1])).reduce((acc, [name, plg]) => { acc[name] = plg; return acc; }, {}));',
|
||||||
);
|
);
|
||||||
writer.writeLine(` return await ${mode}PluginsCache;`);
|
writer.writeLine(` return await ${mode}PluginsCache;`);
|
||||||
writer.writeLine('};');
|
writer.writeLine('};');
|
||||||
@ -117,7 +124,7 @@ export const pluginVirtualModuleGenerator = (
|
|||||||
}
|
}
|
||||||
writer.writeLine(' ]);');
|
writer.writeLine(' ]);');
|
||||||
writer.writeLine(
|
writer.writeLine(
|
||||||
' resolve(stubEntries.reduce((acc, [name, plg]) => { acc[name] = plg; return acc; }, {}));',
|
' resolve(stubEntries.filter(entry => entry && supportsPlatform(entry[1])).reduce((acc, [name, plg]) => { acc[name] = plg; return acc; }, {}));',
|
||||||
);
|
);
|
||||||
writer.writeLine(' return await promise;');
|
writer.writeLine(' return await promise;');
|
||||||
writer.writeLine('};');
|
writer.writeLine('};');
|
||||||
@ -128,3 +135,17 @@ export const pluginVirtualModuleGenerator = (
|
|||||||
|
|
||||||
return src.getText();
|
return src.getText();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function supportsPlatform({ platform }: { platform: string }) {
|
||||||
|
if (typeof platform !== "number") return true;
|
||||||
|
|
||||||
|
const is = globalThis.electronIs;
|
||||||
|
|
||||||
|
if (is.windows()) return (platform & Platform.Windows) !== 0;
|
||||||
|
if (is.macOS()) return (platform & Platform.macOS) !== 0;
|
||||||
|
if (is.linux()) return (platform & Platform.Linux) !== 0;
|
||||||
|
if (is.freebsd()) return (platform & Platform.Freebsd) !== 0;
|
||||||
|
|
||||||
|
// unknown platform
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user