Skip to content

Commit

Permalink
UI Tweaks - Borders, Spacing, Color (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koranir authored Apr 3, 2024
1 parent ae05916 commit debc629
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 132 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ zip-extract = { version = "0.1.3", default-features = false, features = ["deflat
[dependencies.iced]
version = "0.12.1"
default-features = false
features = ["advanced", "image", "tokio"]
features = ["web-colors", "advanced", "image", "tokio"]

[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
Expand Down
31 changes: 11 additions & 20 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,12 @@ pub struct PRHead {

pub fn get_pr(id: u16) -> Result<PR> {
make_request(&format!(
"https://api.github.com/repos/endless-sky/endless-sky/pulls/{}",
id
"https://api.github.com/repos/endless-sky/endless-sky/pulls/{id}"
))
}

pub fn unblock_artifact_download(artifact_id: u32) -> String {
format!(
"https://artifact-unblocker.mcofficer.workers.dev/artifact/{}",
artifact_id,
)
format!("https://artifact-unblocker.mcofficer.workers.dev/artifact/{artifact_id}",)
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -92,8 +88,7 @@ pub fn get_latest_workflow_run(
head_repo_id: u32,
) -> Result<WorkflowRun> {
let mut pages: Vec<WorkflowRuns> = make_paginated_request(&format!(
"https://api.github.com/repos/endless-sky/endless-sky/actions/workflows/{}/runs?branch={}",
workflow_id, branch
"https://api.github.com/repos/endless-sky/endless-sky/actions/workflows/{workflow_id}/runs?branch={branch}"
))?;

let runs: Vec<WorkflowRun> = pages
Expand Down Expand Up @@ -136,8 +131,7 @@ impl Artifact for WorkflowRunArtifact {

pub fn get_workflow_run_artifacts(run_id: u64) -> Result<Vec<WorkflowRunArtifact>> {
let artifacts: WorkflowRunArtifacts = make_request(&format!(
"https://api.github.com/repos/endless-sky/endless-sky/actions/runs/{}/artifacts",
run_id
"https://api.github.com/repos/endless-sky/endless-sky/actions/runs/{run_id}/artifacts"
))?;
info!(
"Got {} artifacts for workflow run {}",
Expand All @@ -158,8 +152,7 @@ pub struct GitObject {

pub fn get_git_ref(name: &str) -> Result<GitRef> {
make_request(&format!(
"https://api.github.com/repos/endless-sky/endless-sky/git/ref/{}",
name
"https://api.github.com/repos/endless-sky/endless-sky/git/ref/{name}"
))
}

Expand All @@ -171,13 +164,12 @@ pub struct Release {

pub fn get_release_by_tag(tag: &str) -> Result<Release> {
make_request(&format!(
"https://api.github.com/repos/endless-sky/endless-sky/releases/tags/{}",
tag
"https://api.github.com/repos/endless-sky/endless-sky/releases/tags/{tag}"
))
}

pub fn get_latest_release(repo_slug: &str) -> Result<String> {
let url = &format!("https://github.com/{}/releases/latest", repo_slug);
let url = &format!("https://github.com/{repo_slug}/releases/latest");
let res = ureq::get(url).call()?;

if res.status() >= 400 {
Expand All @@ -186,7 +178,7 @@ pub fn get_latest_release(repo_slug: &str) -> Result<String> {
res.status(),
res.status_text(),
url,
)
);
};

Ok(res.get_url().rsplit_once('/').unwrap().1.to_string())
Expand Down Expand Up @@ -214,8 +206,7 @@ impl Artifact for ReleaseAsset {

pub fn get_release_assets(release_id: i64) -> Result<Vec<ReleaseAsset>> {
let assets: ReleaseAssets = make_request(&format!(
"https://api.github.com/repos/endless-sky/endless-sky/releases/{}/assets",
release_id
"https://api.github.com/repos/endless-sky/endless-sky/releases/{release_id}/assets"
))?;
info!("Got {} assets for release {}", assets.0.len(), release_id);
Ok(assets.0)
Expand All @@ -231,7 +222,7 @@ fn make_request<T: DeserializeOwned>(url: &str) -> Result<T> {
res.status(),
res.status_text(),
url,
)
);
}
Ok(res.into_json()?)
}
Expand Down Expand Up @@ -281,7 +272,7 @@ fn check_ratelimit(res: &ureq::Response) {
};
}
} else if remaining < 10 {
warn!("Only {} github API requests remaining", remaining)
warn!("Only {} github API requests remaining", remaining);
}
}
Err(e) => warn!("Failed to parse X-RateLimit-Remaining Header: {}", e),
Expand Down
10 changes: 5 additions & 5 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn install(
mut instance_source: InstanceSource,
) -> Result<Instance> {
info!("Installing to {}", destination.to_string_lossy());
if let InstanceType::Unknown = instance_type {
if instance_type == InstanceType::Unknown {
return Err(anyhow!("Cannot install InstanceType::Unknown",));
}
send_progress_message(&name, "Preparing directories".into());
Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn install(
let mut executable_path = destination.clone();
executable_path.push(instance_type.executable().unwrap());

if let InstanceType::AppImage = instance_type {
if instance_type == InstanceType::AppImage {
fs::rename(&archive_file, &executable_path)?;
} else if cfg!(target_os = "macos") && archive_file.to_string_lossy().contains("dmg") {
send_progress_message(&name, "Processing DMG file".into());
Expand All @@ -81,7 +81,7 @@ pub fn install(

// TODO: Remove this after a while, only exists for backwards compatibility with pre-cmake PRs
if InstanceType::Windows == instance_type && !executable_path.exists() {
executable_path.set_file_name("EndlessSky.exe")
executable_path.set_file_name("EndlessSky.exe");
}

// upload-artifact doesn't preserve permissions, so we need to set the executable bit here
Expand Down Expand Up @@ -177,12 +177,12 @@ pub fn choose_artifact<A: Artifact>(artifacts: Vec<A>, instance_type: InstanceTy

#[cfg(unix)]
fn chmod_x(file: &PathBuf) {
if let Err(e) = fs::set_permissions(&file, PermissionsExt::from_mode(0o755)) {
if let Err(e) = fs::set_permissions(file, PermissionsExt::from_mode(0o755)) {
warn!(
"Failed to set executable bit for {}: {}",
file.to_string_lossy(),
e
)
);
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/install_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct InstanceSource {
impl Default for InstanceSource {
fn default() -> Self {
Self {
identifier: String::from(""),
identifier: String::new(),
r#type: InstanceSourceType::Continuous,
}
}
Expand All @@ -52,7 +52,7 @@ impl InstanceSourceType {

impl fmt::Display for InstanceSourceType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}

Expand All @@ -72,19 +72,19 @@ impl InstallFrame {
Message::Dummy,
);
} else {
error!("Could not get instances directory from AppDirs")
error!("Could not get instances directory from AppDirs");
}
}
InstallFrameMessage::SourceTypeChanged(source_type) => self.source.r#type = source_type,
InstallFrameMessage::NameChanged(name) => {
if let Some(invalid) = name.chars().rfind(|c| BLACKLISTED_CHARS.contains(c)) {
error!("Invalid character: '{}'", invalid)
error!("Invalid character: '{}'", invalid);
} else {
self.name = name
self.name = name;
}
}
InstallFrameMessage::SourceIdentifierChanged(identifier) => {
self.source.identifier = identifier
self.source.identifier = identifier;
}
}
Command::none()
Expand All @@ -95,7 +95,7 @@ impl InstallFrame {
Column::new().spacing(10).push(Text::new("Choose a Type:")),
|column, source_type| {
column.push(Radio::new(
format!("{:?}", source_type),
format!("{source_type:?}"),
*source_type,
Some(self.source.r#type),
InstallFrameMessage::SourceTypeChanged,
Expand All @@ -119,7 +119,7 @@ impl InstallFrame {
InstanceType::AppImage
} else {
InstanceType::MacOS
}))
}));
}

Container::new(Scrollable::new(
Expand Down
53 changes: 19 additions & 34 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub enum InstanceState {
Ready,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct Progress {
status: String,
done: Option<u32>,
Expand All @@ -75,18 +75,6 @@ pub struct Progress {
total_approx: bool,
}

impl Default for Progress {
fn default() -> Self {
Self {
status: "".into(),
done: None,
total: None,
units: None,
total_approx: false,
}
}
}

impl Progress {
pub fn total(mut self, total: impl Into<Option<u32>>) -> Self {
self.total = total.into();
Expand Down Expand Up @@ -117,13 +105,13 @@ impl<T: AsRef<str>> From<T> for Progress {

impl InstanceState {
pub fn is_playing(&self) -> bool {
matches!(self, InstanceState::Playing)
matches!(self, Self::Playing)
}
pub fn is_working(&self) -> bool {
matches!(self, InstanceState::Working { .. })
matches!(self, Self::Working { .. })
}
pub fn is_ready(&self) -> bool {
matches!(self, InstanceState::Ready)
matches!(self, Self::Ready)
}
}

Expand All @@ -147,13 +135,13 @@ impl Instance {
state: InstanceState,
) -> Self {
Self {
state,
path,
executable,
name,
version,
instance_type,
source,
state,
}
}

Expand All @@ -166,7 +154,7 @@ impl Instance {
iced::Command::batch(vec![
iced::Command::perform(dummy(), move |()| {
Message::InstanceMessage(
name1.to_string(),
name1,
InstanceMessage::StateChanged(InstanceState::Playing),
)
}),
Expand All @@ -179,7 +167,7 @@ impl Instance {
),
move |()| {
Message::InstanceMessage(
name2.to_string(),
name2,
InstanceMessage::StateChanged(InstanceState::Ready),
)
},
Expand All @@ -191,7 +179,7 @@ impl Instance {
iced::Command::batch(vec![
iced::Command::perform(dummy(), move |()| {
Message::InstanceMessage(
name.clone(),
name,
InstanceMessage::StateChanged(InstanceState::Working(
"Updating".into(),
)),
Expand All @@ -206,7 +194,7 @@ impl Instance {
InstanceMessage::Delete => {
let name = self.name.clone();
iced::Command::perform(delete(self.path.clone()), move |_| {
Message::RemoveInstance(Some(name.clone()))
Message::RemoveInstance(Some(name))
})
}
InstanceMessage::StateChanged(state) => {
Expand Down Expand Up @@ -271,15 +259,12 @@ impl Instance {
"{}/{}{}{}",
done,
if progress.total_approx { "~" } else { "" },
progress
.total
.map(|u| u.to_string())
.unwrap_or_else(|| "?".into()),
progress.units.as_ref().unwrap_or(&"".into())
progress.total.map_or_else(|| "?".into(), |u| u.to_string()),
progress.units.as_ref().unwrap_or(&String::new())
))
.size(12)
.horizontal_alignment(alignment::Horizontal::Center),
)
);
}
Row::new()
.push(Space::with_width(Length::FillPortion(1)))
Expand All @@ -306,18 +291,18 @@ pub async fn perform_install(
instance_type: InstanceType,
instance_source: InstanceSource,
) {
send_message(Message::AddInstance(Instance::new(
send_message(Message::AddInstance(Box::new(Instance::new(
path.clone(),
"provisional".into(),
name.clone(),
instance_source.identifier.clone(),
instance_type,
instance_source.clone(),
InstanceState::Working(Progress::default()),
)));
))));
match install::install(path, name.clone(), instance_type, instance_source) {
Ok(instance) => {
send_message(Message::AddInstance(instance));
send_message(Message::AddInstance(Box::new(instance)));
}
Err(e) => {
error!("Install failed: {:#}", e);
Expand All @@ -329,7 +314,7 @@ pub async fn perform_install(
pub async fn open_folder(path: PathBuf) {
info!("Opening {} in file explorer", path.to_string_lossy());
if let Err(e) = open::that(path.as_path()) {
error!("Failed to open path: {}", e)
error!("Failed to open path: {}", e);
}
}

Expand All @@ -346,7 +331,7 @@ pub async fn delete(path: PathBuf) -> Option<PathBuf> {
pub async fn perform_update(instance: Instance) {
let name = instance.name.clone();
match update::update_instance(instance).await {
Ok(instance) => send_message(Message::AddInstance(instance)),
Ok(instance) => send_message(Message::AddInstance(Box::new(instance))),
Err(e) => {
error!("Failed to update instance: {:#}", e);
send_message(Message::InstanceMessage(
Expand Down Expand Up @@ -374,11 +359,11 @@ pub async fn play(path: PathBuf, executable: PathBuf, name: String, do_debug: bo
"[year]-[month]-[day] [hour]-[minute]-[second]",
)?)?;
let mut out_path = log_path.clone();
out_path.push(format!("{}.out", time));
out_path.push(format!("{time}.out"));
let mut out = File::create(out_path)?;

let mut err_path = log_path.clone();
err_path.push(format!("{}.err", time));
err_path.push(format!("{time}.err"));
let mut err = File::create(err_path)?;

info!(
Expand Down
Loading

0 comments on commit debc629

Please sign in to comment.