Skip to content

Commit

Permalink
init fix and revert
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackhr-arch committed Jun 26, 2024
1 parent 0d53f67 commit 83ef9f4
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 163 deletions.
39 changes: 5 additions & 34 deletions clashtui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clashtui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tui = ["ui", "ratatui"]
[dependencies]
ui = { path = "ui", optional = true }
backend = { path = "backend" }
ratatui = { version = "*", default-features = false, features = [
ratatui = { version = "0.26.1", default-features = false, features = [
"crossterm",
], optional = true }
log = "0.4"
Expand Down
14 changes: 0 additions & 14 deletions clashtui/backend/src/backend/impl_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,20 +521,6 @@ impl ClashBackend {
}
}
}
/// # Limitations
///
/// Windows treats symlink creation as a [privileged action][symlink-security],
/// therefore this function is likely to fail unless the user makes changes to
/// their system to permit symlink creation. Users can try enabling Developer
/// Mode, granting the `SeCreateSymbolicLinkPrivilege` privilege, or running
/// the process as an administrator.
///
/// [symlink-security]: https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links
#[allow(unused)]
fn crt_symlink_file<P: AsRef<std::path::Path>>(original: P, target: P) -> std::io::Result<()> {
use std::os;
os::unix::fs::symlink(original, target)
}
enum CrtFile {
Ok(File),
Tmp(File),
Expand Down
2 changes: 1 addition & 1 deletion clashtui/backend/src/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) fn parse_yaml(yaml_path: &std::path::Path) -> std::io::Result<serde_y
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))
}

