Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/common/dashboard/get-unraid-version.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getters } from '@app/store/index.js';
import { FileLoadStatus } from '@app/store/types.js';

/**
* Unraid version string.
* @returns The current version.
*/
export const getUnraidVersion = async (): Promise<string> => {
const { getters } = await import('@app/store/index.js');
const { status, var: emhttpVar } = getters.emhttp();
if (status === FileLoadStatus.LOADED) {
return emhttpVar.version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ describe('CustomizationService', () => {
vi.mocked(fs.access).mockRejectedValue(error);
const result = await service.getActivationData();
expect(result).toBeNull();
expect(loggerWarnSpy).toHaveBeenCalledWith(
expect(loggerDebugSpy).toHaveBeenCalledWith(
`Activation directory ${activationDir} not found when searching for JSON file.`
);
});
Expand All @@ -363,7 +363,7 @@ describe('CustomizationService', () => {
vi.mocked(fs.readdir).mockResolvedValue(['otherfile.txt' as any]);
const result = await service.getActivationData();
expect(result).toBeNull();
expect(loggerWarnSpy).toHaveBeenCalledWith('No activation JSON file found.');
expect(loggerDebugSpy).toHaveBeenCalledWith('No activation JSON file found.');
});

it('should return null and log error on readdir failure', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class CustomizationService implements OnModuleInit {
return jsonFile ? path.join(this.activationDir, jsonFile) : null;
} catch (error: unknown) {
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
this.logger.warn(
this.logger.debug(
`Activation directory ${this.activationDir} not found when searching for JSON file.`
);
} else {
Expand Down Expand Up @@ -144,7 +144,7 @@ export class CustomizationService implements OnModuleInit {
const activationJsonPath = await this.getActivationJsonPath();

if (!activationJsonPath) {
this.logger.warn('No activation JSON file found.');
this.logger.debug('No activation JSON file found.');
return null;
}

Expand Down
29 changes: 29 additions & 0 deletions api/src/unraid-api/unraid-file-modifier/file-modification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { access, readFile, unlink, writeFile } from 'fs/promises';
import { basename, dirname, join } from 'path';

import { applyPatch, createPatch, parsePatch, reversePatch } from 'diff';
import { coerce, compare, gte } from 'semver';

import { getUnraidVersion } from '@app/common/dashboard/get-unraid-version.js';

export interface ShouldApplyWithReason {
shouldApply: boolean;
Expand Down Expand Up @@ -236,4 +239,30 @@ export abstract class FileModification {
});
return patch;
}

protected async isUnraidVersionGreaterThanOrEqualTo(
version: string = '7.2.0', // Defaults to the version of Unraid that includes the API by default
{ includePrerelease = true }: { includePrerelease?: boolean } = {}
): Promise<boolean> {
const unraidVersion = coerce(await getUnraidVersion(), { includePrerelease });
const comparedVersion = coerce(version, { includePrerelease });
if (!unraidVersion) {
throw new Error(`Failed to compare Unraid version - missing unraid version`);
}
if (!comparedVersion) {
throw new Error(`Failed to compare Unraid version - missing comparison version`);
}
// If includePrerelease and base versions are equal, treat prerelease as greater
if (includePrerelease) {
const baseUnraid = `${unraidVersion.major}.${unraidVersion.minor}.${unraidVersion.patch}`;
const baseCompared = `${comparedVersion.major}.${comparedVersion.minor}.${comparedVersion.patch}`;
if (baseUnraid === baseCompared) {
// If unraidVersion has prerelease and comparedVersion does not, treat as greater
if (unraidVersion.prerelease.length && !comparedVersion.prerelease.length) {
return true;
}
}
}
return gte(unraidVersion, comparedVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ function verifyUsernamePassword(string $username, string $password): bool
$myCase = file_exists("$boot/$myFile") ? file_get_contents("$boot/$myFile") : false;

extract(parse_plugin_cfg('dynamix', true));
$theme_dark = in_array($display['theme'], ['black', 'gray']);

require_once "$docroot/plugins/dynamix/include/ThemeHelper.php";
$themeHelper = new ThemeHelper($display['theme']);
$isDarkTheme = $themeHelper->isDarkTheme();
?>

<!DOCTYPE html>
<html lang="en">
<html lang="en" class="<?= $themeHelper->getThemeHtmlClass() ?>">
<head>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
Expand Down Expand Up @@ -201,8 +204,8 @@ function verifyUsernamePassword(string $username, string $password): bool
/
/************************/
body {
background: <?=$theme_dark ? '#1C1B1B' : '#F2F2F2'?>;
color: <?=$theme_dark ? '#fff' : '#1c1b1b'?>;
background: <?=$isDarkTheme?'#1C1B1B':'#F2F2F2'?>;
color: <?=$isDarkTheme?'#fff':'#1c1b1b'?>;
font-family: clear-sans, sans-serif;
font-size: .875rem;
padding: 0;
Expand Down Expand Up @@ -286,7 +289,7 @@ function verifyUsernamePassword(string $username, string $password): bool
width: 500px;
margin: 6rem auto;
border-radius: 10px;
background: <?=$theme_dark ? '#2B2A29' : '#fff'?>;
background: <?=$isDarkTheme?'#2B2A29':'#fff'?>;
}
#login::after {
content: "";
Expand Down Expand Up @@ -378,7 +381,7 @@ function verifyUsernamePassword(string $username, string $password): bool
/************************/
@media (max-width: 500px) {
body {
background: <?=$theme_dark ? '#2B2A29' : '#fff'?>;
background: <?=$isDarkTheme?'#2B2A29':'#fff'?>;
}
[type=email], [type=number], [type=password], [type=search], [type=tel], [type=text], [type=url], textarea {
font-size: 16px; /* This prevents the mobile browser from zooming in on the input-field. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1747746267705
1747746267705
Loading
Loading