Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooltips #199

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,640 changes: 805 additions & 835 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions mods-manager/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ pub async fn uninstall(mod_path: &Path, mods_directory: PathBuf) -> Result<(), s
mod tests {
use {
super::install,
crate::{ModName, Source},
crate::{tests::get_resource_path, ModName, Source},
tempdir::TempDir,
};
use crate::tests::get_resource_path;

#[tokio::test]
async fn test_install_zip() {
Expand Down
2 changes: 1 addition & 1 deletion mods-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ mod tests {
p.push(relative_path);
p
}
}
}
37 changes: 17 additions & 20 deletions mods-manager/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ pub async fn fetch_package(source: Source, directory: impl AsRef<Path>) -> Resul

extract_archive(&archive_file_path, &directory)?
}
Source::LocalArchive(archive_file_path) => {
extract_archive(&archive_file_path, &directory)?
}
Source::LocalArchive(archive_file_path) => extract_archive(&archive_file_path, &directory)?,
};

Ok(Package::open(package_root_directory)?)
Expand Down Expand Up @@ -128,18 +126,20 @@ mod archives {
fn extract_rar(archive_file_path: &Path, destination_directory: impl AsRef<Path>) -> Result<PathBuf, ArchiveError> {
let destination_directory = destination_directory.as_ref();

let mut archive =
unrar::Archive::new(archive_file_path)
.open_for_processing()
.unwrap();
let mut archive = unrar::Archive::new(archive_file_path).open_for_processing().unwrap();

while let Some(header) = archive.read_header().map_err(|e| ArchiveError::ReadFailed(archive_file_path.to_path_buf(), Box::new(e)))? {
while let Some(header) = archive
.read_header()
.map_err(|e| ArchiveError::ReadFailed(archive_file_path.to_path_buf(), Box::new(e)))?
{
archive = if header.entry().is_file() {
header.extract_with_base(destination_directory)
.map_err(|e| ArchiveError::ReadFailed(archive_file_path.to_path_buf(), Box::new(e)))
?
header
.extract_with_base(destination_directory)
.map_err(|e| ArchiveError::ReadFailed(archive_file_path.to_path_buf(), Box::new(e)))?
} else {
header.skip().map_err(|e| ArchiveError::ReadFailed(archive_file_path.to_path_buf(), Box::new(e)))?
header
.skip()
.map_err(|e| ArchiveError::ReadFailed(archive_file_path.to_path_buf(), Box::new(e)))?
};
}

Expand Down Expand Up @@ -196,7 +196,8 @@ async fn download_url(url: &str, directory: impl AsRef<Path>) -> Result<PathBuf,
let directory = directory.as_ref();
let response = backoff::future::retry(backoff::ExponentialBackoff::default(), || async {
Ok(reqwest::get(url).await?)
}).await?;
})
.await?;
let file_name = get_file_name(url, &response).ok_or(FetchError::InvalidUrl(url.to_string()))?;
let archive_file_path = directory.join(file_name);
let content = response.bytes().await?;
Expand All @@ -209,15 +210,11 @@ async fn download_url(url: &str, directory: impl AsRef<Path>) -> Result<PathBuf,
#[cfg(test)]
mod tests {
use {
super::{extract_file_name, is_valid_filename_with_extension},
test_case::test_case,
};
use {
super::fetch_package,
crate::{ModName, Source},
super::{extract_file_name, fetch_package, is_valid_filename_with_extension},
crate::{tests::get_resource_path, ModName, Source},
tempdir::TempDir,
test_case::test_case,
};
use crate::tests::get_resource_path;

#[test_case(
"https://github.com/n0kk/ahud/archive/refs/heads/master.zip",
Expand Down
14 changes: 9 additions & 5 deletions teamwork-launcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ build = "build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies.iced]
version = "0.10.0"
features = ["tokio", "svg", "image", "lazy", "advanced"]

[dependencies.iced_aw]
version = "0.6.0"
default-features = false
features = ["floating_element", "number_input", "spinner"]

[dependencies]
teamwork = { path = "../teamwork" }
mods-manager = { path = "../mods-manager" }
iced = { version = "0.9.0", features = ["tokio", "svg", "image"] }
# For access to image::Data
iced_native = "0.10.1"
iced_lazy = "0.6.1"
iced_aw = { version = "0.5.2", default-features = false, features = ["floating_element", "number_input", "spinner"] }
thiserror = "1"
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = "1"
Expand Down
33 changes: 17 additions & 16 deletions teamwork-launcher/src/application/geolocation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::time::Duration;
use {
crate::application::{country::Country, message::CountryServiceMessage},
iced::{
Expand All @@ -12,6 +11,7 @@ use {
std::{
collections::{btree_map::Entry, BTreeMap},
net::Ipv4Addr,
time::Duration,
},
};

Expand Down Expand Up @@ -42,8 +42,14 @@ async fn locate(ip: &Ipv4Addr, timeout: Duration) -> Result<Country, Error> {

let url = format!("{}/{}", COUNTRY_IS_API_URL, ip);
let ip = ip.to_string();
let client = reqwest::Client::builder().timeout(timeout).build().map_err(|error| Error::new(ip.clone(), &error))?;
let raw_text = client.get(url).send().await
let client = reqwest::Client::builder()
.timeout(timeout)
.build()
.map_err(|error| Error::new(ip.clone(), &error))?;
let raw_text = client
.get(url)
.send()
.await
.map_err(|error| Error::new(ip.clone(), &error))?
.text()
.await
Expand Down Expand Up @@ -76,20 +82,15 @@ pub fn subscription() -> Subscription<CountryServiceMessage> {
let ip = receiver.select_next_some().await;

match cache.entry(ip) {
Entry::Vacant(vacant) => {
match locate(&ip, Duration::from_secs(10)).await {
Ok(country) => {
vacant.insert(country.clone());
(
CountryServiceMessage::CountryFound(ip, country),
State::Ready(receiver, cache),
)
}
Err(error) => {
(CountryServiceMessage::Error(ip, error),
State::Ready(receiver, cache))
},
Entry::Vacant(vacant) => match locate(&ip, Duration::from_secs(10)).await {
Ok(country) => {
vacant.insert(country.clone());
(
CountryServiceMessage::CountryFound(ip, country),
State::Ready(receiver, cache),
)
}
Err(error) => (CountryServiceMessage::Error(ip, error), State::Ready(receiver, cache)),
},
Entry::Occupied(occupied) => (
CountryServiceMessage::CountryFound(ip, occupied.get().clone()),
Expand Down
5 changes: 3 additions & 2 deletions teamwork-launcher/src/application/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use {
},
iced::{
futures::channel::mpsc::UnboundedSender,
widget::{image, pane_grid, scrollable::RelativeOffset},
widget::{image, pane_grid, scrollable::Viewport},
},
mods_manager::{Install, ModName, PackageEntry, Source},
std::{net::Ipv4Addr, path::PathBuf, sync::Arc, time::Duration},
Expand Down Expand Up @@ -196,8 +196,9 @@ pub enum Message {
CopyConnectionString(IpPort),
Bookmarked(IpPort, bool),
CopyToClipboard(String),
ServerListScroll(RelativeOffset),
ServerListScroll(Viewport),
Back,
FontLoaded(Result<(), iced::font::Error>),
}

impl From<FetchServersEvent> for Message {
Expand Down
33 changes: 23 additions & 10 deletions teamwork-launcher/src/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ use {
iced::{
futures::{channel::mpsc::UnboundedSender, FutureExt, SinkExt, TryFutureExt},
subscription, theme,
widget::{column, container, image, pane_grid, scrollable},
widget::{
column, container, image,
pane_grid::{self, Axis},
scrollable,
},
Command, Element, Renderer, Subscription, Theme,
},
iced_native::widget::pane_grid::Axis,
iced_views::Views,
itertools::Itertools,
log::{debug, error, trace},
Expand Down Expand Up @@ -182,6 +185,13 @@ impl iced::Application for TeamworkLauncher {

panes.resize(&panes_split, flags.user_settings.servers_filter_pane_ratio);

let initial_commands = Command::batch(vec![
mods_management::commands::scan_mods_directory(mods_directory),
iced::font::load(include_bytes!("../fonts/tf2build.ttf").as_slice()).map(Message::FontLoaded),
iced::font::load(include_bytes!("../fonts/TF2secondary.ttf").as_slice()).map(Message::FontLoaded),
iced::font::load(include_bytes!("../fonts/Lato-Regular.ttf").as_slice()).map(Message::FontLoaded),
]);

(
Self {
views: Views::new(Screens::Main),
Expand Down Expand Up @@ -216,7 +226,7 @@ impl iced::Application for TeamworkLauncher {
panes_split,
servers_list_view_mode: ViewMode::Normal,
},
mods_management::commands::scan_mods_directory(mods_directory),
initial_commands,
)
}

Expand Down Expand Up @@ -314,12 +324,17 @@ impl iced::Application for TeamworkLauncher {
self.screenshots.set(PromisedValue::Loading);
return screenshots::fetch_screenshot(map_name, self.user_settings.teamwork_api_key());
}
Message::ServerListScroll(position) => {
self.servers_list.scroll_position = position;
Message::ServerListScroll(viewport) => {
self.servers_list.scroll_position = viewport.relative_offset();
}
Message::ShowMods => {
self.views.push(Screens::Mods);
}
Message::FontLoaded(result) => {
if let Err(error) = result {
panic!("Failed to load font: {:?}", error);
}
}
}

Command::none()
Expand Down Expand Up @@ -426,10 +441,7 @@ impl TeamworkLauncher {
let ping_sender = self.ping_request_sender.as_mut().unwrap();

ping_sender
.send(PingRequest {
ip,
sort,
})
.send(PingRequest { ip, sort })
.unwrap_or_else(|e| error!("ping sender {}", e))
.now_or_never();

Expand Down Expand Up @@ -511,7 +523,8 @@ impl TeamworkLauncher {
unique_map_names.insert(server.map.clone());
}

let unique_ips: BTreeSet<Ipv4Addr> = BTreeSet::from_iter(servers_refs.iter().map(|server| server.ip_port.ip()).cloned());
let unique_ips: BTreeSet<Ipv4Addr> =
BTreeSet::from_iter(servers_refs.iter().map(|server| server.ip_port.ip()).cloned());

drop(servers_refs);

Expand Down
3 changes: 1 addition & 2 deletions teamwork-launcher/src/application/mods_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use {
screens::{AddModView, Screens},
Message, TeamworkLauncher,
},
iced::widget::text_input,
iced_native::Command,
iced::{widget::text_input, Command},
mods_manager::{Install, Source},
reqwest::Url,
};
Expand Down
3 changes: 1 addition & 2 deletions teamwork-launcher/src/application/thumbnail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use {
widget::image,
Subscription,
},
iced_native::image::Data,
log::{error, trace},
std::{
collections::BTreeMap,
Expand Down Expand Up @@ -161,7 +160,7 @@ impl ThumbnailCache {
break;
}

if let Data::Bytes(bytes) = handle.data() {
if let iced::advanced::image::Data::Bytes(bytes) = handle.data() {
let file_path = self.directory_path.join(map_name.as_str());

current_bytes += bytes.len() as u64;
Expand Down
Binary file added teamwork-launcher/src/fonts/Lato-Regular.ttf
Binary file not shown.
12 changes: 3 additions & 9 deletions teamwork-launcher/src/fonts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
use iced::Font;

pub const TF2_BUILD: Font = Font::External {
name: "TF2 build",
bytes: include_bytes!("tf2build.ttf"),
};

pub const TF2_SECONDARY: Font = Font::External {
name: "TF2 secondary",
bytes: include_bytes!("TF2secondary.ttf"),
};
pub const TF2_BUILD: Font = Font::with_name("TF2 Build");
pub const TF2_SECONDARY: Font = Font::with_name("TF2");
pub const DEFAULT_FONT: Font = Font::with_name("Lato");
8 changes: 6 additions & 2 deletions teamwork-launcher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn load_settings(testing_mode_enabled: bool) -> Settings<ApplicationFlags> {
let blacklist = read_file(configuration_directory.join("blacklist.json")).unwrap_or_default();
let mods = read_bin_file(configuration_directory.join("mods.registry")).unwrap_or_default();

if let Some(window_settings) = user_settings.window.clone() {
let mut settings = if let Some(window_settings) = user_settings.window.clone() {
let mut settings = Settings::with_flags(ApplicationFlags {
bookmarks,
user_settings,
Expand Down Expand Up @@ -135,7 +135,11 @@ fn load_settings(testing_mode_enabled: bool) -> Settings<ApplicationFlags> {
mods,
blacklist,
})
}
};

settings.default_font = fonts::DEFAULT_FONT;

settings
}

fn setup_logger(configuration_directory: &Path) -> Result<(), fern::InitError> {
Expand Down
12 changes: 4 additions & 8 deletions teamwork-launcher/src/ui/add_mod_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ use {
widget::{button, column, container, horizontal_space, row, text, text_input},
Alignment, Element, Length,
},
iced_aw::{floating_element::Anchor, native::FloatingElement, Spinner},
iced_aw::{floating_element::Anchor, native::FloatingElement},
mods_manager::Source,
};
use crate::ui::widgets::spinner;

pub fn view(context: &AddModView) -> Element<Message> {
match context.scanning {
true => container(
Spinner::new()
.circle_radius(4.0)
.width(Length::Fixed(64.0))
.height(Length::Fixed(64.0)),
)
true => container(spinner(Length::Fixed(64.0), 4.0))
.width(Length::Fill)
.height(Length::Fill)
.center_x()
Expand Down Expand Up @@ -58,7 +54,7 @@ pub fn view(context: &AddModView) -> Element<Message> {

let content = container(main_column).height(Length::Fill).center_y();

FloatingElement::new(content, || button("X").on_press(Message::Back).into())
FloatingElement::new(content, button("X").on_press(Message::Back))
.anchor(Anchor::NorthEast)
.into()
}
Expand Down
9 changes: 5 additions & 4 deletions teamwork-launcher/src/ui/blacklist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use {
icons,
ui::{self, buttons::svg_button},
},
iced::widget::{column, row, text, text_input},
iced_lazy::Component,
iced_native::Element,
iced::{
widget::{column, row, text, text_input, Component},
Element,
},
};

pub struct Blacklist<'l> {
Expand Down Expand Up @@ -85,6 +86,6 @@ impl<'a> Component<Message, iced::Renderer> for Blacklist<'a> {

impl<'a> From<Blacklist<'a>> for Element<'a, Message, iced::Renderer> {
fn from(blacklist: Blacklist<'a>) -> Self {
iced_lazy::component(blacklist)
iced::widget::component(blacklist)
}
}
Loading