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
1 change: 1 addition & 0 deletions frontend/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare module 'vue' {
DriverFormComponent: typeof import('./src/components/DriverFormComponent.vue')['default']
DriverInspectModal: typeof import('./src/components/DriverInspectModal.vue')['default']
DriverSelector: typeof import('./src/components/DriverSelector.vue')['default']
HardwareInfo: typeof import('./src/components/HardwareInfo.vue')['default']
LoadingOverlay: typeof import('./src/components/LoadingOverlay.vue')['default']
MatchRuleFormComponent: typeof import('./src/components/MatchRuleFormComponent.vue')['default']
MatchRuleInputModal: typeof import('./src/components/MatchRuleInputModal.vue')['default']
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as appSettingStorage from '@/wailsjs/go/storage/AppSettingStorage'
import * as driverGroupStorage from '@/wailsjs/go/storage/DriverGroupStorage'
import * as ruleSetStorage from '@/wailsjs/go/storage/RuleSetStorage'
import { CheckForUpdates } from '@/wailsjs/go/update/Updater'
import { ref } from 'vue'
import { ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import type { RouteLocationRaw } from 'vue-router'

Expand All @@ -21,6 +21,14 @@ const [settingsStore, groupStore, matchStore, unsavedFormStore] = [

const initilisating = ref(true)

watch(
() => settingsStore.settings.ui_scale,
scale => {
document.documentElement.style.fontSize = `${Number(scale) || 100}%`
},
{ immediate: true }
)

const hasUpdate = ref(false)

Promise.all([
Expand Down
77 changes: 77 additions & 0 deletions frontend/src/components/HardwareInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<script setup lang="ts">
import { sysinfo } from '@/wailsjs/go/models'
import { computed } from 'vue'

const props = withDefaults(
defineProps<{
/** null renders nothing; callers may bind the page's hw+os ref directly */
info?: { hw: sysinfo.ResolvedHardware; os: sysinfo.OSInfo } | null
size?: 'normal' | 'large'
/** null/undefined hides the badge */
cpuTemp?: { value: number | null; error: string | null } | null
}>(),
{ size: 'normal', info: null, cpuTemp: null }
)

// Full literal class strings so Tailwind JIT can see them
const STYLES: Record<
typeof props.size,
{ heading: string; value: string; block: string; badge: string }
> = {
normal: { heading: 'text-sm', value: 'text-sm', block: '', badge: 'text-xs' },
large: {
heading: 'text-xl',
value: 'text-xl',
block: 'mb-2',
badge: 'text-base'
}
}

function hwKey(part: string): string {
return `hw${part.charAt(0).toUpperCase() + part.slice(1)}`
}

const tempClass = computed(() =>
props.cpuTemp?.error != null
? 'bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400'
: props.cpuTemp!.value! < 45
? 'bg-apple-green-100 text-apple-green-700'
: props.cpuTemp!.value! >= 85
? 'bg-red-100 text-red-700'
: 'bg-yellow-100 text-yellow-700'
)

const tempText = computed(() => `${props.cpuTemp?.error != null ? '--' : props.cpuTemp!.value}°C`)
</script>

<template>
<template v-if="info">
<div v-for="[part, names] in Object.entries(info.hw)" :key="part" :class="STYLES[size].block">
<h2 :class="STYLES[size].heading" class="font-bold">
{{ $t(hwKey(part)) }}
<UBadge
v-if="part === 'cpu' && cpuTemp && (cpuTemp.value != null || cpuTemp.error != null)"
size="sm"
class="ms-1 rounded px-1.5 py-0 font-medium"
:class="[STYLES[size].badge, tempClass]"
>
{{ tempText }}
</UBadge>
</h2>

<p v-for="(name, i) in names" :key="i" :class="STYLES[size].value">
{{ name }}
</p>
</div>

<div>
<h2 :class="STYLES[size].heading" class="font-bold">{{ $t('hwOs') }}</h2>

<p class="wrap-break-word" :class="STYLES[size].value">
{{ [info.os.caption, info.os.displayVersion].filter(Boolean).join(' ') }}
—
{{ $t(info.os.activated ? 'osActivationActivated' : 'osActivationNotActivated') }}
</p>
</div>
</template>
</template>
2 changes: 2 additions & 0 deletions frontend/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"settingSuccessAction": "On Completion",
"settingSuccessActionDelay": "Success Action Delay",
"settingTask": "Task",
"settingTextScale": "Text Size",
"statusAborted": "aborted",
"statusAborting": "aborting",
"statusCompleted": "completed",
Expand Down Expand Up @@ -229,6 +230,7 @@
"titleImportExport": "Import/Export",
"titleImportPreview": "Import Preview",
"titleInspectGroup": "Inspect Option",
"titleLargeView": "Hardware Summary",
"titleMatchRule": "Match Rule",
"titleSettings": "Settings",
"titleSetupTools": "Setup Tools",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/i18n/zh_Hant_HK.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"settingSuccessAction": "關機設定",
"settingSuccessActionDelay": "關機選項延遲",
"settingTask": "額外工作",
"settingTextScale": "介面文字大小",
"statusAborted": "已取消",
"statusAborting": "取消中",
"statusCompleted": "完成",
Expand Down Expand Up @@ -229,6 +230,7 @@
"titleImportExport": "匯入/匯出資料",
"titleImportPreview": "匯入預覽",
"titleInspectGroup": "檢視選項",
"titleLargeView": "硬體摘要",
"titleMatchRule": "配對規則",
"titleSettings": "設定",
"titleSetupTools": "系統工具",
Expand Down
104 changes: 60 additions & 44 deletions frontend/src/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import CommandStatueModal from '@/components/CommandStatusModal.vue'
import HardwareInfo from '@/components/HardwareInfo.vue'
import { type Command } from '@/types/execute'
import * as utils from '@/utils'
import { decodeError } from '@/utils/index'
Expand All @@ -14,10 +15,6 @@ const { t } = useI18n()

const toast = useToast()

function hwKey(part: string): string {
return `hw${part.charAt(0).toUpperCase() + part.slice(1)}`
}

const [statusModal, form] = [useTemplateRef('statusModal'), useTemplateRef('form')]

const [groupStore, settingStore] = [useDriverGroupStore(), useAppSettingStore()]
Expand All @@ -44,6 +41,14 @@ const selectedDisplay = ref<number>(0)
const selectedMiscellaneous = ref<number[]>([])
const matching = ref(false)

const largeView = ref(false)

// Narrowed hw+os pair for HardwareInfo; null while data is loading
const hwInfo = computed(() => {
const { hw, os } = systemInfo.value
return hw !== null && os !== null ? { hw, os } : null
})

function loadSystemInfo() {
Promise.all([utils.getHardware(), utils.getOSInfo()]).then(([hw, os]) => {
systemInfo.value = { hw, os }
Expand Down Expand Up @@ -212,45 +217,29 @@ onBeforeUnmount(() => {

<template>
<div class="flex h-full flex-col">
<div class="flex flex-1 flex-col gap-y-1 overflow-y-auto rounded-sm border p-1">
<template v-if="systemInfo.hw !== null && systemInfo.os !== null">
<div v-for="[part, names] in Object.entries(systemInfo.hw)" :key="part">
<h2 class="text-sm font-bold">
{{ $t(hwKey(part)) }}
<UBadge
v-if="part === 'cpu' && (cpuTemp !== null || cpuTempError !== null)"
size="sm"
class="ms-1 rounded px-1.5 py-0 text-xs font-medium"
:class="
cpuTempError !== null
? 'bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400'
: cpuTemp! < 45
? 'bg-apple-green-100 text-apple-green-700'
: cpuTemp! >= 85
? 'bg-red-100 text-red-700'
: 'bg-yellow-100 text-yellow-700'
"
>
{{ cpuTempError !== null ? '--' : cpuTemp! }}°C
</UBadge>
</h2>

<p v-for="(name, i) in names" :key="i" class="text-sm">
{{ name }}
</p>
</div>

<div>
<h2 class="text-sm font-bold">{{ $t('hwOs') }}</h2>

<p class="text-sm">
{{ [systemInfo.os!.caption, systemInfo.os!.displayVersion].filter(Boolean).join(' ') }}
—
{{
$t(systemInfo.os!.activated ? 'osActivationActivated' : 'osActivationNotActivated')
}}
</p>
</div>
<div class="relative flex flex-1 flex-col gap-y-1 overflow-y-auto rounded-sm border p-1">
<UButton
icon="mdi:fullscreen"
variant="ghost"
color="neutral"
size="xs"
class="absolute inset-e-1 top-1 z-10"
:disabled="hwInfo === null"
:aria-label="$t('titleLargeView')"
@click="
() => {
loadSystemInfo()
largeView = true
}
"
/>

<template v-if="hwInfo !== null">
<HardwareInfo
:info="hwInfo"
size="normal"
:cpu-temp="{ value: cpuTemp, error: cpuTempError }"
/>
</template>

<template v-else>
Expand Down Expand Up @@ -320,7 +309,7 @@ onBeforeUnmount(() => {
<div class="flex flex-1">
<div class="relative mb-3 h-full w-full">
<label
class="pointer-events-none absolute top-1 left-3 origin-top-left -translate-y-[0.55rem] scale-[0.9] bg-white px-2 text-xs text-gray-500"
class="pointer-events-none absolute top-1 left-3 origin-top-left translate-y-[-0.55rem] scale-[0.9] bg-white px-2 text-xs text-gray-500"
>
{{ $t('categoryMiscellaneous') }}
</label>
Expand Down Expand Up @@ -449,6 +438,33 @@ onBeforeUnmount(() => {
</div>
</div>

<!-- lg:max-w-none overrides the global modal content `lg:max-w-3xl` set in vite.config.ts -->
<UModal
v-model:open="largeView"
fullscreen
:close="false"
:ui="{ content: 'lg:max-w-none overflow-y-auto' }"
>
<template #content>
<UButton
icon="mdi:close"
variant="ghost"
color="neutral"
class="absolute inset-e-5 top-5 text-neutral-500 hover:text-neutral-900"
:aria-label="$t('close')"
@click="largeView = false"
/>

<div class="px-10 py-4">
<HardwareInfo
:info="hwInfo"
size="large"
:cpu-temp="{ value: cpuTemp, error: cpuTempError }"
/>
</div>
</template>
</UModal>

<CommandStatueModal
ref="statusModal"
@completed="
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/pages/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,23 @@ function handleSubmit() {

<hr class="border-gray-100 dark:border-gray-800" />

<section>
<h3 class="mb-3 text-lg font-bold">{{ $t('settingTextScale') }}</h3>

<div class="flex flex-col gap-y-1">
<USelect
v-model="settings.ui_scale"
name="ui_scale"
color="primary"
variant="outline"
class="w-56"
:items="[100, 125, 150].map(v => ({ label: `${v}%`, value: v }))"
/>
</div>
</section>

<hr class="border-gray-100 dark:border-gray-800" />

<section>
<h3 class="mb-3 text-lg font-bold">{{ $t('settingCPUTemp') }}</h3>

Expand Down
2 changes: 2 additions & 0 deletions frontend/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export namespace storage {
allow_pre_release: boolean;
enable_cpu_temp: boolean;
cpu_temp_refresh_interval: number;
ui_scale: number;

static createFrom(source: any = {}) {
return new AppSetting(source);
Expand All @@ -212,6 +213,7 @@ export namespace storage {
this.allow_pre_release = source["allow_pre_release"];
this.enable_cpu_temp = source["enable_cpu_temp"];
this.cpu_temp_refresh_interval = source["cpu_temp_refresh_interval"];
this.ui_scale = source["ui_scale"];
}
}
export class Driver {
Expand Down
6 changes: 6 additions & 0 deletions pkg/storage/app_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type AppSetting struct {
AllowPreRelease bool `json:"allow_pre_release"`
EnableCPUTemp bool `json:"enable_cpu_temp"`
CPUTempRefreshInterval int `json:"cpu_temp_refresh_interval"`
UIScale int `json:"ui_scale"`
}

type SuccessAction string
Expand Down Expand Up @@ -50,6 +51,7 @@ func (s *AppSettingStorage) All() (AppSetting, error) {
SuccessActionDelay: 5,
EnableCPUTemp: false,
CPUTempRefreshInterval: 5,
UIScale: 100,
}
return s.setting, s.write()
}
Expand All @@ -63,6 +65,10 @@ func (s *AppSettingStorage) All() (AppSetting, error) {
if s.setting.CPUTempRefreshInterval <= 0 {
s.setting.CPUTempRefreshInterval = 5
}
// Backfill: legacy setting.json predates ui_scale.
if s.setting.UIScale <= 0 {
s.setting.UIScale = 100
}
return s.setting, nil
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/storage/app_setting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func TestAppSettingStorage_AllWithoutExistingFile(t *testing.T) {
if result.SuccessActionDelay != 5 {
t.Errorf("expected SuccessActionDelay to be 5, got %d", result.SuccessActionDelay)
}
if result.UIScale != 100 {
t.Errorf("expected UIScale to be 100, got %d", result.UIScale)
}
}

func TestAppSettingStorage_AllWithExistingFile(t *testing.T) {
Expand Down Expand Up @@ -213,6 +216,10 @@ func TestLegacySettingMigration(t *testing.T) {
if result.AutoCheckUpdate != true {
t.Errorf("AutoCheckUpdate = %v, want true", result.AutoCheckUpdate)
}
// Legacy files also predate ui_scale, which backfills to 100.
if result.UIScale != 100 {
t.Errorf("UIScale = %d, want 100", result.UIScale)
}
}

// jsonMarshal is a test helper that panics on marshal error.
Expand Down
Loading