mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-08-20 00:15:27 -07:00
fix(launcher): restore Matroska thumbnails in Linux rofi picker (#210)
This commit is contained in:
@@ -159,6 +159,9 @@ interface RofiIconEntry {
|
||||
iconPath?: string;
|
||||
}
|
||||
|
||||
const ROFI_THUMBNAILER_FILE = 'subminer-ffmpegthumbnailer.thumbnailer';
|
||||
const DEFAULT_XDG_DATA_DIRS = ['/usr/local/share', '/usr/share'];
|
||||
|
||||
function showRofiIconMenu(
|
||||
entries: RofiIconEntry[],
|
||||
prompt: string,
|
||||
@@ -389,6 +392,47 @@ export function findRofiTheme(scriptPath: string): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
export function findRofiThumbnailerDataRoot(scriptPath: string): string | null {
|
||||
if (process.platform !== 'linux') return null;
|
||||
|
||||
const scriptDir = path.dirname(realpathMaybe(scriptPath));
|
||||
const xdgDataHome = process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local/share');
|
||||
const roots = [
|
||||
path.join(xdgDataHome, 'SubMiner'),
|
||||
path.posix.join('/usr/local/share/SubMiner'),
|
||||
path.posix.join('/usr/share/SubMiner'),
|
||||
path.join(scriptDir, 'assets'),
|
||||
path.join(scriptDir, '..', 'assets'),
|
||||
];
|
||||
|
||||
for (const root of roots) {
|
||||
if (fs.existsSync(path.join(root, 'thumbnailers', ROFI_THUMBNAILER_FILE))) {
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function prependXdgDataDir(dataRoot: string, currentValue?: string): string {
|
||||
const currentDirs = currentValue
|
||||
? currentValue.split(path.delimiter).filter(Boolean)
|
||||
: DEFAULT_XDG_DATA_DIRS;
|
||||
return [dataRoot, ...currentDirs.filter((candidate) => candidate !== dataRoot)].join(
|
||||
path.delimiter,
|
||||
);
|
||||
}
|
||||
|
||||
function buildRofiThumbnailEnvironment(scriptPath: string): NodeJS.ProcessEnv {
|
||||
if (!commandExists('ffmpegthumbnailer')) return process.env;
|
||||
const dataRoot = findRofiThumbnailerDataRoot(scriptPath);
|
||||
if (!dataRoot) return process.env;
|
||||
return {
|
||||
...process.env,
|
||||
XDG_DATA_DIRS: prependXdgDataDir(dataRoot, process.env.XDG_DATA_DIRS),
|
||||
};
|
||||
}
|
||||
|
||||
export function showRofiMenu(
|
||||
videos: string[],
|
||||
dir: string,
|
||||
@@ -420,6 +464,7 @@ export function showRofiMenu(
|
||||
const result = spawnSync('rofi', args, {
|
||||
input: buildRofiMenu(videos, dir, recursive),
|
||||
encoding: 'utf8',
|
||||
env: buildRofiThumbnailEnvironment(scriptPath),
|
||||
stdio: ['pipe', 'pipe', 'ignore'],
|
||||
});
|
||||
if (result.error) {
|
||||
|
||||
Reference in New Issue
Block a user