feat: support theme update and various improvements

- Add support for updating themes if a newer version is uploaded
- Hide config button for plugins without configuration items
- Auto refresh theme cache after panel update
- Fix issue where user used traffic cannot be set as a decimal
- Fix subscription issue for shadowrocket in v2board theme
This commit is contained in:
xboard
2025-07-15 01:26:14 +08:00
parent f6cf6706c7
commit 706ba5a7a9
7 changed files with 42 additions and 30 deletions
+21 -10
View File
@@ -156,7 +156,21 @@ class ThemeService
$targetPath = $userThemePath . $config['name'];
if (File::exists($targetPath)) {
throw new Exception('主题已存在');
$oldConfigFile = $targetPath . '/config.json';
if (!File::exists($oldConfigFile)) {
throw new Exception('已存在主题缺少配置文件');
}
$oldConfig = json_decode(File::get($oldConfigFile), true);
$oldVersion = $oldConfig['version'] ?? '0.0.0';
$newVersion = $config['version'] ?? '0.0.0';
if (version_compare($newVersion, $oldVersion, '>')) {
File::deleteDirectory($targetPath);
File::copyDirectory($sourcePath, $targetPath);
$this->initConfig($config['name']);
return true;
} else {
throw new Exception('主题已存在且不是新版本');
}
}
File::copyDirectory($sourcePath, $targetPath);
@@ -180,9 +194,6 @@ class ThemeService
public function switch(string $theme): bool
{
$currentTheme = admin_setting('current_theme');
if ($theme === $currentTheme) {
return true;
}
try {
// 验证主题是否存在
@@ -196,12 +207,6 @@ class ThemeService
throw new Exception('主题视图文件不存在');
}
// 复制主题文件到public目录
$targetPath = public_path('theme/' . $theme);
if (!File::copyDirectory($themePath, $targetPath)) {
throw new Exception('复制主题文件失败');
}
// 清理旧主题文件
if ($currentTheme) {
$oldPath = public_path('theme/' . $currentTheme);
@@ -210,6 +215,12 @@ class ThemeService
}
}
// 复制主题文件到public目录
$targetPath = public_path('theme/' . $theme);
if (!File::copyDirectory($themePath, $targetPath)) {
throw new Exception('复制主题文件失败');
}
admin_setting(['current_theme' => $theme]);
return true;