From 123c74de46836baa4775619b3865f8ae79bf182c Mon Sep 17 00:00:00 2001 From: kuaifan Date: Wed, 15 Oct 2025 22:55:16 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish.yml | 1 - .gitignore | 3 ++ app/Http/Controllers/IndexController.php | 4 ++ app/Module/Base.php | 57 ++++++++++++++++++++++++ cmd | 22 ++++++++- electron/index.html | 2 +- index.html | 1 - resources/assets/js/app.js | 2 + resources/views/main.blade.php | 2 +- vite.config.js | 15 ++++++- 10 files changed, 102 insertions(+), 7 deletions(-) delete mode 100644 index.html diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 34977b159..3a4891fd4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,7 +4,6 @@ on: push: branches: - "pro" - - "dev" jobs: check-version: diff --git a/.gitignore b/.gitignore index e91b730a7..fceb5b219 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,9 @@ vars.yaml Homestead.json Homestead.yaml +# Development file +/index.html + # Testing .phpunit.result.cache test.* diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 7a73a9421..dea8947d2 100755 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -61,6 +61,10 @@ class IndexController extends InvokeController $array = Base::json2array(file_get_contents($hotFile)); $style = null; $script = preg_replace("/^(\/\/(.*?))(:\d+)?\//i", "$1:" . $array['APP_DEV_PORT'] . "/", asset_main("resources/assets/js/app.js")); + $proxyUri = Base::liveEnv('VSCODE_PROXY_URI'); + if (is_string($proxyUri) && preg_match('/^https?:\/\//i', $proxyUri)) { + $script = preg_replace('/^(https?:\/\/|\/\/)[^\/]+/', rtrim($proxyUri, '/'), $script, 1); + } } else { $array = Base::json2array(file_get_contents($manifestFile)); $style = asset_main($array['resources/assets/js/app.js']['css'][0]); diff --git a/app/Module/Base.php b/app/Module/Base.php index bbed5b8ed..ab0baeccb 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -3073,4 +3073,61 @@ class Base return $html; } } + + /** + * 实时读取 .env 配置(不受配置缓存影响) + * @param string $key 配置键名 + * @param mixed $default 默认值 + * @return mixed + */ + public static function liveEnv($key, $default = null) + { + $envFile = base_path('.env'); + if (!file_exists($envFile)) { + return $default; + } + + $envContent = file_get_contents($envFile); + $lines = explode("\n", $envContent); + + foreach ($lines as $line) { + $line = trim($line); + + // 跳过注释和空行 + if (empty($line) || str_starts_with($line, '#')) { + continue; + } + + // 解析 KEY=VALUE + if (str_contains($line, '=')) { + [$envKey, $envValue] = explode('=', $line, 2); + $envKey = trim($envKey); + + if ($envKey === $key) { + $envValue = trim($envValue); + + // 移除引号 + if (preg_match('/^(["\'])(.*)\1$/', $envValue, $matches)) { + $envValue = $matches[2]; + } + + // 处理布尔值 + $lowerValue = strtolower($envValue); + if ($lowerValue === 'true') { + return true; + } + if ($lowerValue === 'false') { + return false; + } + if ($lowerValue === 'null' || $lowerValue === '(null)') { + return null; + } + + return $envValue; + } + } + } + + return $default; + } } diff --git a/cmd b/cmd index 2d1ba4ae1..3326e4616 100755 --- a/cmd +++ b/cmd @@ -119,6 +119,14 @@ switch_debug() { fi } +# 检查是否有sudo +check_sudo() { + if [ "$EUID" -ne 0 ]; then + error "请使用 sudo 运行此脚本" + exit 1 + fi +} + # 检查docker、docker-compose check_docker() { docker --version &> /dev/null @@ -175,7 +183,15 @@ web_build() { fi if [ "$type" = "dev" ]; then echo "" > ./index.html - env_set APP_DEV_PORT $(rand 20001 30000) + if [ -z "$(env_get APP_DEV_PORT)" ]; then + env_set APP_DEV_PORT $(rand 20001 30000) + fi + if [ -n "${VSCODE_PROXY_URI:-}" ]; then + APP_REAL_URI=$(TARGET_PORT="$(env_get APP_PORT)" node -p "process.env.VSCODE_PROXY_URI.replace(/\{\{port\}\}/g, process.env.TARGET_PORT || '')") + VSCODE_PROXY_URI=$(APP_DEV_PORT="$(env_get APP_DEV_PORT)" node -p "process.env.VSCODE_PROXY_URI.replace(/\{\{port\}\}/g, process.env.APP_DEV_PORT || '')") + echo "" > ./index.html + fi + env_set VSCODE_PROXY_URI "${VSCODE_PROXY_URI:-}" fi switch_debug "$type" # @@ -479,7 +495,8 @@ handle_install() { for vol in "${volumes[@]}"; do tmp_path="${WORK_DIR}/${vol}" mkdir -p "${tmp_path}" - chmod -R 775 "${tmp_path}" + find "${tmp_path}" -type d -exec chmod 775 {} \; + rm -f "${tmp_path}/dootask.lock" cmda="${cmda} -v ${tmp_path}:/usr/share/${vol}" cmdb="${cmdb} touch /usr/share/${vol}/dootask.lock &&" @@ -644,6 +661,7 @@ handle_update() { # 卸载函数 handle_uninstall() { + check_sudo # 确认卸载 echo -e "${RedBG}警告:此操作将永久删除以下内容:${Font}" echo "- 数据库" diff --git a/electron/index.html b/electron/index.html index cbe3fb960..2429a761b 100644 --- a/electron/index.html +++ b/electron/index.html @@ -18,7 +18,7 @@ -
+
PAGE LOADING
diff --git a/index.html b/index.html deleted file mode 100644 index a89f456f4..000000000 --- a/index.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 1b124b78c..cbfaa7961 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -2,6 +2,8 @@ const isElectron = !!(window && window.process && window.process.type && window. const isEEUIApp = window && window.navigator && /eeui/i.test(window.navigator.userAgent); const isSoftware = isElectron || isEEUIApp; +document.getElementById("app")?.setAttribute("data-preload", "false"); + import {languageName, switchLanguage as $L} from "./language"; import {isLocalHost} from "./components/Replace/utils"; diff --git a/resources/views/main.blade.php b/resources/views/main.blade.php index f61dd20bd..5134c300b 100755 --- a/resources/views/main.blade.php +++ b/resources/views/main.blade.php @@ -34,7 +34,7 @@ @extends('ie') -
+
PAGE LOADING
diff --git a/vite.config.js b/vite.config.js index ebfdb31d1..a89b2b2c3 100644 --- a/vite.config.js +++ b/vite.config.js @@ -22,6 +22,7 @@ export default defineConfig(({command, mode}) => { const env = loadEnv(mode, process.cwd(), '') const host = "0.0.0.0" const port = parseInt(env['APP_DEV_PORT']) + const proxy_uri = env['VSCODE_PROXY_URI'] if (command === 'serve') { const hotFile = path.resolve(__dirname, 'public/hot') @@ -80,6 +81,17 @@ export default defineConfig(({command, mode}) => { }) } + const serverHmr = {} + if (/^https?:\/\//i.test(proxy_uri)) { + const proxyUri = new URL(proxy_uri) + if (proxyUri) { + Object.assign(serverHmr, { + host: proxyUri.host, + clientPort: proxyUri.port || (/^https/.test(proxy_uri) ? 443 : 80) + }) + } + } + return { base: basePath, publicDir: publicPath, @@ -98,7 +110,8 @@ export default defineConfig(({command, mode}) => { '**/language/**', '**/electron/**', ] - } + }, + hmr: serverHmr }, resolve: { alias: {