Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat: add proxy settings for editor update downloads

esengineb2e86f9f5cf5
diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs
index 65573e396..73410178a 100644
--- a/desktop/src-tauri/src/lib.rs
+++ b/desktop/src-tauri/src/lib.rs
@@ -213,10 +213,14 @@ async fn execute_command(
// Update (proxy-aware)
// =============================================================================
-fn get_proxy_url() -> Option<url::Url> {
- ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy"]
- .iter()
- .find_map(|key| std::env::var(key).ok())
+fn resolve_proxy(explicit: Option<String>) -> Option<url::Url> {
+ explicit
+ .filter(|s| !s.is_empty())
+ .or_else(|| {
+ ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy"]
+ .iter()
+ .find_map(|key| std::env::var(key).ok())
+ })
.and_then(|s| url::Url::parse(&s).ok())
}
@@ -227,10 +231,10 @@ struct UpdateInfo {
}
#[tauri::command]
-async fn check_update(app: AppHandle) -> Result<Option<UpdateInfo>, String> {
+async fn check_update(app: AppHandle, proxy: Option<String>) -> Result<Option<UpdateInfo>, String> {
let mut builder = app.updater_builder();
- if let Some(proxy) = get_proxy_url() {
- builder = builder.proxy(proxy);
+ if let Some(proxy_url) = resolve_proxy(proxy) {
+ builder = builder.proxy(proxy_url);
}
let updater = builder.build().map_err(|e| e.to_string())?;
match updater.check().await {
@@ -244,10 +248,10 @@ async fn check_update(app: AppHandle) -> Result<Option<UpdateInfo>, String> {
}
#[tauri::command]
-async fn install_update(app: AppHandle) -> Result<(), String> {
+async fn install_update(app: AppHandle, proxy: Option<String>) -> Result<(), String> {
let mut builder = app.updater_builder();
- if let Some(proxy) = get_proxy_url() {
- builder = builder.proxy(proxy);
+ if let Some(proxy_url) = resolve_proxy(proxy) {
+ builder = builder.proxy(proxy_url);
}
let updater = builder.build().map_err(|e| e.to_string())?;
let update = updater
diff --git a/desktop/src-tauri/tauri.conf.json b/desktop/src-tauri/tauri.conf.json
index a0ccd9541..2ec0c12c1 100644
--- a/desktop/src-tauri/tauri.conf.json
+++ b/desktop/src-tauri/tauri.conf.json
@@ -23,7 +23,7 @@
}
],
"security": {
- "csp": "default-src 'self' asset: http://asset.localhost ipc: http://ipc.localhost; connect-src 'self' blob:; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval' 'unsafe-eval' blob:; img-src 'self' asset: http://asset.localhost data:; style-src 'self' 'unsafe-inline'",
+ "csp": "default-src 'self' asset: http://asset.localhost ipc: http://ipc.localhost; connect-src 'self' blob: http://127.0.0.1:* http://localhost:*; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval' 'unsafe-eval' blob:; img-src 'self' asset: http://asset.localhost data:; style-src 'self' 'unsafe-inline'",
"dangerousDisableAssetCspModification": [
"style-src"
],
diff --git a/desktop/src/main.ts b/desktop/src/main.ts
index 80e6d0ac6..450d1e18d 100644
--- a/desktop/src/main.ts
+++ b/desktop/src/main.ts
@@ -5,7 +5,7 @@
import 'dockview-core/dist/styles/dockview.css';
import '@esengine/editor/styles';
-import { createEditor, ProjectLauncher, setPlatformAdapter, setEditorContext, loadProjectConfig, showToast, dismissToast, showProgressToast, updateToast, type Editor } from '@esengine/editor';
+import { createEditor, ProjectLauncher, setPlatformAdapter, setEditorContext, loadProjectConfig, showToast, dismissToast, showProgressToast, updateToast, getSettingsValue, type Editor } from '@esengine/editor';
import { TauriPlatformAdapter } from './TauriPlatformAdapter';
import { nativeFS, nativeShell } from './native-fs';
import { invoke } from '@tauri-apps/api/core';
@@ -141,7 +141,8 @@ async function checkForUpdate(manual = false): Promise<void> {
}
try {
- const update = await invoke<{ version: string; body: string | null } | null>('check_update');
+ const proxy = getSettingsValue<string>('network.proxy') || undefined;
+ const update = await invoke<{ version: string; body: string | null } | null>('check_update', { proxy });
if (!update) {
if (tid) {
updateToast(tid, { type: 'success', title: 'You\'re up to date', message: 'No updates available.' });
@@ -163,7 +164,8 @@ async function checkForUpdate(manual = false): Promise<void> {
onClick: async () => {
const dlTid = showProgressToast('Downloading update...');
try {
- await invoke('install_update');
+ const installProxy = getSettingsValue<string>('network.proxy') || undefined;
+ await invoke('install_update', { proxy: installProxy });
updateToast(dlTid, { type: 'success', title: 'Update complete', message: 'Restarting...' });
setTimeout(() => relaunch(), 1000);
} catch (e) {
diff --git a/editor/src/settings/builtinSettings.ts b/editor/src/settings/builtinSettings.ts
index 9d773a80c..3044c0fb7 100644
--- a/editor/src/settings/builtinSettings.ts
+++ b/editor/src/settings/builtinSettings.ts
@@ -38,6 +38,12 @@ export function registerBuiltinSettings(): void {
order: 5,
});
+ registerSettingsSection({
+ id: 'network',
+ title: 'Network',
+ order: 6,
+ });
+
registerSettingsItem({
id: 'project.name',
section: 'project',
@@ -389,4 +395,14 @@ export function registerBuiltinSettings(): void {
{ label: '2048', value: '2048' },
],
});
+
+ registerSettingsItem({
+ id: 'network.proxy',
+ section: 'network',
+ label: 'HTTP Proxy',
+ description: 'Proxy for update downloads (e.g. http://127.0.0.1:7890)',
+ type: 'string',
+ defaultValue: '',
+ order: 0,
+ });
}