Skip to content

Commit

Permalink
Comment the update_profiles_with_api and remove build-windows fro…
Browse files Browse the repository at this point in the history
…m workflow.
  • Loading branch information
JohanChane committed Mar 20, 2024
1 parent c1ce4a5 commit ed7ad55
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 231 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,3 @@ jobs:
name: Linux_Build
path: artifacts
retention-days: 5

build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Set up Mihomo
run: |
curl -L https://github.com/MetaCubeX/mihomo/releases/download/v1.18.1/mihomo-windows-amd64-v1.18.1.zip --output mihomo.zip
7z x mihomo.zip
mihomo-windows-amd64.exe -d Example -f Example/basic_clash_config.yaml &
- name: Download Dependencies
run: cd clashtui && cargo fetch

- name: Build
run: cd clashtui && cargo build --verbose && cargo build --release

# - name: Run tests
# run: cd clashtui && cargo test --all --verbose

- name: Build Version
run: cd clashtui && cargo r -- -v

- name: Pre Upload
run: |
mkdir artifacts
mv ./clashtui/target/debug/clashtui.exe ./artifacts/clashtui.debug.exe
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: Windows_Build
path: artifacts
retention-days: 5
51 changes: 1 addition & 50 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,59 +58,10 @@ jobs:
path: artifacts
retention-days: 5

build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Mihomo
run: |
curl -L https://github.com/MetaCubeX/mihomo/releases/download/v1.18.1/mihomo-windows-amd64-v1.18.1.zip --output mihomo.zip
7z x mihomo.zip
mihomo-windows-amd64.exe -d Example -f Example/basic_clash_config.yaml &
- name: Cache Target
uses: actions/cache@v4
with:
path: |
./clashtui/target
~/.cargo
key: ci-${{ runner.os }}-${{ hashFiles('./clashtui/Cargo.lock') }}
restore-keys: |
ci-${{ runner.os }}-${{ hashFiles('./clashtui/Cargo.lock') }}
ci-${{ runner.os }}-
- name: Download Dependencies
run: cd clashtui && cargo fetch

# - name: Run tests
# run: cd clashtui && cargo test --all --verbose

- name: Build
run: cd clashtui && cargo build --verbose && cargo build --release

- name: Build Version
run: cd clashtui && cargo r -- -v

- name: Pre Upload
run: |
mkdir artifacts
mv ./clashtui/target/release/clashtui.exe ./artifacts/clashtui.release.exe
mv ./clashtui/target/debug/clashtui.exe ./artifacts/clashtui.debug.exe
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: Windows_Build
path: artifacts
retention-days: 5

release:
runs-on: ubuntu-latest

needs: [build-linux, build-windows]
needs: [build-linux]

if: startsWith(github.ref, 'refs/tags/')

Expand Down
5 changes: 2 additions & 3 deletions clashtui/Cargo.lock

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

3 changes: 1 addition & 2 deletions clashtui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clashtui"
version = "0.2.4"
version = "0.2.0"
edition = "2021"

authors = ["Johan Chane <johanchanex@gmail.com>"]
Expand Down Expand Up @@ -30,7 +30,6 @@ log = "0.4"
log4rs = {version = "1.3", default-features = false, features = ["pattern_encoder", "file_appender"]}
enumflags2 = "0.7.9"
nix = {version = "0.28.0", features = ["fs", "user"]}
libc = "0.2.153"
regex = "1.10.3"

[workspace]
Expand Down
2 changes: 1 addition & 1 deletion clashtui/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "api"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
34 changes: 17 additions & 17 deletions clashtui/api/src/clash.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
const DEFAULT_PAYLOAD: &str = "'{\"path\": \"\", \"payload\": \"\"}'";
const TIMEOUT: u8 = 3;
//const TIMEOUT: u8 = 3;
const TIMEOUT: u8 = 10; // Adapting to poor network conditions.
// ToDo: Users can adjust settings based on their network quality.
#[cfg(target_feature = "deprecated")]
const GEO_URI: &str = "https://api.github.com/repos/MetaCubeX/meta-rules-dat/releases/latest";
#[cfg(target_feature = "deprecated")]
const USER_AGENT: &str = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";

use std::io::Result;
use std::time::SystemTime;

use minreq::{Method, Proxy};
use chrono::{DateTime, Local, TimeZone};

// format: {type: [(name, modifytime)]}
pub type ProfileTimeMap = std::collections::HashMap<ProfileSectionType, Vec<(String, Option<std::time::SystemTime>)>>;
use minreq::Method;