pub fn get_mtime<P>(file_path: P) -> std::io::Result<std::time::SystemTime>
pub fn get_modify_time<P>(file_path: P) -> std::io::Result<std::time::SystemTime>
where
P: AsRef<std::path::Path>,
{
Expand Down
2 changes: 1 addition & 1 deletion clashtui/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() {
println!("cargo:rerun-if-changed=../.git/refs/heads/dev");
println!("cargo:rerun-if-changed=build.rs",);

if let Ok(_) = env::var("CLASHTUI_VERSION") {
if env::var("CLASHTUI_VERSION").is_ok() {
} else {
println!("cargo:rustc-env=CLASHTUI_VERSION={}", get_version());
}
Expand Down
23 changes: 5 additions & 18 deletions clashtui/src/tui/app.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use core::cell::{OnceCell, RefCell};
use std::io::{BufRead, Read, Write};
use std::{path::PathBuf, rc::Rc};
use std::rc::Rc;

use crate::utils::{Flag, Flags};
use ui::event;

use crate::msgpopup_methods;
use crate::tui::{
tabs::{ClashSrvCtlTab, ProfileTab, TabEvent, Tabs},
tools,
Expand All @@ -13,23 +13,9 @@ use crate::tui::{
EventState, StatusBar, TabBar, Theme, Visibility,
};
use crate::utils::{ClashBackend, SharedBackend, SharedState, State};
use crate::{msgpopup_methods, utils};

use super::impl_app::MonkeyPatch;

/// Mihomo (Clash.Meta) TUI Client
///
/// A tui tool for mihomo
#[derive(argh::FromArgs)]
pub struct CliEnv {
/// don't show UI but only update all profiles
#[argh(switch, short = 'u')]
pub update_all_profiles: bool,
/// print version information and exit
#[argh(switch, short = 'v')]
pub version: bool,
}

pub struct App {
tabbar: TabBar,
tabs: Vec<Tabs>,
Expand Down Expand Up @@ -168,7 +154,7 @@ impl App {
Keys::AppConfig => {
let _ = self
.util
.open_dir(&self.util.cfg.clash_cfg_dir)
.open_dir(std::path::Path::new(&self.util.cfg.clash_cfg_dir))
.map_err(|e| log::error!("ODIR: {e:?}"));
EventState::WorkDone
}
Expand Down Expand Up @@ -276,7 +262,8 @@ impl App {
)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))
}
#[desperated]
#[deprecated]
#[cfg(predicate)]
fn do_some_job_after_initapp_before_setupui(&mut self) {
// ## Correct the perm of files in clash_cfg_dir.
if !self.clashtui_util.check_perms_of_ccd_files() {
Expand Down
23 changes: 10 additions & 13 deletions clashtui/src/tui/tabs/clashsrvctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ impl ClashSrvCtlTab {
pub fn new(util: SharedBackend, state: SharedState) -> Self {
let mut operations = List::new(CLASHSRVCTL.to_string());
operations.set_items(vec![
#[cfg(target_os = "linux")]
ClashSrvOp::SetPermission.into(),
ClashSrvOp::StartClashService.into(),
ClashSrvOp::StopClashService.into(),
ClashSrvOp::SwitchMode.into(),
#[cfg(target_os = "windows")]
ClashSrvOp::SwitchSysProxy.into(),
#[cfg(target_os = "windows")]
ClashSrvOp::EnableLoopback.into(),
#[cfg(target_os = "windows")]
ClashSrvOp::InstallSrv.into(),
#[cfg(target_os = "windows")]
ClashSrvOp::UnInstallSrv.into(),
]);
let mut modes = List::new("Mode".to_string());
modes.set_items(vec![
Expand Down Expand Up @@ -133,19 +142,7 @@ impl super::TabEvent for ClashSrvCtlTab {
}
},
}
match op {
// Ops that doesn't need refresh
ClashSrvOp::SetPermission => {}

ClashSrvOp::StartClashService => {
todo!("Not good idea");
std::thread::sleep(std::time::Duration::from_secs(2)); // Waiting for mihomo to finish starting.
self.clashtui_state.borrow_mut().refresh();
}
_ => {
self.clashtui_state.borrow_mut().refresh();
}
}
self.state.borrow_mut().refresh();
}
}
fn draw(&mut self, f: &mut ratatui::prelude::Frame, area: ratatui::prelude::Rect) {
Expand Down
16 changes: 4 additions & 12 deletions clashtui/src/tui/tabs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,16 @@ macro_rules! msgpopup_methods {
impl $type {
// single-line popup
pub fn popup_txt_msg(&mut self, msg: String) {
if !msg.is_empty() {
self.msgpopup.push_txt_msg(msg);
self.msgpopup.show();
}
self.msgpopup.push_txt_msg(msg);
self.msgpopup.show();
}
// multi-lines popup
pub fn popup_list_msg<I>(&mut self, msg: I)
where
I: IntoIterator<Item = String>,
{
let mut list_msg = Vec::<String>::new();
for m in msg.into_iter() {
list_msg.push(m);
}
if list_msg.len() > 0 {
self.msgpopup.push_list_msg(list_msg);
self.msgpopup.show();
}
self.msgpopup.push_list_msg(msg);
self.msgpopup.show();
}
#[allow(unused)]
pub fn hide_msgpopup(&mut self) {
Expand Down
34 changes: 2 additions & 32 deletions clashtui/src/tui/tabs/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub struct ProfileTab {
util: SharedBackend,
state: SharedState,
op: Option<PTOp>,
confirm_op: Option<PTOp>,
}

impl ProfileTab {
Expand All @@ -48,7 +47,6 @@ impl ProfileTab {
util,
state,
op: None,
confirm_op: None,
};

instance.update_profile_list();
Expand Down Expand Up @@ -132,23 +130,6 @@ impl ProfileTab {
}
}

fn handle_gen_profile_info_ev(&mut self) {
if let Some(profile_name) = self.profile_list.selected() {
let is_cur_profile = profile_name == self.clashtui_state.borrow().get_profile();
match self
.clashtui_util
.gen_profile_info(profile_name, is_cur_profile)
{
Ok(info) => {
self.popup_list_msg(info);
}
Err(e) => {
self.popup_txt_msg(e.to_string());
}
}
}
}

fn update_profile_list(&mut self) {
let profile_names = self.util.get_profile_names().unwrap();
let profile_times: Vec<Option<std::time::SystemTime>> = profile_names
Expand All @@ -166,7 +147,7 @@ impl ProfileTab {
self.profile_list
.set_extras(profile_times.into_iter().map(|t| {
t.map(|t| {
utils::str_duration(
display_duration(
now.duration_since(t)
.expect("Clock may have gone backwards"),
)
Expand All @@ -186,7 +167,7 @@ impl super::TabEvent for ProfileTab {
if event_state.is_notconsumed() {
event_state = match self.confirm_popup.event(ev)? {
EventState::Yes => {
self.op = self.confirm_op.take();
self.op.replace(PTOp::Delete);
EventState::WorkDone
}
EventState::Cancel | EventState::WorkDone => EventState::WorkDone,
Expand Down Expand Up @@ -252,7 +233,6 @@ impl super::TabEvent for ProfileTab {
Keys::ProfileDelete => {
self.confirm_popup
.popup_msg("`y` to Delete, `Esc` to cancel".to_string());
self.confirm_op.replace(PTOp::Delete);
EventState::WorkDone
}
Keys::Edit => {
Expand Down Expand Up @@ -321,15 +301,6 @@ impl super::TabEvent for ProfileTab {
}
EventState::WorkDone
}
Keys::ProfileInfo => {
self.popup_txt_msg("Generating info...".to_string());
self.op.replace(PTOp::GenInfo);
EventState::WorkDone
}
Keys::ProfileNoPp => {
self.clashtui_state.borrow_mut().switch_no_pp();
EventState::WorkDone
}
_ => EventState::NotConsumed,
};
}
Expand Down Expand Up @@ -391,7 +362,6 @@ impl super::TabEvent for ProfileTab {
PTOp::UpdateAll => self.handle_update_profile_ev(true),
PTOp::Select => self.handle_select_profile_ev(),
PTOp::Delete => self.handle_delete_profile_ev(),
PTOp::GenInfo => self.handle_gen_profile_info_ev(),
}
}
}
Expand Down
27 changes: 0 additions & 27 deletions clashtui/src/utils/clashtui_data.rs

This file was deleted.

Loading

0 comments on commit 83ef9f4

Please sign in to comment.