feat: add auto update support (#65)

This commit is contained in:
2026-05-16 00:09:14 -07:00
committed by GitHub
parent 105713361e
commit 91a01b86a9
71 changed files with 2368 additions and 188 deletions
+9 -22
View File
@@ -29,12 +29,6 @@ export function detectSupportAssetDataDirs(options: {
homeDir: string;
xdgDataHome?: string;
}): string[] {
if (options.platform === 'darwin') {
return [
path.join(options.homeDir, 'Library/Application Support/SubMiner'),
'/usr/local/share/SubMiner',
];
}
if (options.platform === 'linux') {
const xdgDataHome = options.xdgDataHome || path.join(options.homeDir, '.local/share');
return [path.join(xdgDataHome, 'SubMiner'), '/usr/local/share/SubMiner', '/usr/share/SubMiner'];
@@ -46,10 +40,10 @@ export function buildProtectedSupportAssetsCommand(assetUrl: string, dataDir: st
const quotedDir = shellQuote(dataDir);
return [
'tmp=$(mktemp -d)',
'trap \'rm -rf "$tmp"\' EXIT',
`curl -fSL ${shellQuote(assetUrl)} -o "$tmp/subminer-assets.tar.gz"`,
'tar -xzf "$tmp/subminer-assets.tar.gz" -C "$tmp"',
`sudo mkdir -p ${quotedDir}/plugin/subminer ${quotedDir}/themes`,
`sudo cp -R "$tmp/plugin/subminer/." ${quotedDir}/plugin/subminer/`,
`sudo mkdir -p ${quotedDir}/themes`,
`sudo cp "$tmp/assets/themes/subminer.rasi" ${quotedDir}/themes/subminer.rasi`,
].join(' && ');
}
@@ -76,12 +70,15 @@ export async function updateSupportAssetsFromRelease(options: {
homeDir?: string;
xdgDataHome?: string;
}): Promise<SupportAssetsUpdateResult[]> {
if ((options.platform ?? process.platform) !== 'linux') {
return [{ status: 'skipped', message: 'Support assets are only installed on Linux.' }];
}
if (!options.release) return [{ status: 'missing-asset', message: 'No release found.' }];
const asset = findReleaseAsset(options.release, 'subminer-assets.tar.gz');
if (!asset) return [{ status: 'missing-asset', message: 'Release has no support assets.' }];
if (!asset) return [{ status: 'missing-asset', message: 'Release has no rofi theme asset.' }];
const expectedSha256 = options.sha256Sums.get('subminer-assets.tar.gz');
if (!expectedSha256) {
return [{ status: 'missing-asset', message: 'SHA256SUMS.txt has no support assets entry.' }];
return [{ status: 'missing-asset', message: 'SHA256SUMS.txt has no rofi theme entry.' }];
}
const dataDirs = detectSupportAssetDataDirs({
@@ -91,12 +88,11 @@ export async function updateSupportAssetsFromRelease(options: {
});
const existingDataDirs: string[] = [];
for (const dataDir of dataDirs) {
const hasPlugin = await pathExists(path.join(dataDir, 'plugin/subminer'));
const hasTheme = await pathExists(path.join(dataDir, 'themes/subminer.rasi'));
if (hasPlugin || hasTheme) existingDataDirs.push(dataDir);
if (hasTheme) existingDataDirs.push(dataDir);
}
if (existingDataDirs.length === 0) {
return [{ status: 'skipped', message: 'No existing support asset install detected.' }];
return [{ status: 'skipped', message: 'No existing rofi theme install detected.' }];
}
const protectedResults: SupportAssetsUpdateResult[] = existingDataDirs
@@ -139,17 +135,8 @@ export async function updateSupportAssetsFromRelease(options: {
await execFileAsync('tar', ['-xzf', archivePath, '-C', tempDir]);
const results: SupportAssetsUpdateResult[] = [...protectedResults];
for (const dataDir of writableDataDirs) {
const targetPluginDir = path.join(dataDir, 'plugin/subminer');
const targetThemePath = path.join(dataDir, 'themes/subminer.rasi');
if (await pathExists(targetPluginDir)) {
await fs.promises.mkdir(targetPluginDir, { recursive: true });
await fs.promises.cp(path.join(tempDir, 'plugin/subminer'), targetPluginDir, {
recursive: true,
force: true,
});
}
if (await pathExists(targetThemePath)) {
await fs.promises.mkdir(path.dirname(targetThemePath), { recursive: true });
await fs.promises.copyFile(
path.join(tempDir, 'assets/themes/subminer.rasi'),
targetThemePath,