Merge branch 'Syngnat:dev' into dev

This commit is contained in:
Jonclex
2026-04-13 12:41:53 +08:00
committed by GitHub
36 changed files with 2097 additions and 497 deletions

View File

@@ -0,0 +1,21 @@
import { describe, expect, it } from 'vitest';
import { resolveAboutDisplayVersion } from './appVersionDisplay';
describe('resolveAboutDisplayVersion', () => {
it('shows fixed dev version for development build', () => {
expect(resolveAboutDisplayVersion('development', '0.6.5')).toBe('0.0.1-dev');
});
it('shows fixed dev version for wails dev build type', () => {
expect(resolveAboutDisplayVersion('dev', '0.6.5')).toBe('0.0.1-dev');
});
it('keeps real version for non-development builds', () => {
expect(resolveAboutDisplayVersion('production', '0.6.5')).toBe('0.6.5');
});
it('falls back to unknown when version is empty outside development', () => {
expect(resolveAboutDisplayVersion('production', '')).toBe('未知');
});
});

View File

@@ -0,0 +1,14 @@
const DEV_ABOUT_VERSION = '0.0.1-dev';
export const resolveAboutDisplayVersion = (
buildType: string,
version: string | undefined,
): string => {
const normalizedBuildType = String(buildType || '').trim().toLowerCase();
if (normalizedBuildType === 'development' || normalizedBuildType === 'dev') {
return DEV_ABOUT_VERSION;
}
const normalizedVersion = String(version || '').trim();
return normalizedVersion || '未知';
};

View File

@@ -4,14 +4,22 @@ import { shouldEnableMacWindowDiagnostics } from './macWindowDiagnostics';
describe('macWindowDiagnostics', () => {
it('stays disabled outside macOS runtime', () => {
expect(shouldEnableMacWindowDiagnostics(false, true)).toBe(false);
expect(shouldEnableMacWindowDiagnostics(false, true, 'true')).toBe(false);
});
it('stays disabled for production builds on macOS', () => {
expect(shouldEnableMacWindowDiagnostics(true, false)).toBe(false);
expect(shouldEnableMacWindowDiagnostics(true, false, 'true')).toBe(false);
});
it('enables diagnostics only for macOS development builds', () => {
expect(shouldEnableMacWindowDiagnostics(true, true)).toBe(true);
it('stays disabled by default for macOS development builds', () => {
expect(shouldEnableMacWindowDiagnostics(true, true)).toBe(false);
expect(shouldEnableMacWindowDiagnostics(true, true, '')).toBe(false);
expect(shouldEnableMacWindowDiagnostics(true, true, '0')).toBe(false);
});
it('enables diagnostics only when explicitly opted in on macOS development builds', () => {
expect(shouldEnableMacWindowDiagnostics(true, true, '1')).toBe(true);
expect(shouldEnableMacWindowDiagnostics(true, true, 'true')).toBe(true);
expect(shouldEnableMacWindowDiagnostics(true, true, 'yes')).toBe(true);
});
});

View File

@@ -1,6 +1,22 @@
const isTruthyFlag = (value: string | undefined): boolean => {
switch (String(value || '').trim().toLowerCase()) {
case '1':
case 'true':
case 'yes':
case 'on':
return true;
default:
return false;
}
};
export const shouldEnableMacWindowDiagnostics = (
isMacRuntime: boolean,
isDevBuild: boolean,
envValue?: string,
): boolean => {
return isMacRuntime && isDevBuild;
if (!isMacRuntime || !isDevBuild) {
return false;
}
return isTruthyFlag(envValue);
};