Skip to content

Commit

Permalink
Merge pull request #7 from arduano/trunk
Browse files Browse the repository at this point in the history
Updating dependencies to be able to compile again, plus various cleanups
  • Loading branch information
diced authored Dec 10, 2023
2 parents 4e7d77c + 4d600a4 commit 867f236
Show file tree
Hide file tree
Showing 17 changed files with 1,463 additions and 746 deletions.
1,037 changes: 592 additions & 445 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "dvm"
description = "discord version manager for linux"
homepage = "https://github.com/diced/dvm"
repository = "https://github.com/diced/dvm.git"
license = "MIT"
license = "GPL-3"
version = "1.1.9"
authors = ["diced <pranaco2@gmail.com>"]
edition = "2021"
Expand All @@ -13,7 +13,11 @@ name = "dvm"

[dependencies]
tokio = { version = "1.6.0", features = ["full"] }
reqwest = { version = "0.11.3", features = ["json", "native-tls", "blocking"], default-features = false }
reqwest = { version = "0.11.3", features = [
"json",
"native-tls",
"blocking",
], default-features = false }
colored = "2.0.0"
clap = "3.0.0-beta.2"
clap_generate = "3.0.0-beta.2"
clap = { version = "4.4.11", features = ["derive", "color"] }
clap_complete = "4.4.4"
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions src/branch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::fmt;

use clap::ValueEnum;

#[derive(Debug, Clone, Copy)]
pub enum DiscordBranch {
STABLE,
PTB,
CANARY,
DEVELOPMENT,
}

impl fmt::Display for DiscordBranch {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.to_possible_value().unwrap().get_name())
}
}

impl clap::ValueEnum for DiscordBranch {
fn value_variants<'a>() -> &'a [Self] {
&[
DiscordBranch::STABLE,
DiscordBranch::CANARY,
DiscordBranch::PTB,
DiscordBranch::DEVELOPMENT,
]
}

fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
match self {
DiscordBranch::STABLE => Some(clap::builder::PossibleValue::new("stable")),
DiscordBranch::CANARY => Some(clap::builder::PossibleValue::new("canary")),
DiscordBranch::PTB => Some(clap::builder::PossibleValue::new("ptb")),
DiscordBranch::DEVELOPMENT => Some(clap::builder::PossibleValue::new("development")),
}
}
}
23 changes: 12 additions & 11 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{ env, fs, path::Path};
use std::{env, fs, path::Path};

