Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5dfb34082 | ||
|
|
2ba5c4e706 | ||
|
|
27bcc5f4f8 | ||
|
|
d884bd539b | ||
|
|
580a56727c | ||
|
|
ac3163d061 | ||
|
|
8bc7a6c3e1 | ||
|
|
31d368979e |
91
.github/workflows/release.yml
vendored
91
.github/workflows/release.yml
vendored
@@ -106,7 +106,6 @@ jobs:
|
||||
with:
|
||||
tagName: v__VERSION__
|
||||
releaseName: "Clash Verge Rev Lite v__VERSION__"
|
||||
releaseBody: "More new features are now supported."
|
||||
tauriScript: pnpm
|
||||
args: --target ${{ matrix.target }}
|
||||
|
||||
@@ -219,14 +218,13 @@ jobs:
|
||||
sudo apt-get update
|
||||
sudo apt-get install jq
|
||||
echo "VERSION=$(cat package.json | jq '.version' | tr -d '"')" >> $GITHUB_ENV
|
||||
echo "BUILDTIME=$(TZ=Asia/Shanghai date)" >> $GITHUB_ENV
|
||||
echo "BUILDTIME=$(TZ=Europe/Moscow date)" >> $GITHUB_ENV
|
||||
|
||||
- name: Upload Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: v${{env.VERSION}}
|
||||
name: "Clash Verge Rev Lite v${{env.VERSION}}"
|
||||
body: "More new features are now supported."
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
files: |
|
||||
src-tauri/target/${{ matrix.target }}/release/bundle/deb/*.deb
|
||||
@@ -275,8 +273,8 @@ jobs:
|
||||
|
||||
- name: Download WebView2 Runtime
|
||||
run: |
|
||||
invoke-webrequest -uri https://github.com/westinyang/WebView2RuntimeArchive/releases/download/109.0.1518.78/Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.${{ matrix.arch }}.cab -outfile Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.${{ matrix.arch }}.cab
|
||||
Expand .\Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.${{ matrix.arch }}.cab -F:* ./src-tauri
|
||||
invoke-webrequest -uri https://github.com/westinyang/WebView2RuntimeArchive/releases/download/133.0.3065.92/Microsoft.WebView2.FixedVersionRuntime.133.0.3065.92.${{ matrix.arch }}.cab -outfile Microsoft.WebView2.FixedVersionRuntime.133.0.3065.92.${{ matrix.arch }}.cab
|
||||
Expand .\Microsoft.WebView2.FixedVersionRuntime.133.0.3065.92.${{ matrix.arch }}.cab -F:* ./src-tauri
|
||||
Remove-Item .\src-tauri\tauri.windows.conf.json
|
||||
Rename-Item .\src-tauri\webview2.${{ matrix.arch }}.json tauri.windows.conf.json
|
||||
|
||||
@@ -317,7 +315,6 @@ jobs:
|
||||
with:
|
||||
tag_name: v${{steps.build.outputs.appVersion}}
|
||||
name: "Clash Verge Rev Lite v${{steps.build.outputs.appVersion}}"
|
||||
body: "More new features are now supported."
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
files: src-tauri/target/${{ matrix.target }}/release/bundle/nsis/*setup*
|
||||
|
||||
@@ -376,3 +373,85 @@ jobs:
|
||||
run: pnpm updater-fixed-webview2
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
create_release_notes:
|
||||
name: Create Release Notes
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Fetch UPDATE logs
|
||||
id: fetch_update_logs
|
||||
run: |
|
||||
if [ -f "UPDATELOG.md" ]; then
|
||||
UPDATE_LOGS=$(awk '/^## v/{if(flag) exit; flag=1} flag' UPDATELOG.md)
|
||||
if [ -n "$UPDATE_LOGS" ]; then
|
||||
echo "Found update logs"
|
||||
echo "UPDATE_LOGS<<EOF" >> $GITHUB_ENV
|
||||
echo "$UPDATE_LOGS" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
else
|
||||
echo "No update sections found in UPDATELOG.md"
|
||||
fi
|
||||
else
|
||||
echo "UPDATELOG.md file not found"
|
||||
fi
|
||||
shell: bash
|
||||
|
||||
- name: Get Version
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install jq
|
||||
echo "VERSION=$(cat package.json | jq '.version' | tr -d '"')" >> $GITHUB_ENV
|
||||
echo "BUILDTIME=$(TZ=Europe/Moscow date)" >> $GITHUB_ENV
|
||||
|
||||
- run: |
|
||||
if [ -z "$UPDATE_LOGS" ]; then
|
||||
echo "No update logs found, using default message"
|
||||
UPDATE_LOGS="More new features are now supported. Check for detailed changelog soon."
|
||||
else
|
||||
echo "Using found update logs"
|
||||
fi
|
||||
|
||||
cat > release.txt << EOF
|
||||
$UPDATE_LOGS
|
||||
|
||||
## Which version should I download?
|
||||
|
||||
### macOS
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite_${{ env.VERSION }}_aarch64.dmg"><img src="https://img.shields.io/badge/DMG-default?style=flat&logo=apple&label=Apple%20Silicon"></a><br>
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite_${{ env.VERSION }}_x64.dmg"><img src="https://img.shields.io/badge/DMG-default?style=flat&logo=apple&label=Intel"></a><br>
|
||||
> :warning: **Warning**
|
||||
If you get a notification that the application is corrupted when you run it on macOS, run this command:<br>
|
||||
`sudo xattr -r -c /Applications/Clash\ Verge\ Rev\ Lite.app`
|
||||
|
||||
### Linux
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite_${{ env.VERSION }}_amd64.deb"><img src="https://img.shields.io/badge/x64-default?style=flat&logo=debian&label=DEB"> </a><br>
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite-${{ env.VERSION }}-1.x86_64.rpm"><img src="https://img.shields.io/badge/x64-default?style=flat&logo=fedora&label=RPM"> </a>
|
||||
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite_${{ env.VERSION }}_arm64.deb"><img src="https://img.shields.io/badge/arm64-default?style=flat&logo=debian&label=DEB"> </a><br>
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite-${{ env.VERSION }}-1.aarch64.rpm"><img src="https://img.shields.io/badge/aarch64-default?style=flat&logo=fedora&label=RPM"> </a>
|
||||
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite_${{ env.VERSION }}_armhf.deb"><img src="https://img.shields.io/badge/armhf-default?style=flat&logo=debian&label=DEB"> </a><br>
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite-${{ env.VERSION }}-1.armhfp.rpm"><img src="https://img.shields.io/badge/armhfp-default?style=flat&logo=fedora&label=RPM"> </a>
|
||||
|
||||
### Windows (Win7 is no longer supported)
|
||||
#### Normal version (recommended)
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite_${{ env.VERSION }}_x64-setup.exe"><img src="https://badgen.net/badge/icon/x64?icon=windows&label=exe"></a><br>
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite_${{ env.VERSION }}_arm64-setup.exe"><img src="https://badgen.net/badge/icon/arm64?icon=windows&label=exe"></a>
|
||||
#### Portable version is no longer available with many problems
|
||||
#### Built-in Webview version 2 (large size, only used in enterprise version of the system or can not install webview2)
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite_${{ env.VERSION }}_x64_fixed_webview2-setup.exe"><img src="https://badgen.net/badge/icon/x64?icon=windows&label=exe"></a><br>
|
||||
<a href="https://github.com/coolcoala/clash-verge-rev-lite/releases/download/v${{ env.VERSION }}/Clash.Verge.Rev.Lite_${{ env.VERSION }}_arm64_fixed_webview2-setup.exe"><img src="https://badgen.net/badge/icon/arm64?icon=windows&label=exe"></a>
|
||||
|
||||
Created at ${{ env.BUILDTIME }}.
|
||||
EOF
|
||||
|
||||
- name: Upload Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: v${{env.VERSION}}
|
||||
name: "Clash Verge Rev Lite v${{env.VERSION}}"
|
||||
body_path: release.txt
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
## v0.2.1
|
||||
|
||||
- added headers "announce-url", "update-always"
|
||||
- added a check for the presence of a profile, if it already exists, an update will be performed
|
||||
- fixed processing of links for displaying telegram icon on the main page
|
||||
- added profile update button on the main page
|
||||
|
||||
## v0.2
|
||||
|
||||
- added handlers for "Announe", "Support-Url", "New-Sub-Domain", "Profile-Title" headers:
|
||||
|
||||
19
hooks/use-mobile.ts
Normal file
19
hooks/use-mobile.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from "react"
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
|
||||
return !!isMobile
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "clash-verge",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.2",
|
||||
"license": "GPL-3.0-only",
|
||||
"scripts": {
|
||||
"dev": "cross-env RUST_BACKTRACE=1 tauri dev -f verge-dev",
|
||||
|
||||
@@ -49,9 +49,9 @@ async function resolvePortable() {
|
||||
zip.addLocalFolder(
|
||||
path.join(
|
||||
releaseDir,
|
||||
`Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.${arch}`,
|
||||
`Microsoft.WebView2.FixedVersionRuntime.133.0.3065.92.${arch}`,
|
||||
),
|
||||
`Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.${arch}`,
|
||||
`Microsoft.WebView2.FixedVersionRuntime.133.0.3065.92.${arch}`,
|
||||
);
|
||||
zip.addLocalFolder(configDir, ".config");
|
||||
|
||||
|
||||
2
src-tauri/Cargo.lock
generated
2
src-tauri/Cargo.lock
generated
@@ -1061,7 +1061,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clash-verge"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"ab_glyph",
|
||||
"aes-gcm",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "clash-verge"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
description = "clash verge"
|
||||
authors = ["zzzgydi", "wonfen", "MystiPanda", "coolcoala"]
|
||||
license = "GPL-3.0-only"
|
||||
|
||||
@@ -129,8 +129,24 @@ pub async fn enhance_profiles() -> CmdResult {
|
||||
/// 导入配置文件
|
||||
#[tauri::command]
|
||||
pub async fn import_profile(url: String, option: Option<PrfOption>) -> CmdResult {
|
||||
let item = wrap_err!(PrfItem::from_url(&url, None, None, option).await)?;
|
||||
wrap_err!(Config::profiles().data().append_item(item))
|
||||
let existing_uid = {
|
||||
let profiles = Config::profiles();
|
||||
let profiles = profiles.latest();
|
||||
|
||||
profiles.items.as_ref()
|
||||
.and_then(|items| items.iter().find(|item| item.url.as_deref() == Some(&url)))
|
||||
.and_then(|item| item.uid.clone())
|
||||
};
|
||||
|
||||
if let Some(uid) = existing_uid {
|
||||
logging!(info, Type::Cmd, true, "The profile with URL {} already exists (UID: {}). Running the update...", url, uid);
|
||||
update_profile(uid, option).await
|
||||
} else {
|
||||
logging!(info, Type::Cmd, true, "Profile with URL {} not found. Create a new one...", url);
|
||||
let item = wrap_err!(PrfItem::from_url(&url, None, None, option).await)?;
|
||||
wrap_err!(Config::profiles().data().append_item(item))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// 重新排序配置文件
|
||||
@@ -647,3 +663,48 @@ pub fn get_next_update_time(uid: String) -> CmdResult<Option<i64>> {
|
||||
let next_time = timer.get_next_update_time(&uid);
|
||||
Ok(next_time)
|
||||
}
|
||||
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn update_profiles_on_startup() -> CmdResult {
|
||||
logging!(info, Type::Cmd, true, "Checking profiles for updates at startup...");
|
||||
|
||||
let profiles_to_update = {
|
||||
let profiles = Config::profiles();
|
||||
let profiles = profiles.latest();
|
||||
|
||||
profiles.items.as_ref()
|
||||
.map_or_else(
|
||||
Vec::new,
|
||||
|items| items.iter()
|
||||
.filter(|item| item.option.as_ref().is_some_and(|opt| opt.update_always == Some(true)))
|
||||
.filter_map(|item| item.uid.clone())
|
||||
.collect()
|
||||
)
|
||||
};
|
||||
|
||||
if profiles_to_update.is_empty() {
|
||||
logging!(info, Type::Cmd, true, "No profiles to update immediately.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
logging!(info, Type::Cmd, true, "Found profiles to update: {:?}", profiles_to_update);
|
||||
|
||||
let mut update_futures = Vec::new();
|
||||
for uid in profiles_to_update {
|
||||
update_futures.push(update_profile(uid, None));
|
||||
}
|
||||
|
||||
let results = futures::future::join_all(update_futures).await;
|
||||
|
||||
|
||||
if results.iter().any(|res| res.is_ok()) {
|
||||
logging!(info, Type::Cmd, true, "The startup update is complete, restart the kernel...");
|
||||
CoreManager::global().update_config().await.map_err(|e| e.to_string())?;
|
||||
handle::Handle::refresh_clash();
|
||||
} else {
|
||||
logging!(warn, Type::Cmd, true, "All updates completed with errors on startup.");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -63,6 +63,10 @@ pub struct PrfItem {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub announce: Option<String>,
|
||||
|
||||
/// profile announce url
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub announce_url: Option<String>,
|
||||
|
||||
/// the file data
|
||||
#[serde(skip)]
|
||||
pub file_data: Option<String>,
|
||||
@@ -126,6 +130,9 @@ pub struct PrfOption {
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub use_hwid: Option<bool>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub update_always: Option<bool>,
|
||||
}
|
||||
|
||||
impl PrfOption {
|
||||
@@ -146,6 +153,7 @@ impl PrfOption {
|
||||
a.groups = b.groups.or(a.groups);
|
||||
a.timeout_seconds = b.timeout_seconds.or(a.timeout_seconds);
|
||||
a.use_hwid = b.use_hwid.or(a.use_hwid);
|
||||
a.update_always = b.update_always.or(a.update_always);
|
||||
Some(a)
|
||||
}
|
||||
t => t.0.or(t.1),
|
||||
@@ -246,6 +254,7 @@ impl PrfItem {
|
||||
home: None,
|
||||
support_url: None,
|
||||
announce: None,
|
||||
announce_url: None,
|
||||
updated: Some(chrono::Local::now().timestamp() as usize),
|
||||
file_data: Some(file_data.unwrap_or(tmpl::ITEM_LOCAL.into())),
|
||||
})
|
||||
@@ -267,7 +276,7 @@ impl PrfItem {
|
||||
let user_agent = opt_ref.and_then(|o| o.user_agent.clone());
|
||||
let update_interval = opt_ref.and_then(|o| o.update_interval);
|
||||
let timeout = opt_ref.and_then(|o| o.timeout_seconds).unwrap_or(20);
|
||||
let use_hwid = opt_ref.is_some_and(|o| o.use_hwid.unwrap_or(true));
|
||||
let use_hwid = Config::verge().latest().enable_send_hwid.unwrap_or(true);
|
||||
let mut merge = opt_ref.and_then(|o| o.merge.clone());
|
||||
let mut script = opt_ref.and_then(|o| o.script.clone());
|
||||
let mut rules = opt_ref.and_then(|o| o.rules.clone());
|
||||
@@ -373,6 +382,11 @@ impl PrfItem {
|
||||
},
|
||||
};
|
||||
|
||||
let update_always = match header.get("update-always") {
|
||||
Some(value) => value.to_str().unwrap_or("false").parse::<bool>().ok(),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let home = match header.get("profile-web-page-url") {
|
||||
Some(value) => {
|
||||
let str_value = value.to_str().unwrap_or("");
|
||||
@@ -403,6 +417,14 @@ impl PrfItem {
|
||||
None => None,
|
||||
};
|
||||
|
||||
let announce_url = match header.get("announce-url") {
|
||||
Some(value) => {
|
||||
let str_value = value.to_str().unwrap_or("");
|
||||
Some(str_value.to_string())
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
let profile_title = match header.get("profile-title") {
|
||||
Some(value) => {
|
||||
let str_value = value.to_str().unwrap_or("");
|
||||
@@ -472,6 +494,7 @@ impl PrfItem {
|
||||
extra,
|
||||
option: Some(PrfOption {
|
||||
update_interval,
|
||||
update_always,
|
||||
merge,
|
||||
script,
|
||||
rules,
|
||||
@@ -482,6 +505,7 @@ impl PrfItem {
|
||||
home,
|
||||
support_url,
|
||||
announce,
|
||||
announce_url,
|
||||
updated: Some(chrono::Local::now().timestamp() as usize),
|
||||
file_data: Some(data.into()),
|
||||
})
|
||||
@@ -511,6 +535,7 @@ impl PrfItem {
|
||||
home: None,
|
||||
support_url: None,
|
||||
announce: None,
|
||||
announce_url: None,
|
||||
updated: Some(chrono::Local::now().timestamp() as usize),
|
||||
file_data: Some(template),
|
||||
})
|
||||
@@ -535,6 +560,7 @@ impl PrfItem {
|
||||
home: None,
|
||||
support_url: None,
|
||||
announce: None,
|
||||
announce_url: None,
|
||||
selected: None,
|
||||
extra: None,
|
||||
option: None,
|
||||
@@ -558,6 +584,7 @@ impl PrfItem {
|
||||
home: None,
|
||||
support_url: None,
|
||||
announce: None,
|
||||
announce_url: None,
|
||||
selected: None,
|
||||
extra: None,
|
||||
option: None,
|
||||
@@ -581,6 +608,7 @@ impl PrfItem {
|
||||
home: None,
|
||||
support_url: None,
|
||||
announce: None,
|
||||
announce_url: None,
|
||||
selected: None,
|
||||
extra: None,
|
||||
option: None,
|
||||
@@ -604,6 +632,7 @@ impl PrfItem {
|
||||
home: None,
|
||||
support_url: None,
|
||||
announce: None,
|
||||
announce_url: None,
|
||||
selected: None,
|
||||
extra: None,
|
||||
option: None,
|
||||
|
||||
@@ -221,6 +221,7 @@ impl IProfiles {
|
||||
each.updated = item.updated;
|
||||
each.home = item.home;
|
||||
each.announce = item.announce;
|
||||
each.announce_url = item.announce_url;
|
||||
each.support_url = item.support_url;
|
||||
each.name = item.name;
|
||||
each.url = item.url;
|
||||
|
||||
@@ -74,6 +74,8 @@ pub struct IVerge {
|
||||
/// enable dns settings - this controls whether dns_config.yaml is applied
|
||||
pub enable_dns_settings: Option<bool>,
|
||||
|
||||
pub enable_send_hwid: Option<bool>,
|
||||
|
||||
pub primary_action: Option<String>,
|
||||
|
||||
/// always use default bypass
|
||||
@@ -403,6 +405,7 @@ impl IVerge {
|
||||
enable_auto_light_weight_mode: Some(false),
|
||||
auto_light_weight_minutes: Some(10),
|
||||
enable_dns_settings: Some(false),
|
||||
enable_send_hwid: Some(true),
|
||||
primary_action: Some("tun-mode".into()),
|
||||
home_cards: None,
|
||||
service_state: None,
|
||||
@@ -492,6 +495,7 @@ impl IVerge {
|
||||
patch!(enable_auto_light_weight_mode);
|
||||
patch!(auto_light_weight_minutes);
|
||||
patch!(enable_dns_settings);
|
||||
patch!(enable_send_hwid);
|
||||
patch!(primary_action);
|
||||
patch!(home_cards);
|
||||
patch!(service_state);
|
||||
@@ -588,6 +592,7 @@ pub struct IVergeResponse {
|
||||
pub enable_auto_light_weight_mode: Option<bool>,
|
||||
pub auto_light_weight_minutes: Option<u64>,
|
||||
pub enable_dns_settings: Option<bool>,
|
||||
pub enable_send_hwid: Option<bool>,
|
||||
pub primary_action: Option<String>,
|
||||
pub home_cards: Option<serde_json::Value>,
|
||||
pub enable_hover_jump_navigator: Option<bool>,
|
||||
@@ -661,6 +666,7 @@ impl From<IVerge> for IVergeResponse {
|
||||
enable_auto_light_weight_mode: verge.enable_auto_light_weight_mode,
|
||||
auto_light_weight_minutes: verge.auto_light_weight_minutes,
|
||||
enable_dns_settings: verge.enable_dns_settings,
|
||||
enable_send_hwid: verge.enable_send_hwid,
|
||||
primary_action: verge.primary_action,
|
||||
home_cards: verge.home_cards,
|
||||
enable_hover_jump_navigator: verge.enable_hover_jump_navigator,
|
||||
|
||||
@@ -216,6 +216,14 @@ pub fn run() {
|
||||
app.manage(Mutex::new(state::proxy::CmdProxyState::default()));
|
||||
app.manage(Mutex::new(state::lightweight::LightWeightState::default()));
|
||||
|
||||
tauri::async_runtime::spawn(async {
|
||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||
logging!(info, Type::Cmd, true, "Running profile updates at startup...");
|
||||
if let Err(e) = crate::cmd::update_profiles_on_startup().await {
|
||||
log::error!("Failed to update profiles on startup: {}", e);
|
||||
}
|
||||
});
|
||||
|
||||
logging!(info, Type::Setup, true, "初始化完成,继续执行");
|
||||
Ok(())
|
||||
})
|
||||
@@ -295,6 +303,7 @@ pub fn run() {
|
||||
cmd::read_profile_file,
|
||||
cmd::save_profile_file,
|
||||
cmd::get_next_update_time,
|
||||
cmd::update_profiles_on_startup,
|
||||
// script validation
|
||||
cmd::script_validate_notice,
|
||||
cmd::validate_script_file,
|
||||
|
||||
@@ -552,33 +552,21 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
|
||||
if link_parsed.scheme() == "clash" || link_parsed.scheme() == "clash-verge" {
|
||||
let mut name: Option<String> = None;
|
||||
let mut url_param: Option<String> = None;
|
||||
let mut use_hwid = true;
|
||||
|
||||
for (key, value) in link_parsed.query_pairs() {
|
||||
match key.as_ref() {
|
||||
"name" => name = Some(value.into_owned()),
|
||||
"url" => url_param = Some(percent_decode_str(&value).decode_utf8_lossy().to_string()),
|
||||
"hwid" => use_hwid = value == "1" || value == "true",
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
let option = if use_hwid {
|
||||
log::info!(target:"app", "HWID usage requested via deep link");
|
||||
Some(PrfOption {
|
||||
use_hwid: Some(true),
|
||||
..Default::default()
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
match url_param {
|
||||
Some(url) => {
|
||||
log::info!(target:"app", "decoded subscription url: {url}");
|
||||
|
||||
create_window(false);
|
||||
match PrfItem::from_url(url.as_ref(), name, None, option).await {
|
||||
match PrfItem::from_url(url.as_ref(), name, None, None).await {
|
||||
Ok(item) => {
|
||||
let uid = item.uid.clone().unwrap();
|
||||
let _ = wrap_err!(Config::profiles().data().append_item(item));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.2",
|
||||
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
||||
"bundle": {
|
||||
"active": true,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"timestampUrl": "",
|
||||
"webviewInstallMode": {
|
||||
"type": "fixedRuntime",
|
||||
"path": "./Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.arm64/"
|
||||
"path": "./Microsoft.WebView2.FixedVersionRuntime.133.0.3065.92.arm64/"
|
||||
},
|
||||
"nsis": {
|
||||
"displayLanguageSelector": true,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"timestampUrl": "",
|
||||
"webviewInstallMode": {
|
||||
"type": "fixedRuntime",
|
||||
"path": "./Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.x64/"
|
||||
"path": "./Microsoft.WebView2.FixedVersionRuntime.133.0.3065.92.x64/"
|
||||
},
|
||||
"nsis": {
|
||||
"displayLanguageSelector": true,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"timestampUrl": "",
|
||||
"webviewInstallMode": {
|
||||
"type": "fixedRuntime",
|
||||
"path": "./Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.x86/"
|
||||
"path": "./Microsoft.WebView2.FixedVersionRuntime.133.0.3065.92.x86/"
|
||||
},
|
||||
"nsis": {
|
||||
"displayLanguageSelector": true,
|
||||
|
||||
86
src/components/layout/sidebar.tsx
Normal file
86
src/components/layout/sidebar.tsx
Normal file
@@ -0,0 +1,86 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import {
|
||||
Sidebar,
|
||||
SidebarContent, SidebarFooter,
|
||||
SidebarGroup,
|
||||
SidebarGroupContent,
|
||||
SidebarHeader,
|
||||
SidebarMenu,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
} from "@/components/ui/sidebar"
|
||||
import { t } from 'i18next';
|
||||
import { cn } from '@root/lib/utils';
|
||||
|
||||
import {
|
||||
Home,
|
||||
Users,
|
||||
Server,
|
||||
Cable,
|
||||
ListChecks,
|
||||
FileText,
|
||||
Settings, EarthLock,
|
||||
} from 'lucide-react';
|
||||
import { UpdateButton } from "@/components/layout/update-button";
|
||||
import React from "react";
|
||||
|
||||
const menuItems = [
|
||||
{ title: 'Home', url: '/home', icon: Home },
|
||||
{ title: 'Profiles', url: '/profile', icon: Users },
|
||||
{ title: 'Proxies', url: '/proxies', icon: Server },
|
||||
{ title: 'Connections', url: '/connections', icon: Cable },
|
||||
{ title: 'Rules', url: '/rules', icon: ListChecks },
|
||||
{ title: 'Logs', url: '/logs', icon: FileText },
|
||||
{ title: 'Settings', url: '/settings', icon: Settings },
|
||||
];
|
||||
|
||||
export function AppSidebar() {
|
||||
return (
|
||||
<Sidebar variant="floating" collapsible="icon">
|
||||
<SidebarHeader>
|
||||
<SidebarMenuButton>
|
||||
<EarthLock/>
|
||||
<span className="font-semibold group-data-[state=collapsed]:hidden">
|
||||
Clash Koala
|
||||
</span>
|
||||
</SidebarMenuButton>
|
||||
</SidebarHeader>
|
||||
<SidebarContent>
|
||||
<SidebarGroup>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu className="gap-3">
|
||||
{menuItems.map((item) => {
|
||||
const isActive = location.pathname === item.url;
|
||||
return (
|
||||
<SidebarMenuItem key={item.title} className="my-1">
|
||||
<SidebarMenuButton
|
||||
asChild
|
||||
isActive={isActive}
|
||||
tooltip={t(item.title)}>
|
||||
<Link
|
||||
key={item.title}
|
||||
to={item.url}
|
||||
className={cn(
|
||||
'flex items-center gap-3 rounded-lg px-3 py-2 text-muted-foreground transition-all hover:text-primary',
|
||||
'data-[active=true]:font-semibold data-[active=true]:border'
|
||||
)}
|
||||
>
|
||||
<item.icon className="h-4 w-4 drop-shadow-md" />
|
||||
{t(item.title)}
|
||||
</Link>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
)
|
||||
})}
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
</SidebarContent>
|
||||
<SidebarFooter>
|
||||
<div className="w-full flex justify-center">
|
||||
<UpdateButton className="bg-green-700 hover:bg-green-500 hover:text-white text-white text-shadow-md" />
|
||||
</div>
|
||||
</SidebarFooter>
|
||||
</Sidebar>
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,9 @@ import { UpdateViewer } from "../setting/mods/update-viewer";
|
||||
import { DialogRef } from "../base";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { t } from "i18next";
|
||||
import {Download, RefreshCw} from "lucide-react";
|
||||
import { useSidebar } from "../ui/sidebar";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
@@ -14,6 +17,7 @@ export const UpdateButton = (props: Props) => {
|
||||
const { className } = props;
|
||||
const { verge } = useVerge();
|
||||
const { auto_check_update } = verge || {};
|
||||
const { state: sidebarState } = useSidebar();
|
||||
|
||||
const viewerRef = useRef<DialogRef>(null);
|
||||
|
||||
@@ -32,15 +36,26 @@ export const UpdateButton = (props: Props) => {
|
||||
return (
|
||||
<>
|
||||
<UpdateViewer ref={viewerRef} />
|
||||
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
className={className}
|
||||
onClick={() => viewerRef.current?.open()}
|
||||
>
|
||||
New
|
||||
</Button>
|
||||
{sidebarState === 'collapsed' ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className={className}
|
||||
onClick={() => viewerRef.current?.open()}
|
||||
>
|
||||
<Download />
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="lg"
|
||||
className={className}
|
||||
onClick={() => viewerRef.current?.open()}
|
||||
>
|
||||
<Download />
|
||||
{t("New update")}
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -447,6 +447,21 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={control}
|
||||
name="option.update_always"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-center justify-between">
|
||||
<FormLabel>{t("Update on Startup")}</FormLabel>
|
||||
<FormControl>
|
||||
<Switch
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={control}
|
||||
name="option.with_proxy"
|
||||
|
||||
@@ -118,7 +118,7 @@ export const UpdateViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogContent className="sm:max-w-2xl">
|
||||
<DialogHeader>
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="flex justify-between items-center pr-5">
|
||||
<DialogTitle>
|
||||
{t("New Version")} v{updateInfo?.version}
|
||||
</DialogTitle>
|
||||
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
Power,
|
||||
BellOff,
|
||||
Repeat,
|
||||
Fingerprint
|
||||
} from "lucide-react";
|
||||
|
||||
// Модальные окна
|
||||
@@ -390,6 +391,22 @@ const SettingSystem = ({ onError }: Props) => {
|
||||
</Select>
|
||||
</GuardState>
|
||||
</SettingRow>
|
||||
|
||||
<SettingRow
|
||||
label={<LabelWithIcon icon={Fingerprint} text={t("Send HWID")} />}
|
||||
>
|
||||
<GuardState
|
||||
value={verge?.enable_send_hwid ?? true} // По умолчанию включено
|
||||
valueProps="checked"
|
||||
onChangeProps="onCheckedChange"
|
||||
onFormat={onSwitchFormat}
|
||||
onChange={(e) => onChangeData({ enable_send_hwid: e })}
|
||||
onGuard={(e) => patchVerge({ enable_send_hwid: e })}
|
||||
onCatch={onError}
|
||||
>
|
||||
<Switch />
|
||||
</GuardState>
|
||||
</SettingRow>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
724
src/components/ui/sidebar.tsx
Normal file
724
src/components/ui/sidebar.tsx
Normal file
@@ -0,0 +1,724 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, VariantProps } from "class-variance-authority"
|
||||
import { PanelLeftIcon } from "lucide-react"
|
||||
|
||||
import { useIsMobile } from "@root/hooks/use-mobile"
|
||||
import { cn } from "@root/lib/utils"
|
||||
import { Button } from "@root/src/components/ui/button"
|
||||
import { Input } from "@root/src/components/ui/input"
|
||||
import { Separator } from "@root/src/components/ui/separator"
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetDescription,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@root/src/components/ui/sheet"
|
||||
import { Skeleton } from "@root/src/components/ui/skeleton"
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@root/src/components/ui/tooltip"
|
||||
|
||||
const SIDEBAR_COOKIE_NAME = "sidebar_state"
|
||||
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
||||
const SIDEBAR_WIDTH = "16rem"
|
||||
const SIDEBAR_WIDTH_MOBILE = "18rem"
|
||||
const SIDEBAR_WIDTH_ICON = "3rem"
|
||||
const SIDEBAR_KEYBOARD_SHORTCUT = "b"
|
||||
|
||||
type SidebarContextProps = {
|
||||
state: "expanded" | "collapsed"
|
||||
open: boolean
|
||||
setOpen: (open: boolean) => void
|
||||
openMobile: boolean
|
||||
setOpenMobile: (open: boolean) => void
|
||||
isMobile: boolean
|
||||
toggleSidebar: () => void
|
||||
}
|
||||
|
||||
const SidebarContext = React.createContext<SidebarContextProps | null>(null)
|
||||
|
||||
function useSidebar() {
|
||||
const context = React.useContext(SidebarContext)
|
||||
if (!context) {
|
||||
throw new Error("useSidebar must be used within a SidebarProvider.")
|
||||
}
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
function SidebarProvider({
|
||||
defaultOpen = true,
|
||||
open: openProp,
|
||||
onOpenChange: setOpenProp,
|
||||
className,
|
||||
style,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
defaultOpen?: boolean
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
}) {
|
||||
const isMobile = useIsMobile()
|
||||
const [openMobile, setOpenMobile] = React.useState(false)
|
||||
|
||||
// This is the internal state of the sidebar.
|
||||
// We use openProp and setOpenProp for control from outside the component.
|
||||
const [_open, _setOpen] = React.useState(defaultOpen)
|
||||
const open = openProp ?? _open
|
||||
const setOpen = React.useCallback(
|
||||
(value: boolean | ((value: boolean) => boolean)) => {
|
||||
const openState = typeof value === "function" ? value(open) : value
|
||||
if (setOpenProp) {
|
||||
setOpenProp(openState)
|
||||
} else {
|
||||
_setOpen(openState)
|
||||
}
|
||||
|
||||
// This sets the cookie to keep the sidebar state.
|
||||
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
|
||||
},
|
||||
[setOpenProp, open]
|
||||
)
|
||||
|
||||
// Helper to toggle the sidebar.
|
||||
const toggleSidebar = React.useCallback(() => {
|
||||
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open)
|
||||
}, [isMobile, setOpen, setOpenMobile])
|
||||
|
||||
// Adds a keyboard shortcut to toggle the sidebar.
|
||||
React.useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (
|
||||
event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
|
||||
(event.metaKey || event.ctrlKey)
|
||||
) {
|
||||
event.preventDefault()
|
||||
toggleSidebar()
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown)
|
||||
return () => window.removeEventListener("keydown", handleKeyDown)
|
||||
}, [toggleSidebar])
|
||||
|
||||
// We add a state so that we can do data-state="expanded" or "collapsed".
|
||||
// This makes it easier to style the sidebar with Tailwind classes.
|
||||
const state = open ? "expanded" : "collapsed"
|
||||
|
||||
const contextValue = React.useMemo<SidebarContextProps>(
|
||||
() => ({
|
||||
state,
|
||||
open,
|
||||
setOpen,
|
||||
isMobile,
|
||||
openMobile,
|
||||
setOpenMobile,
|
||||
toggleSidebar,
|
||||
}),
|
||||
[state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
|
||||
)
|
||||
|
||||
return (
|
||||
<SidebarContext.Provider value={contextValue}>
|
||||
<TooltipProvider delayDuration={0}>
|
||||
<div
|
||||
data-slot="sidebar-wrapper"
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH,
|
||||
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
|
||||
...style,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
className={cn(
|
||||
"group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
</SidebarContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
function Sidebar({
|
||||
side = "left",
|
||||
variant = "sidebar",
|
||||
collapsible = "offcanvas",
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
side?: "left" | "right"
|
||||
variant?: "sidebar" | "floating" | "inset"
|
||||
collapsible?: "offcanvas" | "icon" | "none"
|
||||
}) {
|
||||
const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
|
||||
|
||||
if (collapsible === "none") {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar"
|
||||
className={cn(
|
||||
"bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
|
||||
<SheetContent
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar"
|
||||
data-mobile="true"
|
||||
className="bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden"
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
side={side}
|
||||
>
|
||||
<SheetHeader className="sr-only">
|
||||
<SheetTitle>Sidebar</SheetTitle>
|
||||
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
||||
</SheetHeader>
|
||||
<div className="flex h-full w-full flex-col">{children}</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="group peer text-sidebar-foreground hidden md:block"
|
||||
data-state={state}
|
||||
data-collapsible={state === "collapsed" ? collapsible : ""}
|
||||
data-variant={variant}
|
||||
data-side={side}
|
||||
data-slot="sidebar"
|
||||
>
|
||||
{/* This is what handles the sidebar gap on desktop */}
|
||||
<div
|
||||
data-slot="sidebar-gap"
|
||||
className={cn(
|
||||
"relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
|
||||
"group-data-[collapsible=offcanvas]:w-0",
|
||||
"group-data-[side=right]:rotate-180",
|
||||
variant === "floating" || variant === "inset"
|
||||
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon)"
|
||||
)}
|
||||
/>
|
||||
<div
|
||||
data-slot="sidebar-container"
|
||||
className={cn(
|
||||
"fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex",
|
||||
side === "left"
|
||||
? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
|
||||
: "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
|
||||
// Adjust the padding for floating and inset variants.
|
||||
variant === "floating" || variant === "inset"
|
||||
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar-inner"
|
||||
className="bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow-sm"
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarTrigger({
|
||||
className,
|
||||
onClick,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button>) {
|
||||
const { toggleSidebar } = useSidebar()
|
||||
|
||||
return (
|
||||
<Button
|
||||
data-sidebar="trigger"
|
||||
data-slot="sidebar-trigger"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={cn("size-7", className)}
|
||||
onClick={(event) => {
|
||||
onClick?.(event)
|
||||
toggleSidebar()
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<PanelLeftIcon />
|
||||
<span className="sr-only">Toggle Sidebar</span>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
|
||||
const { toggleSidebar } = useSidebar()
|
||||
|
||||
return (
|
||||
<button
|
||||
data-sidebar="rail"
|
||||
data-slot="sidebar-rail"
|
||||
aria-label="Toggle Sidebar"
|
||||
tabIndex={-1}
|
||||
onClick={toggleSidebar}
|
||||
title="Toggle Sidebar"
|
||||
className={cn(
|
||||
"hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex",
|
||||
"in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
|
||||
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
|
||||
"hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full",
|
||||
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
||||
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
|
||||
return (
|
||||
<main
|
||||
data-slot="sidebar-inset"
|
||||
className={cn(
|
||||
"bg-background relative flex w-full flex-1 flex-col",
|
||||
"md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarInput({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Input>) {
|
||||
return (
|
||||
<Input
|
||||
data-slot="sidebar-input"
|
||||
data-sidebar="input"
|
||||
className={cn("bg-background h-8 w-full shadow-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-header"
|
||||
data-sidebar="header"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-footer"
|
||||
data-sidebar="footer"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Separator>) {
|
||||
return (
|
||||
<Separator
|
||||
data-slot="sidebar-separator"
|
||||
data-sidebar="separator"
|
||||
className={cn("bg-sidebar-border mx-2 w-auto", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-content"
|
||||
data-sidebar="content"
|
||||
className={cn(
|
||||
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-group"
|
||||
data-sidebar="group"
|
||||
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroupLabel({
|
||||
className,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "div"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-group-label"
|
||||
data-sidebar="group-label"
|
||||
className={cn(
|
||||
"text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroupAction({
|
||||
className,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-group-action"
|
||||
data-sidebar="group-action"
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:absolute after:-inset-2 md:after:hidden",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroupContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-group-content"
|
||||
data-sidebar="group-content"
|
||||
className={cn("w-full text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="sidebar-menu"
|
||||
data-sidebar="menu"
|
||||
className={cn("flex w-full min-w-0 flex-col gap-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="sidebar-menu-item"
|
||||
data-sidebar="menu-item"
|
||||
className={cn("group/menu-item relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const sidebarMenuButtonVariants = cva(
|
||||
"peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
||||
outline:
|
||||
"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
|
||||
},
|
||||
size: {
|
||||
default: "h-8 text-sm",
|
||||
sm: "h-7 text-xs",
|
||||
lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function SidebarMenuButton({
|
||||
asChild = false,
|
||||
isActive = false,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
tooltip,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
asChild?: boolean
|
||||
isActive?: boolean
|
||||
tooltip?: string | React.ComponentProps<typeof TooltipContent>
|
||||
} & VariantProps<typeof sidebarMenuButtonVariants>) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
const { isMobile, state } = useSidebar()
|
||||
|
||||
const button = (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-button"
|
||||
data-sidebar="menu-button"
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
|
||||
if (!tooltip) {
|
||||
return button
|
||||
}
|
||||
|
||||
if (typeof tooltip === "string") {
|
||||
tooltip = {
|
||||
children: tooltip,
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side="right"
|
||||
align="center"
|
||||
hidden={state !== "collapsed" || isMobile}
|
||||
{...tooltip}
|
||||
/>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuAction({
|
||||
className,
|
||||
asChild = false,
|
||||
showOnHover = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
asChild?: boolean
|
||||
showOnHover?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-action"
|
||||
data-sidebar="menu-action"
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:absolute after:-inset-2 md:after:hidden",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
showOnHover &&
|
||||
"peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuBadge({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-menu-badge"
|
||||
data-sidebar="menu-badge"
|
||||
className={cn(
|
||||
"text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none",
|
||||
"peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSkeleton({
|
||||
className,
|
||||
showIcon = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
showIcon?: boolean
|
||||
}) {
|
||||
// Random width between 50 to 90%.
|
||||
const width = React.useMemo(() => {
|
||||
return `${Math.floor(Math.random() * 40) + 50}%`
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-menu-skeleton"
|
||||
data-sidebar="menu-skeleton"
|
||||
className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
|
||||
{...props}
|
||||
>
|
||||
{showIcon && (
|
||||
<Skeleton
|
||||
className="size-4 rounded-md"
|
||||
data-sidebar="menu-skeleton-icon"
|
||||
/>
|
||||
)}
|
||||
<Skeleton
|
||||
className="h-4 max-w-(--skeleton-width) flex-1"
|
||||
data-sidebar="menu-skeleton-text"
|
||||
style={
|
||||
{
|
||||
"--skeleton-width": width,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="sidebar-menu-sub"
|
||||
data-sidebar="menu-sub"
|
||||
className={cn(
|
||||
"border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSubItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="sidebar-menu-sub-item"
|
||||
data-sidebar="menu-sub-item"
|
||||
className={cn("group/menu-sub-item relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSubButton({
|
||||
asChild = false,
|
||||
size = "md",
|
||||
isActive = false,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"a"> & {
|
||||
asChild?: boolean
|
||||
size?: "sm" | "md"
|
||||
isActive?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "a"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-sub-button"
|
||||
data-sidebar="menu-sub-button"
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-hidden focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
"data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
|
||||
size === "sm" && "text-xs",
|
||||
size === "md" && "text-sm",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarGroup,
|
||||
SidebarGroupAction,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel,
|
||||
SidebarHeader,
|
||||
SidebarInput,
|
||||
SidebarInset,
|
||||
SidebarMenu,
|
||||
SidebarMenuAction,
|
||||
SidebarMenuBadge,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
SidebarMenuSkeleton,
|
||||
SidebarMenuSub,
|
||||
SidebarMenuSubButton,
|
||||
SidebarMenuSubItem,
|
||||
SidebarProvider,
|
||||
SidebarRail,
|
||||
SidebarSeparator,
|
||||
SidebarTrigger,
|
||||
useSidebar,
|
||||
}
|
||||
13
src/components/ui/skeleton.tsx
Normal file
13
src/components/ui/skeleton.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { cn } from "@root/lib/utils"
|
||||
|
||||
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="skeleton"
|
||||
className={cn("bg-accent animate-pulse rounded-md", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Skeleton }
|
||||
@@ -660,5 +660,10 @@
|
||||
"Show Advanced Settings": "Show Advanced Settings",
|
||||
"Hide Advanced Settings": "Hide Advanced Settings",
|
||||
"Main Toggle Action": "Main Toggle Action",
|
||||
"Support": "Support"
|
||||
"Support": "Support",
|
||||
"Update on Startup": "Update on Startup",
|
||||
"Send HWID": "Send HWID",
|
||||
"New Version is available": "New Version is available",
|
||||
"New Version": "New Version",
|
||||
"New update": "New update"
|
||||
}
|
||||
|
||||
@@ -612,5 +612,10 @@
|
||||
"Show Advanced Settings": "Показать дополнительные настройки",
|
||||
"Hide Advanced Settings": "Скрыть дополнительные настройки",
|
||||
"Main Toggle Action": "Действие главного переключателя",
|
||||
"Support": "Поддержка"
|
||||
"Support": "Поддержка",
|
||||
"Update on Startup": "Обновлять при запуске",
|
||||
"Send HWID": "Отправлять HWID",
|
||||
"New Version is available": "Доступна новая версия",
|
||||
"New Version": "Новая версия",
|
||||
"New update": "Доступно обновление"
|
||||
}
|
||||
|
||||
@@ -5,23 +5,15 @@ import { SWRConfig, mutate } from "swr";
|
||||
import { useEffect, useCallback, useState, useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useLocation, useRoutes, useNavigate } from "react-router-dom";
|
||||
import { List, Paper, ThemeProvider, SvgIcon } from "@mui/material";
|
||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import { routers } from "./_routers";
|
||||
import { getAxios } from "@/services/api";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import LogoSvg from "@/assets/image/logo.svg?react";
|
||||
import iconLight from "@/assets/image/icon_light.svg?react";
|
||||
import iconDark from "@/assets/image/icon_dark.svg?react";
|
||||
import { useThemeMode, useEnableLog } from "@/services/states";
|
||||
import { LayoutItem } from "@/components/layout/layout-item";
|
||||
import { LayoutTraffic } from "@/components/layout/layout-traffic";
|
||||
import { UpdateButton } from "@/components/layout/update-button";
|
||||
import { useCustomTheme } from "@/components/layout/use-custom-theme";
|
||||
import getSystem from "@/utils/get-system";
|
||||
import "dayjs/locale/ru";
|
||||
import "dayjs/locale/zh-cn";
|
||||
import { getPortableFlag } from "@/services/cmds";
|
||||
import React from "react";
|
||||
import { useListen } from "@/hooks/use-listen";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
@@ -30,6 +22,8 @@ import { initGlobalLogService } from "@/services/global-log-service";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
import { NoticeManager } from "@/components/base/NoticeManager";
|
||||
import { SidebarProvider, useSidebar } from "@/components/ui/sidebar";
|
||||
import { AppSidebar } from "@/components/layout/sidebar";
|
||||
|
||||
const appWindow = getCurrentWebviewWindow();
|
||||
export let portableFlag = false;
|
||||
@@ -50,11 +44,11 @@ const handleNoticeMessage = (
|
||||
switch (status) {
|
||||
case "import_sub_url::ok":
|
||||
mutate("getProfiles");
|
||||
navigate("/profile", { state: { current: msg } });
|
||||
navigate("/", { state: { activateProfile: msg } });
|
||||
showNotice("success", t("Import Subscription Successful"));
|
||||
window.dispatchEvent(new CustomEvent('activate-profile', { detail: msg }));
|
||||
break;
|
||||
case "import_sub_url::error":
|
||||
navigate("/profile");
|
||||
showNotice("error", msg);
|
||||
break;
|
||||
case "set_config::error":
|
||||
@@ -442,17 +436,36 @@ const Layout = () => {
|
||||
}, [start_page]);
|
||||
|
||||
if (!routersEles) {
|
||||
return <div className="h-screen w-screen bg-background" />;
|
||||
return <div className="h-screen w-screen bg-background" />;
|
||||
}
|
||||
|
||||
const AppLayout = () => {
|
||||
const { state, isMobile } = useSidebar();
|
||||
const location = useLocation();
|
||||
const routersEles = useRoutes(routers);
|
||||
|
||||
return (
|
||||
<>
|
||||
<AppSidebar />
|
||||
<main
|
||||
className="h-screen w-full overflow-y-auto transition-[margin] duration-200 ease-linear"
|
||||
>
|
||||
<div className="h-full w-full relative">
|
||||
{routersEles && React.cloneElement(routersEles, { key: location.pathname })}
|
||||
</div>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<SWRConfig value={{ errorRetryCount: 3 }}>
|
||||
<NoticeManager />
|
||||
<div className="h-screen w-screen bg-background text-foreground overflow-hidden">
|
||||
<div className="h-full w-full relative">
|
||||
{React.cloneElement(routersEles, { key: location.pathname })}
|
||||
</div>
|
||||
</div>
|
||||
<SidebarProvider defaultOpen={false}>
|
||||
<AppLayout />
|
||||
</SidebarProvider>
|
||||
</SWRConfig>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -8,7 +8,6 @@ import React, {
|
||||
import { useLockFn } from "ahooks";
|
||||
import { Virtuoso } from "react-virtuoso";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useConnectionSetting } from "@/services/states";
|
||||
import { useVisibility } from "@/hooks/use-visibility";
|
||||
import { useAppData } from "@/providers/app-data-provider";
|
||||
@@ -16,7 +15,6 @@ import { closeAllConnections } from "@/services/api";
|
||||
import parseTraffic from "@/utils/parse-traffic";
|
||||
import { cn } from "@root/lib/utils";
|
||||
|
||||
// Компоненты
|
||||
import { BaseEmpty } from "@/components/base";
|
||||
import { ConnectionItem } from "@/components/connection/connection-item";
|
||||
import { ConnectionTable } from "@/components/connection/connection-table";
|
||||
@@ -26,7 +24,6 @@ import {
|
||||
} from "@/components/connection/connection-detail";
|
||||
import {
|
||||
BaseSearchBox,
|
||||
type SearchState,
|
||||
} from "@/components/base/base-search-box";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -36,14 +33,7 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import {
|
||||
Tooltip,
|
||||
@@ -52,7 +42,6 @@ import {
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
|
||||
// Иконки
|
||||
import {
|
||||
List,
|
||||
Table2,
|
||||
@@ -62,6 +51,7 @@ import {
|
||||
ArrowUp,
|
||||
Menu,
|
||||
} from "lucide-react";
|
||||
import {SidebarTrigger} from "@/components/ui/sidebar";
|
||||
|
||||
const initConn: IConnections = {
|
||||
uploadTotal: 0,
|
||||
@@ -73,7 +63,6 @@ type OrderFunc = (list: IConnectionsItem[]) => IConnectionsItem[];
|
||||
|
||||
const ConnectionsPage = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const pageVisible = useVisibility();
|
||||
const [match, setMatch] = useState(() => (_: string) => true);
|
||||
const [curOrderOpt, setOrderOpt] = useState("Default");
|
||||
@@ -166,15 +155,6 @@ const ConnectionsPage = () => {
|
||||
});
|
||||
}, [connections]);
|
||||
|
||||
const menuItems = [
|
||||
{ label: t("Home"), path: "/home" },
|
||||
{ label: t("Profiles"), path: "/profile" },
|
||||
{ label: t("Settings"), path: "/settings" },
|
||||
{ label: t("Logs"), path: "/logs" },
|
||||
{ label: t("Proxies"), path: "/proxies" },
|
||||
{ label: t("Rules"), path: "/rules" },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="h-full w-full relative">
|
||||
<div
|
||||
@@ -184,6 +164,9 @@ const ConnectionsPage = () => {
|
||||
)}
|
||||
>
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="w-10">
|
||||
<SidebarTrigger />
|
||||
</div>
|
||||
<h2 className="text-2xl font-semibold tracking-tight">
|
||||
{t("Connections")}
|
||||
</h2>
|
||||
@@ -245,26 +228,6 @@ const ConnectionsPage = () => {
|
||||
<Button size="sm" variant="destructive" onClick={onCloseAll}>
|
||||
{t("Close All")}
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" title={t("Menu")}>
|
||||
<Menu className="h-5 w-5" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>{t("Menu")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{menuItems.map((item) => (
|
||||
<DropdownMenuItem
|
||||
key={item.path}
|
||||
onSelect={() => navigate(item.path)}
|
||||
disabled={location.pathname === item.path}
|
||||
>
|
||||
{item.label}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import React, { useRef, useMemo, useCallback, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import React, {useRef, useMemo, useCallback, useState, useEffect} from "react";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
@@ -22,12 +21,11 @@ import {
|
||||
ChevronsUpDown,
|
||||
Check,
|
||||
PlusCircle,
|
||||
Menu,
|
||||
Wrench,
|
||||
AlertTriangle,
|
||||
Loader2,
|
||||
Globe,
|
||||
Send,
|
||||
Send, ExternalLink, RefreshCw,
|
||||
} from "lucide-react";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import { useSystemState } from "@/hooks/use-system-state";
|
||||
@@ -37,14 +35,17 @@ import { ProxySelectors } from "@/components/home/proxy-selectors";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { closeAllConnections } from "@/services/api";
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { updateProfile } from "@/services/cmds";
|
||||
import { SidebarTrigger } from "@/components/ui/sidebar";
|
||||
|
||||
const MinimalHomePage: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const [isToggling, setIsToggling] = useState(false);
|
||||
const [isUpdating, setIsUpdating] = useState(false);
|
||||
const { profiles, patchProfiles, activateSelected, mutateProfiles } =
|
||||
useProfiles();
|
||||
const viewerRef = useRef<ProfileViewerRef>(null);
|
||||
const [uidToActivate, setUidToActivate] = useState<string | null>(null);
|
||||
|
||||
const profileItems = useMemo(() => {
|
||||
const items =
|
||||
@@ -56,7 +57,7 @@ const MinimalHomePage: React.FC = () => {
|
||||
const currentProfile = useMemo(() => {
|
||||
return profileItems.find(p => p.uid === profiles?.current);
|
||||
}, [profileItems, profiles?.current]);
|
||||
console.log(currentProfile);
|
||||
console.log("Current profile", currentProfile);
|
||||
const currentProfileName = currentProfile?.name || profiles?.current;
|
||||
|
||||
const activateProfile = useCallback(
|
||||
@@ -76,6 +77,28 @@ const MinimalHomePage: React.FC = () => {
|
||||
[patchProfiles, activateSelected, mutateProfiles, t],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const handleActivationEvent = (event: Event) => {
|
||||
const customEvent = event as CustomEvent<string>;
|
||||
const profileId = customEvent.detail;
|
||||
if (profileId) {
|
||||
setUidToActivate(profileId);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('activate-profile', handleActivationEvent);
|
||||
return () => {
|
||||
window.removeEventListener('activate-profile', handleActivationEvent);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (uidToActivate && profileItems.some(p => p.uid === uidToActivate)) {
|
||||
activateProfile(uidToActivate, false);
|
||||
setUidToActivate(null);
|
||||
}
|
||||
}, [uidToActivate, profileItems, activateProfile]);
|
||||
|
||||
const handleProfileChange = useLockFn(async (uid: string) => {
|
||||
if (profiles?.current === uid) return;
|
||||
await activateProfile(uid, true);
|
||||
@@ -128,85 +151,107 @@ const MinimalHomePage: React.FC = () => {
|
||||
}
|
||||
});
|
||||
|
||||
const navMenuItems = [
|
||||
{ label: "Profiles", path: "/profile" },
|
||||
{ label: "Settings", path: "/settings" },
|
||||
{ label: "Logs", path: "/logs" },
|
||||
{ label: "Proxies", path: "/proxies" },
|
||||
{ label: "Connections", path: "/connections" },
|
||||
{ label: "Rules", path: "/rules" },
|
||||
];
|
||||
const handleUpdateProfile = useLockFn(async () => {
|
||||
if (!currentProfile?.uid || currentProfile.type !== 'remote') return;
|
||||
setIsUpdating(true);
|
||||
try {
|
||||
await updateProfile(currentProfile.uid);
|
||||
toast.success(t("Profile Updated Successfully"));
|
||||
mutateProfiles(); // Обновляем данные в UI
|
||||
} catch (err: any) {
|
||||
toast.error(t("Failed to update profile"), { description: err.message });
|
||||
} finally {
|
||||
setIsUpdating(false);
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-screen p-5">
|
||||
<header className="absolute top-0 left-0 right-0 p-5 flex items-center justify-between z-20">
|
||||
<div className="w-10"></div>
|
||||
|
||||
{profileItems.length > 0 && (
|
||||
<div className="flex-shrink-0">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full max-w-[250px] sm:max-w-xs"
|
||||
>
|
||||
<span className="truncate">{currentProfileName}</span>
|
||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-[--radix-dropdown-menu-trigger-width]">
|
||||
<DropdownMenuLabel>{t("Profiles")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{profileItems.map((p) => (
|
||||
<DropdownMenuItem
|
||||
key={p.uid}
|
||||
onSelect={() => handleProfileChange(p.uid)}
|
||||
>
|
||||
<span className="flex-1 truncate">{p.name}</span>
|
||||
{profiles?.current === p.uid && (
|
||||
<Check className="ml-4 h-4 w-4" />
|
||||
)}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onSelect={() => viewerRef.current?.create()}>
|
||||
<PlusCircle className="mr-2 h-4 w-4" />
|
||||
<span>{t("Add Profile")}</span>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<div className="h-full w-full flex flex-col">
|
||||
<header className="flex-shrink-0 p-5 grid grid-cols-3 items-center z-10">
|
||||
<div className="flex justify-start">
|
||||
<SidebarTrigger />
|
||||
</div>
|
||||
<div className="justify-self-center flex flex-col items-center gap-2">
|
||||
<div className="relative">
|
||||
{profileItems.length > 0 && (
|
||||
<div className="flex-shrink-0">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" className="w-full max-w-[250px] sm:max-w-xs">
|
||||
<span className="truncate">{currentProfileName}</span>
|
||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-[--radix-dropdown-menu-trigger-width]">
|
||||
<DropdownMenuLabel>{t("Profiles")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{profileItems.map((p) => (
|
||||
<DropdownMenuItem
|
||||
key={p.uid}
|
||||
onSelect={() => handleProfileChange(p.uid)}
|
||||
>
|
||||
<span className="flex-1 truncate">{p.name}</span>
|
||||
{profiles?.current === p.uid && (
|
||||
<Check className="ml-4 h-4 w-4" />
|
||||
)}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onSelect={() => viewerRef.current?.create()}>
|
||||
<PlusCircle className="mr-2 h-4 w-4" />
|
||||
<span>{t("Add Profile")}</span>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
)}
|
||||
{currentProfile?.type === 'remote' && (
|
||||
<div className="absolute top-1/2 -translate-y-1/2 left-full ml-2">
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={handleUpdateProfile}
|
||||
disabled={isUpdating}
|
||||
className="flex-shrink-0"
|
||||
>
|
||||
{isUpdating ? <Loader2 className="h-5 w-5 animate-spin" /> : <RefreshCw className="h-5 w-5" />}
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent><p>{t("Update Profile")}</p></TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="w-10">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="icon">
|
||||
<Menu className="h-5 w-5" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>{t("Menu")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{navMenuItems.map((item) => (
|
||||
<DropdownMenuItem
|
||||
key={item.path}
|
||||
onSelect={() => navigate(item.path)}
|
||||
>
|
||||
{t(item.label)}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
<div className="flex justify-end">
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="flex items-center justify-center flex-grow w-full">
|
||||
<div className="flex flex-col items-center gap-8 pt-10">
|
||||
<main className="flex-1 overflow-y-auto flex items-center justify-center">
|
||||
<div className="relative flex flex-col items-center gap-8 py-10 w-full max-w-4xl px-4">
|
||||
{currentProfile?.announce && (
|
||||
<p className="relative -translate-y-15 text-xl font-semibold text-foreground max-w-lg text-center">
|
||||
{currentProfile.announce}
|
||||
</p>
|
||||
<div className="absolute -top-15 w-full flex justify-center text-center max-w-lg">
|
||||
{currentProfile.announce_url ? (
|
||||
<a
|
||||
href={currentProfile.announce_url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-2 text-base font-semibold text-foreground hover:underline hover:opacity-80 transition-all"
|
||||
title={currentProfile.announce_url}
|
||||
>
|
||||
<span>{currentProfile.announce}</span>
|
||||
<ExternalLink className="h-4 w-4 flex-shrink-0" />
|
||||
</a>
|
||||
) : (
|
||||
<p className="text-base font-semibold text-foreground">
|
||||
{currentProfile.announce}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="text-center">
|
||||
<h1
|
||||
@@ -276,8 +321,8 @@ const MinimalHomePage: React.FC = () => {
|
||||
</Alert>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<footer className="flex justify-center p-4 flex-shrink-0">
|
||||
{currentProfile?.support_url && (
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
@@ -286,7 +331,7 @@ const MinimalHomePage: React.FC = () => {
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<a href={currentProfile.support_url} target="_blank" rel="noopener noreferrer" className="transition-colors hover:text-primary">
|
||||
{(currentProfile.support_url.includes('t.me') || currentProfile.support_url.includes('telegram')) ? (
|
||||
{(currentProfile.support_url.includes('t.me') || currentProfile.support_url.includes('telegram') || currentProfile.support_url.startsWith('tg://')) ? (
|
||||
<Send className="h-5 w-5" />
|
||||
) : (
|
||||
<Globe className="h-5 w-5" />
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// LogPage.tsx
|
||||
|
||||
import React, {
|
||||
useMemo,
|
||||
useState,
|
||||
@@ -10,8 +8,7 @@ import React, {
|
||||
import { Virtuoso } from "react-virtuoso";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useLocalStorage } from "foxact/use-local-storage";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Play, Pause, Trash2, Menu } from "lucide-react";
|
||||
import { Play, Pause, Trash2 } from "lucide-react";
|
||||
import { LogLevel } from "@/hooks/use-log-data";
|
||||
import { useClashInfo } from "@/hooks/use-clash";
|
||||
import { useEnableLog } from "@/services/states";
|
||||
@@ -34,18 +31,10 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import {SidebarTrigger} from "@/components/ui/sidebar";
|
||||
|
||||
const LogPage = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const [enableLog, setEnableLog] = useEnableLog();
|
||||
const { clashInfo } = useClashInfo();
|
||||
const [logLevel, setLogLevel] = useLocalStorage<LogLevel>(
|
||||
@@ -104,28 +93,16 @@ const LogPage = () => {
|
||||
[],
|
||||
);
|
||||
|
||||
const menuItems = [
|
||||
{ label: t("Home"), path: "/home" },
|
||||
{ label: t("Profiles"), path: "/profile" },
|
||||
{ label: t("Settings"), path: "/settings" },
|
||||
{ label: t("Proxies"), path: "/proxies" },
|
||||
{ label: t("Connections"), path: "/connections" },
|
||||
{ label: t("Rules"), path: "/rules" },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="h-full w-full relative">
|
||||
{/* "Липкая" шапка */}
|
||||
<div
|
||||
className={cn(
|
||||
"absolute top-0 left-0 right-0 z-10 p-4 transition-all duration-200",
|
||||
// --- НАЧАЛО ИЗМЕНЕНИЙ ---
|
||||
// Вместо блюра делаем солидный фон с тенью при прокрутке
|
||||
{ "bg-background shadow-md": isScrolled },
|
||||
// --- КОНЕЦ ИЗМЕНЕНИЙ ---
|
||||
)}
|
||||
>
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
<SidebarTrigger />
|
||||
<h2 className="text-2xl font-semibold tracking-tight">{t("Logs")}</h2>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
@@ -146,26 +123,6 @@ const LogPage = () => {
|
||||
{t("Clear")}
|
||||
</Button>
|
||||
)}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" title={t("Menu")}>
|
||||
<Menu className="h-5 w-5" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>{t("Menu")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{menuItems.map((item) => (
|
||||
<DropdownMenuItem
|
||||
key={item.path}
|
||||
onSelect={() => navigate(item.path)}
|
||||
disabled={location.pathname === item.path}
|
||||
>
|
||||
{item.label}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
@@ -187,7 +144,6 @@ const LogPage = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Возвращаем Virtuoso на место */}
|
||||
<div
|
||||
ref={scrollContainerRef}
|
||||
className="absolute top-0 left-0 right-0 bottom-0 pt-32 overflow-y-auto"
|
||||
|
||||
@@ -41,14 +41,12 @@ import { ConfigViewer } from "@/components/setting/mods/config-viewer";
|
||||
import { throttle } from "lodash-es";
|
||||
import { readTextFile } from "@tauri-apps/plugin-fs";
|
||||
import { readText } from "@tauri-apps/plugin-clipboard-manager";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import { useListen } from "@/hooks/use-listen";
|
||||
import { listen, TauriEvent } from "@tauri-apps/api/event";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
import { cn } from "@root/lib/utils";
|
||||
|
||||
// Компоненты shadcn/ui
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Tooltip,
|
||||
@@ -56,31 +54,19 @@ import {
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
|
||||
// Иконки
|
||||
import {
|
||||
ClipboardPaste,
|
||||
X,
|
||||
PlusCircle,
|
||||
RefreshCw,
|
||||
Zap,
|
||||
FileText,
|
||||
Loader2,
|
||||
Menu,
|
||||
} from "lucide-react";
|
||||
import { SidebarTrigger } from "@/components/ui/sidebar";
|
||||
|
||||
const ProfilePage = () => {
|
||||
const { t } = useTranslation();
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const { addListener } = useListen();
|
||||
const [url, setUrl] = useState("");
|
||||
const [disabled, setDisabled] = useState(false);
|
||||
@@ -89,7 +75,6 @@ const ProfilePage = () => {
|
||||
const [updateAllLoading, setUpdateAllLoading] = useState(false);
|
||||
const [enhanceLoading, setEnhanceLoading] = useState(false);
|
||||
|
||||
// Логика для "липкой" шапки
|
||||
const scrollerRef = useRef<HTMLDivElement>(null);
|
||||
const [isScrolled, setIsScrolled] = useState(false);
|
||||
|
||||
@@ -335,15 +320,6 @@ const ProfilePage = () => {
|
||||
};
|
||||
}, [mutateProfiles]);
|
||||
|
||||
const menuItems = [
|
||||
{ label: t("Home"), path: "/home" },
|
||||
{ label: t("Settings"), path: "/settings" },
|
||||
{ label: t("Logs"), path: "/logs" },
|
||||
{ label: t("Proxies"), path: "/proxies" },
|
||||
{ label: t("Connections"), path: "/connections" },
|
||||
{ label: t("Rules"), path: "/rules" },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="h-full w-full relative">
|
||||
<div
|
||||
@@ -353,6 +329,9 @@ const ProfilePage = () => {
|
||||
)}
|
||||
>
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="w-10">
|
||||
<SidebarTrigger />
|
||||
</div>
|
||||
<h2 className="text-2xl font-semibold tracking-tight">
|
||||
{t("Profiles")}
|
||||
</h2>
|
||||
@@ -424,74 +403,14 @@ const ProfilePage = () => {
|
||||
<p>{t("View Runtime Config")}</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" title={t("Menu")}>
|
||||
<Menu className="h-5 w-5" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>{t("Menu")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{menuItems.map((item) => (
|
||||
<DropdownMenuItem
|
||||
key={item.path}
|
||||
onSelect={() => navigate(item.path)}
|
||||
disabled={location.pathname === item.path}
|
||||
>
|
||||
{item.label}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<div className="flex items-center gap-1 flex-grow sm:flex-grow-0">
|
||||
<Input
|
||||
type="text"
|
||||
placeholder={t("Profile URL")}
|
||||
value={url}
|
||||
onChange={(e) => setUrl(e.target.value)}
|
||||
className="h-9 min-w-[200px] flex-grow sm:w-80"
|
||||
/>
|
||||
{url ? (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
title={t("Clear")}
|
||||
onClick={() => setUrl("")}
|
||||
className="h-9 w-9 flex-shrink-0"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
title={t("Paste")}
|
||||
onClick={onCopyLink}
|
||||
className="h-9 w-9 flex-shrink-0"
|
||||
>
|
||||
<ClipboardPaste className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Button
|
||||
onClick={onImport}
|
||||
disabled={!url || disabled || importLoading}
|
||||
className="h-9"
|
||||
>
|
||||
{importLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
{t("Import")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
ref={scrollerRef}
|
||||
className="absolute top-0 left-0 right-0 bottom-0 pt-40 overflow-y-auto"
|
||||
className="absolute top-0 left-0 right-0 bottom-0 pt-25 overflow-y-auto"
|
||||
>
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
|
||||
@@ -1,27 +1,17 @@
|
||||
import useSWR from "swr";
|
||||
import { useEffect } from "react";
|
||||
import React, { useEffect } from "react";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { closeAllConnections, getClashConfig } from "@/services/api";
|
||||
import { patchClashMode } from "@/services/cmds";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import { ProxyGroups } from "@/components/proxy/proxy-groups";
|
||||
import { ProviderButton } from "@/components/proxy/provider-button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Menu } from "lucide-react";
|
||||
import { SidebarTrigger } from "@/components/ui/sidebar";
|
||||
|
||||
const ProxyPage = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { data: clashConfig, mutate: mutateClash } = useSWR(
|
||||
"getClashConfig",
|
||||
@@ -50,18 +40,12 @@ const ProxyPage = () => {
|
||||
}
|
||||
}, [curMode]);
|
||||
|
||||
const menuItems = [
|
||||
{ label: t("Home"), path: "/home" },
|
||||
{ label: t("Profiles"), path: "/profile" },
|
||||
{ label: t("Settings"), path: "/settings" },
|
||||
{ label: t("Logs"), path: "/logs" },
|
||||
{ label: t("Connections"), path: "/connections" },
|
||||
{ label: t("Rules"), path: "/rules" },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col">
|
||||
<div className="p-4 pb-2 flex justify-between items-center">
|
||||
<div className="w-10">
|
||||
<SidebarTrigger />
|
||||
</div>
|
||||
<h2 className="text-2xl font-semibold tracking-tight">
|
||||
{t("Proxies")}
|
||||
</h2>
|
||||
@@ -80,26 +64,6 @@ const ProxyPage = () => {
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" title={t("Menu")}>
|
||||
<Menu className="h-5 w-5" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>{t("Menu")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{menuItems.map((item) => (
|
||||
<DropdownMenuItem
|
||||
key={item.path}
|
||||
onSelect={() => navigate(item.path)}
|
||||
disabled={location.pathname === item.path}
|
||||
>
|
||||
{item.label}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,33 +1,20 @@
|
||||
import { useState, useMemo, useRef, useEffect, useCallback } from "react";
|
||||
import React, { useState, useMemo, useRef, useEffect, useCallback } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Virtuoso, VirtuosoHandle } from "react-virtuoso";
|
||||
import { useAppData } from "@/providers/app-data-provider";
|
||||
import { useVisibility } from "@/hooks/use-visibility";
|
||||
import { cn } from "@root/lib/utils";
|
||||
|
||||
// Компоненты
|
||||
import { BaseEmpty } from "@/components/base";
|
||||
import RuleItem from "@/components/rule/rule-item";
|
||||
import { ProviderButton } from "@/components/rule/provider-button";
|
||||
import { BaseSearchBox, SearchState } from "@/components/base/base-search-box";
|
||||
import { BaseSearchBox } from "@/components/base/base-search-box";
|
||||
import { ScrollTopButton } from "@/components/layout/scroll-top-button";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
|
||||
// Иконки
|
||||
import { Menu } from "lucide-react";
|
||||
import { SidebarTrigger } from "@/components/ui/sidebar";
|
||||
|
||||
const RulesPage = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const { rules = [], refreshRules, refreshRuleProviders } = useAppData();
|
||||
const [match, setMatch] = useState(() => (_: string) => true);
|
||||
const virtuosoRef = useRef<VirtuosoHandle>(null);
|
||||
@@ -36,24 +23,17 @@ const RulesPage = () => {
|
||||
const [isScrolled, setIsScrolled] = useState(false);
|
||||
const pageVisible = useVisibility();
|
||||
|
||||
// --- НАЧАЛО ИЗМЕНЕНИЙ 1 ---
|
||||
// Разделяем логику на два безопасных useEffect
|
||||
useEffect(() => {
|
||||
// Этот эффект сработает только один раз при монтировании компонента
|
||||
refreshRules();
|
||||
refreshRuleProviders();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []); // Пустой массив зависимостей = запуск только один раз
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
// Этот эффект будет срабатывать только при изменении видимости страницы
|
||||
if (pageVisible) {
|
||||
refreshRules();
|
||||
refreshRuleProviders();
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [pageVisible]);
|
||||
// --- КОНЕЦ ИЗМЕНЕНИЙ 1 ---
|
||||
|
||||
const filteredRules = useMemo(() => {
|
||||
return rules.filter((item) => match(item.payload));
|
||||
@@ -75,21 +55,9 @@ const RulesPage = () => {
|
||||
virtuosoRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
||||
}, []);
|
||||
|
||||
// --- НАЧАЛО ИЗМЕНЕНИЙ 2 ---
|
||||
// Оборачиваем обработчик поиска в useCallback для стабильности
|
||||
const handleSearch = useCallback((matcher: (content: string) => boolean) => {
|
||||
setMatch(() => matcher);
|
||||
}, []);
|
||||
// --- КОНЕЦ ИЗМЕНЕНИЙ 2 ---
|
||||
|
||||
const menuItems = [
|
||||
{ label: t("Home"), path: "/home" },
|
||||
{ label: t("Profiles"), path: "/profile" },
|
||||
{ label: t("Settings"), path: "/settings" },
|
||||
{ label: t("Logs"), path: "/logs" },
|
||||
{ label: t("Proxies"), path: "/proxies" },
|
||||
{ label: t("Connections"), path: "/connections" },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="h-full w-full relative">
|
||||
@@ -100,35 +68,17 @@ const RulesPage = () => {
|
||||
)}
|
||||
>
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="w-10">
|
||||
<SidebarTrigger />
|
||||
</div>
|
||||
<h2 className="text-2xl font-semibold tracking-tight">
|
||||
{t("Rules")}
|
||||
</h2>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-70">
|
||||
{/* Передаем стабильную функцию handleSearch в пропс */}
|
||||
<BaseSearchBox onSearch={handleSearch} />
|
||||
</div>
|
||||
<ProviderButton />
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" title={t("Menu")}>
|
||||
<Menu className="h-5 w-5" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>{t("Menu")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{menuItems.map((item) => (
|
||||
<DropdownMenuItem
|
||||
key={item.path}
|
||||
onSelect={() => navigate(item.path)}
|
||||
disabled={location.pathname === item.path}
|
||||
>
|
||||
{item.label}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -150,7 +100,6 @@ const RulesPage = () => {
|
||||
<BaseEmpty />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<ScrollTopButton onClick={scrollToTop} show={showScrollTop} />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -7,23 +7,14 @@ import SettingVergeAdvanced from "@/components/setting/setting-verge-advanced";
|
||||
import SettingClash from "@/components/setting/setting-clash";
|
||||
import SettingSystem from "@/components/setting/setting-system";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Menu, Github, HelpCircle, Send } from "lucide-react";
|
||||
import { cn } from "@root/lib/utils";
|
||||
import { SidebarTrigger } from "@/components/ui/sidebar";
|
||||
|
||||
const SettingPage = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
||||
const [isScrolled, setIsScrolled] = useState(false);
|
||||
@@ -46,14 +37,6 @@ const SettingPage = () => {
|
||||
const toGithubRepo = useLockFn(() =>
|
||||
openWebUrl("https://github.com/coolcoala/clash-verge-rev-lite"),
|
||||
);
|
||||
const menuItems = [
|
||||
{ label: t("Home"), path: "/home" },
|
||||
{ label: t("Profiles"), path: "/profile" },
|
||||
{ label: t("Logs"), path: "/logs" },
|
||||
{ label: t("Proxies"), path: "/proxies" },
|
||||
{ label: t("Connections"), path: "/connections" },
|
||||
{ label: t("Rules"), path: "/rules" },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="h-full w-full relative">
|
||||
@@ -63,9 +46,13 @@ const SettingPage = () => {
|
||||
{ "bg-background/80 backdrop-blur-sm": isScrolled },
|
||||
)}
|
||||
>
|
||||
<div className="w-10">
|
||||
<SidebarTrigger />
|
||||
</div>
|
||||
<h2 className="text-2xl font-semibold tracking-tight">
|
||||
{t("Settings")}
|
||||
</h2>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -75,26 +62,6 @@ const SettingPage = () => {
|
||||
>
|
||||
<Github className="h-5 w-5" />
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" title={t("Menu")}>
|
||||
<Menu className="h-5 w-5" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>{t("Menu")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{menuItems.map((item) => (
|
||||
<DropdownMenuItem
|
||||
key={item.path}
|
||||
onSelect={() => navigate(item.path)}
|
||||
disabled={location.pathname === item.path}
|
||||
>
|
||||
{item.label}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
3
src/services/types.d.ts
vendored
3
src/services/types.d.ts
vendored
@@ -203,6 +203,7 @@ interface IProfileItem {
|
||||
home?: string;
|
||||
support_url?: string;
|
||||
announce?: string;
|
||||
announce_url?: string;
|
||||
}
|
||||
|
||||
interface IProfileOption {
|
||||
@@ -210,6 +211,7 @@ interface IProfileOption {
|
||||
with_proxy?: boolean;
|
||||
self_proxy?: boolean;
|
||||
update_interval?: number;
|
||||
update_always?: boolean;
|
||||
timeout_seconds?: number;
|
||||
danger_accept_invalid_certs?: boolean;
|
||||
merge?: string;
|
||||
@@ -752,6 +754,7 @@ interface IVergeConfig {
|
||||
enable_global_hotkey?: boolean;
|
||||
enable_dns_settings?: boolean;
|
||||
primary_action?: "tun-mode" | "system-proxy";
|
||||
enable_send_hwid?: boolean;
|
||||
proxy_auto_config?: boolean;
|
||||
pac_file_content?: string;
|
||||
proxy_host?: string;
|
||||
|
||||
Reference in New Issue
Block a user