mirror of
https://github.com/yaklang/yaklang-chrome-extension.git
synced 2026-09-26 21:21:53 +08:00
ui v0.0.1-beta
This commit is contained in:
@@ -52,6 +52,61 @@ async function handleSetProxyConfig(config, sendResponse) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加系统代理的处理
|
||||||
|
if (config.proxyType === 'system') {
|
||||||
|
try {
|
||||||
|
// 先清除当前的代理设置
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
chrome.proxy.settings.clear({
|
||||||
|
scope: 'regular'
|
||||||
|
}, resolve);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 然后设置为系统代理
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
chrome.proxy.settings.set({
|
||||||
|
value: {mode: "system"},
|
||||||
|
scope: 'regular'
|
||||||
|
}, resolve);
|
||||||
|
});
|
||||||
|
|
||||||
|
const settings = await getProxySettings();
|
||||||
|
const isSuccess = settings.value.mode === "system";
|
||||||
|
|
||||||
|
if (isSuccess) {
|
||||||
|
// 更新存储
|
||||||
|
await proxyStore.setCurrentProxy({
|
||||||
|
...config,
|
||||||
|
timestamp: Date.now()
|
||||||
|
});
|
||||||
|
|
||||||
|
// 更新代理列表状态
|
||||||
|
const configs = await proxyStore.getProxyConfigs();
|
||||||
|
const updatedConfigs = configs.map(c => ({
|
||||||
|
...c,
|
||||||
|
enabled: c.id === config.id
|
||||||
|
}));
|
||||||
|
await proxyStore.saveProxyConfigs(updatedConfigs);
|
||||||
|
|
||||||
|
console.log('System proxy set successfully');
|
||||||
|
sendResponse({success: true});
|
||||||
|
} else {
|
||||||
|
console.error('Failed to set system proxy');
|
||||||
|
sendResponse({
|
||||||
|
success: false,
|
||||||
|
error: '无法设置系统代理'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error setting system proxy:', error);
|
||||||
|
sendResponse({
|
||||||
|
success: false,
|
||||||
|
error: error.message || '设置系统代理时发生错误'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 处理代理服务器的情况
|
// 处理代理服务器的情况
|
||||||
if (!config || !config.host || !config.port) {
|
if (!config || !config.host || !config.port) {
|
||||||
sendResponse({
|
sendResponse({
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ const FIXED_MODES = [
|
|||||||
config: {
|
config: {
|
||||||
id: 'direct',
|
id: 'direct',
|
||||||
name: '[直接连接]',
|
name: '[直接连接]',
|
||||||
proxyType: 'direct'
|
proxyType: 'direct',
|
||||||
|
enabled: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -27,7 +28,8 @@ const FIXED_MODES = [
|
|||||||
config: {
|
config: {
|
||||||
id: 'system',
|
id: 'system',
|
||||||
name: '[系统代理]',
|
name: '[系统代理]',
|
||||||
proxyType: 'system'
|
proxyType: 'system',
|
||||||
|
enabled: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
+2
-6
@@ -9,9 +9,5 @@ if (!container) throw new Error('Failed to find the root element');
|
|||||||
// 创建根
|
// 创建根
|
||||||
const root = createRoot(container);
|
const root = createRoot(container);
|
||||||
|
|
||||||
// 渲染应用
|
// 渲染应用,移除 StrictMode
|
||||||
root.render(
|
root.render(<App />);
|
||||||
<React.StrictMode>
|
|
||||||
<App />
|
|
||||||
</React.StrictMode>
|
|
||||||
);
|
|
||||||
+1
-1
@@ -2,7 +2,7 @@ export interface ProxyConfig {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
proxyType: "direct" | "fixed_server" | "pac_script" | "auto_detect" | "bypass_list";
|
proxyType: "direct" | "system" | "fixed_servers" | "pac_script" | "auto_detect";
|
||||||
host?: string;
|
host?: string;
|
||||||
port?: number;
|
port?: number;
|
||||||
scheme?: "http" | "https" | "socks4" | "socks5";
|
scheme?: "http" | "https" | "socks4" | "socks5";
|
||||||
|
|||||||
Reference in New Issue
Block a user