use crate::{error, info, r#type::Type, success, Res, util::install_version};
use crate::{branch::DiscordBranch, error, info, success, util::install_version, Res};

pub async fn install(release_type: Type, verbose: bool, open_asar: bool) -> Res<()> {
pub async fn install(release_type: DiscordBranch, verbose: bool, open_asar: bool) -> Res<()> {
// create user var & create .dvm dirs
let user = env::var("USER")?;
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
Expand All @@ -11,10 +11,10 @@ pub async fn install(release_type: Type, verbose: bool, open_asar: bool) -> Res<
}

let pascal_pkg = match release_type {
Type::STABLE => "Discord",
Type::PTB => "DiscordPTB",
Type::CANARY => "DiscordCanary",
Type::DEVELOPMENT => "DiscordDevelopment",
DiscordBranch::STABLE => "Discord",
DiscordBranch::PTB => "DiscordPTB",
DiscordBranch::CANARY => "DiscordCanary",
DiscordBranch::DEVELOPMENT => "DiscordDevelopment",
};

let exists = Path::new(&format!("/home/{}/.dvm/{}", &user, &pascal_pkg)).exists();
Expand All @@ -31,10 +31,11 @@ pub async fn install(release_type: Type, verbose: bool, open_asar: bool) -> Res<
fs::rename(&asar_file, format!("{}.bak", &asar_file))?;
info!("renamed app.asar to app.asar.bak (if discord doesn't work after this, rename it back)");

let res = reqwest::get("https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar")
.await?
.bytes()
.await?;
let res =
reqwest::get("https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar")
.await?
.bytes()
.await?;

fs::write(&asar_file, res)?;

Expand Down
12 changes: 6 additions & 6 deletions src/cli/install_openasar.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{env, fs, path::Path};

use crate::{error, info, r#type::Type, success, Res};
use crate::{branch::DiscordBranch, error, info, success, Res};

pub async fn install_openasar(release_type: Type, verbose: bool) -> Res<()> {
pub async fn install_openasar(release_type: DiscordBranch, verbose: bool) -> Res<()> {
// create user var & create .dvm dirs
let user = env::var("USER")?;
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
Expand All @@ -11,10 +11,10 @@ pub async fn install_openasar(release_type: Type, verbose: bool) -> Res<()> {
}

let pascal_pkg = match release_type {
Type::STABLE => "Discord",
Type::PTB => "DiscordPTB",
Type::CANARY => "DiscordCanary",
Type::DEVELOPMENT => "DiscordDevelopment",
DiscordBranch::STABLE => "Discord",
DiscordBranch::PTB => "DiscordPTB",
DiscordBranch::CANARY => "DiscordCanary",
DiscordBranch::DEVELOPMENT => "DiscordDevelopment",
};

let exists = Path::new(&format!("/home/{}/.dvm/{}", &user, &pascal_pkg)).exists();
Expand Down
9 changes: 7 additions & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
mod install;
mod install_openasar;
mod remove;
mod run;
mod show;
mod update;
mod run;

pub use {install::install, install_openasar::install_openasar, remove::remove, show::show, update::update, run::run};
pub use install::install;
pub use install_openasar::install_openasar;
pub use remove::remove;
pub use run::run;
pub use show::show;
pub use update::update;
20 changes: 10 additions & 10 deletions src/cli/remove.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use std::{env, fs, path::Path};

use crate::{error, info, r#type::Type, success, Res};
use crate::{branch::DiscordBranch, error, info, success, Res};

pub async fn remove(release_type: Type, verbose: bool) -> Res<()> {
pub async fn remove(release_type: DiscordBranch, verbose: bool) -> Res<()> {
// create user var & create .dvm dirs
let user = env::var("USER")?;
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;

let pascal_pkg = match release_type {
Type::STABLE => "Discord",
Type::PTB => "DiscordPTB",
Type::CANARY => "DiscordCanary",
Type::DEVELOPMENT => "DiscordDevelopment",
DiscordBranch::STABLE => "Discord",
DiscordBranch::PTB => "DiscordPTB",
DiscordBranch::CANARY => "DiscordCanary",
DiscordBranch::DEVELOPMENT => "DiscordDevelopment",
};

let pkg_name = match release_type {
Type::STABLE => "discord",
Type::PTB => "discord-ptb",
Type::CANARY => "discord-canary",
Type::DEVELOPMENT => "discord-development",
DiscordBranch::STABLE => "discord",
DiscordBranch::PTB => "discord-ptb",
DiscordBranch::CANARY => "discord-canary",
DiscordBranch::DEVELOPMENT => "discord-development",
};

let exists = Path::new(&format!("/home/{}/.dvm/{}", user, pascal_pkg)).exists();
Expand Down
15 changes: 8 additions & 7 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::{env, fs, path::Path};

use tokio::process::Command;

use crate::{Res, error, info, r#type::Type};
use crate::{branch::DiscordBranch, error, info, Res};

pub async fn run(release_type: Type, args: Vec<String>, verbose: bool) -> Res<()> {
pub async fn run(release_type: DiscordBranch, args: Vec<String>, verbose: bool) -> Res<()> {
// create user var & create .dvm dirs
let user = env::var("USER")?;
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
Expand All @@ -17,10 +17,10 @@ pub async fn run(release_type: Type, args: Vec<String>, verbose: bool) -> Res<()
}

let pascal_pkg = match release_type {
Type::STABLE => "Discord",
Type::PTB => "DiscordPTB",
Type::CANARY => "DiscordCanary",
Type::DEVELOPMENT => "DiscordDevelopment",
DiscordBranch::STABLE => "Discord",
DiscordBranch::PTB => "DiscordPTB",
DiscordBranch::CANARY => "DiscordCanary",
DiscordBranch::DEVELOPMENT => "DiscordDevelopment",
};

let exists = Path::new(&format!("/home/{}/.dvm/{}", user, pascal_pkg)).exists();
Expand All @@ -32,7 +32,8 @@ pub async fn run(release_type: Type, args: Vec<String>, verbose: bool) -> Res<()
Command::new(format!("/home/{}/.dvm/{}/{}", user, pascal_pkg, pascal_pkg))
.args(&args)
.spawn()?
.wait_with_output().await?;
.wait_with_output()
.await?;

Ok(())
}
16 changes: 8 additions & 8 deletions src/cli/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

use colored::*;

use crate::{r#type::Type, Res};
use crate::{branch::DiscordBranch, Res};

// fn dirent(dirent: DirEntry) -> Res<(String, Type)> {
// let rl_type = match dirent.file_name().to_str().unwrap() {
Expand All @@ -22,21 +22,21 @@ use crate::{r#type::Type, Res};
// Ok((version, rl_type))
// }

fn dirent_verbose(dirent: DirEntry) -> Res<(String, Type, PathBuf)> {
fn dirent_verbose(dirent: DirEntry) -> Res<(String, DiscordBranch, PathBuf)> {
let rl_type = match dirent.file_name().to_str().unwrap() {
"Discord" => Type::STABLE,
"DiscordCanary" => Type::CANARY,
"DiscordPTB" => Type::PTB,
"DiscordDevelopment" => Type::DEVELOPMENT,
_ => Type::STABLE,
"Discord" => DiscordBranch::STABLE,
"DiscordCanary" => DiscordBranch::CANARY,
"DiscordPTB" => DiscordBranch::PTB,
"DiscordDevelopment" => DiscordBranch::DEVELOPMENT,
_ => DiscordBranch::STABLE,
};
let path = dirent.path();
let version = fs::read_to_string(path.join("version"))?.replace("\n", "");

Ok((version, rl_type, path))
}

async fn needs_update(version: String, release_type: Type) -> Res<(bool, String)> {
async fn needs_update(version: String, release_type: DiscordBranch) -> Res<(bool, String)> {
let res = reqwest::get(format!(
"https://discordapp.com/api/v8/updates/{}?platform=linux",
release_type
Expand Down
17 changes: 10 additions & 7 deletions src/cli/update.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{env, fs, path::Path};

use crate::{Res, error, info, r#type::Type, success, util::install_version};
use crate::{branch::DiscordBranch, error, info, success, util::install_version, Res};

pub async fn update(release_type: Type, verbose: bool) -> Res<()> {
pub async fn update(release_type: DiscordBranch, verbose: bool) -> Res<()> {
// create user var & create .dvm dirs
let user = env::var("USER")?;
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
Expand All @@ -15,10 +15,10 @@ pub async fn update(release_type: Type, verbose: bool) -> Res<()> {
}

let pascal_pkg = match release_type {
Type::STABLE => "Discord",
Type::PTB => "DiscordPTB",
Type::CANARY => "DiscordCanary",
Type::DEVELOPMENT => "DiscordDevelopment",
DiscordBranch::STABLE => "Discord",
DiscordBranch::PTB => "DiscordPTB",
DiscordBranch::CANARY => "DiscordCanary",
DiscordBranch::DEVELOPMENT => "DiscordDevelopment",
};

let exists = Path::new(&format!("/home/{}/.dvm/{}", user, pascal_pkg)).exists();
Expand All @@ -31,7 +31,10 @@ pub async fn update(release_type: Type, verbose: bool) -> Res<()> {

success!(
"updated {}:{} -> {}:{}",
release_type, version, release_type, latest
release_type,
version,
release_type,
latest
);

Ok(())
Expand Down
35 changes: 0 additions & 35 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
pub const VERSION: &str = "1.1.9";
pub const INSTALL_DESC: &str = "install the latest <type> of discord";
pub const INSTALL_ALIASES: &[&str] = &["i", "in", "get"];
pub const INSTALL_OPENASAR_DESC: &str = "install openasar for <type> of discord";
pub const INSTALL_OPENASAR_ALIASES: &[&str] = &["asar", "oa"];
pub const UPDATE_DESC: &str = "update to the latest <type> of discord";
pub const UPDATE_ALIASES: &[&str] = &["u", "up", "upgrade"];
pub const REMOVE_DESC: &str = "remove the installed <type> of discord";
pub const REMOVE_ALIASES: &[&str] = &["r", "rm", "d", "del", "un", "uninstall"];
pub const SHOW_DESC: &str = "show all installed versions";
pub const SHOW_ALIASES: &[&str] = &["s", "installed", "all", "a", "versions", "types"];
pub const COMP_DESC: &str = "get shell completions";
pub const COMP_ALIASES: &[&str] = &["c", "comp"];
pub const RUN_DESC: &str = "run discord with specific options";
pub const RUN_ALIASES: &[&str] = &["r", "start"];

pub const POSSIBLE_SHELLS: &[&str] = &[
"bash", "b",
"elvish", "e",
"fish", "f",
"powershell", "pwsh", "ps", "p",
"zsh", "z"
];

pub const POSSIBLE_VALUES: &[&str] = &[
"stable",
"discord-stable",
"s",

"canary",
"discord-canary",
"c",

"ptb",
"discord-ptb",
"p",

"development",
"dev",
"discord-development",
"d",
];
Loading

0 comments on commit 867f236

Please # to comment.