#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub enum ProfileSectionType {
Expand All @@ -21,14 +17,6 @@ pub enum ProfileSectionType {
RuleProvider,
}

pub fn provider_str_in_api(section_type: ProfileSectionType) -> Option<String> {
match section_type {
ProfileSectionType::ProxyProvider => Some("proxies".to_string()),
ProfileSectionType::RuleProvider => Some("rules".to_string()),
_ => None,
}
}

trait ResProcess {
fn process(self) -> core::result::Result<String, minreq::Error>;
}
Expand Down Expand Up @@ -140,6 +128,7 @@ impl ClashUtil {
self.request(Method::Patch, "/configs", Some(payload))
}

/*** update_providers_with_api
pub fn update_providers(&self, provider_type: ProfileSectionType) -> Result<Vec<(String, Result<String>)>> {
self.extract_net_providers(provider_type).and_then(|names| self.update_providers_helper(names, provider_type))
}
Expand Down Expand Up @@ -184,7 +173,9 @@ impl ClashUtil {
}
// Sometime mihomo updated the provider but not update it to the file.
pub fn extract_provider_utimes_with_api(&self, provider_type: ProfileSectionType) -> Result<Vec<(String, Option<SystemTime>)>>{
pub fn extract_provider_utimes_with_api(&self, provider_type: ProfileSectionType) -> Result<Vec<(String, Option<std::time::SystemTime>)>>{
use chrono::{DateTime, Local};
let sub_url = format!("/providers/{}", provider_str_in_api(provider_type).unwrap());
let response_str = self.request(Method::Get, sub_url.as_str(), None)?;
Expand Down Expand Up @@ -219,6 +210,15 @@ impl ClashUtil {
Ok(net_providers)
}
pub fn provider_str_in_api(section_type: ProfileSectionType) -> Option<String> {
match section_type {
ProfileSectionType::ProxyProvider => Some("proxies".to_string()),
ProfileSectionType::RuleProvider => Some("rules".to_string()),
_ => None,
}
}
***/

#[cfg(target_feature = "deprecated")]
pub fn check_geo_update(
&self,
Expand Down
2 changes: 1 addition & 1 deletion clashtui/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod dl_mihomo;
#[cfg(target_feature = "github_api")]
mod github_restful_api;

pub use clash::{ClashUtil, Resp, ProfileSectionType, ProfileTimeMap, provider_str_in_api};
pub use clash::{ClashUtil, Resp, ProfileSectionType};
pub use config::{ClashConfig, Mode, TunStack};
#[cfg(target_feature = "github_api")]
pub use github_restful_api::GithubApi;
5 changes: 0 additions & 5 deletions clashtui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ fn main() {

let mut flags = Flags::empty();

// ## Is CliMode
if cli_env.update_all_profiles {
flags.insert(Flag::CliMode)
}

// ## Setup logging as early as possible. So We can log.
let config_dir = load_app_dir(&mut flags);
setup_logging(config_dir.join("clashtui.log").to_str().unwrap());
Expand Down
7 changes: 3 additions & 4 deletions clashtui/src/utils/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ pub use enumflags2::BitFlags;
#[bitflags]
#[repr(u8)]
pub enum Flag {
CliMode = 1,
FirstInit = 1 << 1,
ErrorDuringInit = 1 << 2,
PortableMode = 1 << 3,
FirstInit = 1,
ErrorDuringInit = 1 << 1,
PortableMode = 1 << 2,
}
#[cfg(test)]
mod test {
Expand Down
3 changes: 1 addition & 2 deletions clashtui/src/utils/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use api::{ClashConfig, ClashUtil, Resp};

// format: {section_key: [(name, url, path)]}
pub type NetProviderMap = std::collections::HashMap<ProfileSectionType, Vec<(String, String, String)>>;
// format: {type, [(name, result)]}
pub type UpdateProviderType = std::collections::HashMap<ProfileSectionType, Vec<(String, std::io::Result<String>)>>;

#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub enum ProfileType {
Expand Down Expand Up @@ -138,6 +136,7 @@ fn load_app_config(
.and_then(|v| v.as_str())
.unwrap_or("clash.meta")
.to_string();
log::info!("clash_ua: {}", clash_ua);

let configs = if skip_init_conf {
let config_path = clashtui_dir.join("config.yaml");
Expand Down
Loading

0 comments on commit ed7ad55

Please sign in to comment.