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

FEAT: Support custom TOML themes #286

Merged
merged 37 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e203503
Implement deserializing hex colors to iced::Color.
joshuamegnauth54 Jun 8, 2023
3e348cb
Merge branch 'main' of github.com:joshuamegnauth54/sniffnet into add_…
joshuamegnauth54 Jun 11, 2023
267f852
Merge branch 'main' of github.com:joshuamegnauth54/sniffnet into add_…
joshuamegnauth54 Jun 12, 2023
b7ced9b
Implement `CustomStyle` and test marshalling.
joshuamegnauth54 Jun 15, 2023
e7fa2f8
Clean up ser/de implementations for `Color`.
joshuamegnauth54 Jun 16, 2023
263205a
Support multilingual custom theme descriptions.
joshuamegnauth54 Jun 18, 2023
64efb61
Implement Hash for custom style types.
joshuamegnauth54 Jun 19, 2023
9540971
Replace `StyleType` with `Arc<StyleType>`.
joshuamegnauth54 Jun 22, 2023
3daee4d
Add a `TextInput` to load custom themes.
joshuamegnauth54 Jun 26, 2023
9399976
Update README.md with custom style info.
joshuamegnauth54 Jun 26, 2023
40274f7
Merge branch 'main' of github.com:joshuamegnauth54/sniffnet into add_…
joshuamegnauth54 Jun 26, 2023
1ec0c6e
Clean up: use iced::color!
joshuamegnauth54 Jun 27, 2023
5ad2626
Clean up: Simplify PartialEq impl for Color.
joshuamegnauth54 Jun 27, 2023
d35c578
Clean up: Derive PartialEq instead of implementing
joshuamegnauth54 Jun 28, 2023
cc1db3e
Fix serializing `StyleType::Custom`.
joshuamegnauth54 Jun 30, 2023
94fea30
Handle `CustomStyle` translations better.
joshuamegnauth54 Jul 3, 2023
7f5550b
Merge branch 'main' into add_themes
joshuamegnauth54 Jul 5, 2023
56c7f70
Impl `get_custom_styles` to load styles from a dir
joshuamegnauth54 Jul 9, 2023
ec863ea
Make the settings style page scrollable.
joshuamegnauth54 Jul 10, 2023
04b790a
Add and update Catppuccin styles.
joshuamegnauth54 Jul 11, 2023
773de55
Add unit test for `load_custom_styles`
joshuamegnauth54 Jul 11, 2023
0a66c57
Merge branch 'main' of github.com:joshuamegnauth54/sniffnet into add_…
joshuamegnauth54 Jul 11, 2023
e3d0d11
Make themes look a bit nicer.
joshuamegnauth54 Jul 27, 2023
e426574
Merge remote-tracking branch 'upstream/main' into add_themes
joshuamegnauth54 Jul 28, 2023
fedcda5
Merge 'upstream/advanced-settings' into add_themes
joshuamegnauth54 Sep 25, 2023
eb4c1ce
Clean up old custom style implementation.
joshuamegnauth54 Sep 26, 2023
e9e097f
Add `CustomToml` to `ExtraStyles`.
joshuamegnauth54 Sep 28, 2023
475856b
Add an element for loading custom styles
joshuamegnauth54 Sep 29, 2023
86e4efa
Implement Message::LoadStyle.
joshuamegnauth54 Sep 30, 2023
f32aa7c
Improve custom theme loading in GUI
joshuamegnauth54 Oct 1, 2023
6f320a8
Update readme to use the latest theme spec
joshuamegnauth54 Oct 1, 2023
30e1a01
Clean up tests and code.
joshuamegnauth54 Oct 2, 2023
09a9942
fix README
GyulyVGC Nov 10, 2023
46885a7
fix warnings and clippy lints
GyulyVGC Nov 10, 2023
8f62204
fix wrong nightly parameter for light themes
GyulyVGC Nov 10, 2023
ebb0252
undo derive Ord and PartialOrd for Language
GyulyVGC Nov 10, 2023
93ead04
fix: consistency in loading/storing styles
GyulyVGC Nov 12, 2023
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
54 changes: 51 additions & 3 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ confy = "0.5.1"
serde = { version = "1.0.188", default_features = false, features = ["derive"] }
rodio = { version = "0.17.1", default_features = false, features = ["mp3"] }
dns-lookup = "2.0.2"
toml = "0.8.0"

[target.'cfg(target_arch = "powerpc64")'.dependencies]
reqwest = { version = "0.11.20", features = ["json", "blocking"] }
Expand All @@ -55,6 +56,7 @@ reqwest = { version = "0.11.20", default-features = false, features = ["json", "
#───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

[dev-dependencies]
serde_test = "1.0.176"
rstest = "0.18.2"

#───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Expand Down
80 changes: 65 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<p align="center"><a href="https://www.sniffnet.net"><img alt="" src="https://github.com/GyulyVGC/sniffnet/blob/main/resources/repository/header_repository.png?raw=true" width="100%"/></a></p>

<p align="center">
<p align="center">
<a href="https://github.com/GyulyVGC/sniffnet/blob/main/LICENSE-APACHE"><img alt="" src="https://img.shields.io/crates/l/sniffnet?&color=orange"/></a>
&nbsp;
<a href="https://crates.io/crates/sniffnet"><img alt="" src="https://img.shields.io/crates/v/sniffnet?&logo=rust&color=blue"/></a> <br>
</p>

<p align="center">
<p align="center">
Application to comfortably monitor your Internet traffic <br>
Multithreaded, cross-platform, reliable <br>
🌐 <a href="https://www.sniffnet.net">www.sniffnet.net</a>
Expand Down Expand Up @@ -78,17 +78,17 @@ You can install Sniffnet in one of the following ways:
[32-bit](https://github.com/GyulyVGC/sniffnet/releases/latest/download/Sniffnet_Windows_32-bit.msi)

### macOS

- [Intel](https://github.com/GyulyVGC/sniffnet/releases/latest/download/Sniffnet_macOS_Intel.dmg) |
[Apple silicon](https://github.com/GyulyVGC/sniffnet/releases/latest/download/Sniffnet_macOS_AppleSilicon.dmg)

### Linux

- deb: [amd64](https://github.com/GyulyVGC/sniffnet/releases/latest/download/Sniffnet_LinuxDEB_amd64.deb) |
[arm64](https://github.com/GyulyVGC/sniffnet/releases/latest/download/Sniffnet_LinuxDEB_arm64.deb) |
[arm64](https://github.com/GyulyVGC/sniffnet/releases/latest/download/Sniffnet_LinuxDEB_arm64.deb) |
[i386](https://github.com/GyulyVGC/sniffnet/releases/latest/download/Sniffnet_LinuxDEB_i386.deb) |
[armhf](https://github.com/GyulyVGC/sniffnet/releases/latest/download/Sniffnet_LinuxDEB_armhf.deb)

- rpm: [x86_64](https://github.com/GyulyVGC/sniffnet/releases/latest/download/Sniffnet_LinuxRPM_x86_64.rpm) |
[aarch64](https://github.com/GyulyVGC/sniffnet/releases/latest/download/Sniffnet_LinuxRPM_aarch64.rpm)

Expand Down Expand Up @@ -245,7 +245,7 @@ sudo sniffnet
- 🌍 get information about the country of the remote hosts (IP geolocation)
- ⭐ save your favorite network hosts
- 🔉 set custom notifications to inform you when defined network events occur
- 🎨 choose the style that fits you the most from 4 different available themes
- 🎨 choose the style that fits you the most from 4 different available themes plus custom theme support
- 🕵️ inspect each of your network connections in real time
- 📁 save complete textual reports with detailed information for each network connection:
* source and destination IP addresses
Expand All @@ -267,13 +267,13 @@ sudo sniffnet
Geolocation and network providers (ASN) refer to the remote IP address of each connection. They are retrieved performing lookups against [MMDB files](https://maxmind.github.io/MaxMind-DB/):

> **Note**
>
>
> The MMDB (MaxMind database) format has been developed especially for IP lookup.<br>
> It is optimized to perform lookups on data indexed by IP network ranges quickly and efficiently.<br>
> It permits the best performance on IP lookups, and it's suitable for use in a production environment.
>
>
> This product includes GeoLite2 data created by MaxMind, available from <a href="https://www.maxmind.com">https://www.maxmind.com </a>

This file format potentially allows Sniffnet to execute hundreds of different IP lookups in a matter of a few milliseconds.

</details>
Expand All @@ -284,23 +284,23 @@ sudo sniffnet
<details>

<summary>See details</summary>

<br>

Application layer protocols are inferred from the transport port numbers,
following the convention maintained by [IANA](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml).

Please, remember that this is just a convention:

> **Warning**
>
>
> The Internet Assigned Numbers Authority (IANA) is responsible for maintaining
> the official assignments of port numbers for specific uses. <br>
> However, many unofficial uses of well-known port numbers occur in practice.

The following table reports the port-to-service mappings used by Sniffnet,
chosen from the most common assignments by IANA.

<div align="center">

|Port number(s)|Application protocol | Description |
Expand Down Expand Up @@ -372,6 +372,36 @@ The currently usable hotkeys are reported in the following.

</details>

## Custom themes
<details>

<summary>See details</summary>

Custom themes are specified as a TOML file.

The TOML must follow this format:
```toml
name = "Catppuccin (Mocha)"

# Color palettes are in RGBA hexadecimal where the alpha is optional.
[palette]
primary = "#1e1e2e" # Base
secondary = "#89b4fa" # Blue
outgoing = "#f5c2e7" # Pink
buttons = "#313244" # Surface0
text_headers = "#11111b" # Crust
text_body = "#cdd6f4" # Text
round_borders = "#74c7ec" # Sapphire
round_containers = "#585b70" # Surface 2
starred = "#f9e2af" # Yellow

# Alpha channels are floats within [0.0, 1.0]
badge_alpha = 0.75
color_mix_chart = 0.3
```

The example theme above uses colors from [Catppuccin Mocha](https://github.com/catppuccin/catppuccin).
</details>

## Troubleshooting

Expand All @@ -387,15 +417,35 @@ Check the [required dependencies](#required-dependencies) section for instructio

### Rendering problems

<<<<<<< HEAD
GyulyVGC marked this conversation as resolved.
Show resolved Hide resolved
In some cases, especially if you are running on an old architecture, the `wgpu` default renderer used by [iced](https://github.com/iced-rs/iced)
may cause some problems that could prevent you from running Sniffnet. <br>
In this case, you can try building the application from the [`glow-renderer`](https://github.com/GyulyVGC/sniffnet/tree/glow-renderer)
branch, which uses the `glow` renderer.

> **Note**
>
> View issues labeled with [`renderer`](https://github.com/GyulyVGC/sniffnet/issues?q=is%3Aissue+label%3Arenderer) to see how those problems have been solved by others.
||||||| ec3c96f
In some cases, especially if you are running on an old architecture, the `wgpu` default renderer used by [iced](https://github.com/iced-rs/iced)
may cause some problems that could prevent you from running Sniffnet. <br>
In this case, you can try building the application from the [`glow-renderer`](https://github.com/GyulyVGC/sniffnet/tree/glow-renderer)
branch, which uses the `glow` renderer.

> **Note**
>
> View issues labeled with [`renderer`](https://github.com/GyulyVGC/sniffnet/issues?q=is%3Aissue+label%3Arenderer) to see how those problems have been solved by others.
=======
In some circumstances, especially if you are running on an old architecture or your graphical drivers are not up-to-date,
the `wgpu` default renderer used by [iced](https://github.com/iced-rs/iced)
the `wgpu` default renderer used by [iced](https://github.com/iced-rs/iced)
may cause problems (country icons are completely black, or the interface glitches). <br>
In these cases you can download an alternative version of the application,
In these cases you can download an alternative version of the application,
which is based on `tiny-skia`, a CPU-only software renderer that should work properly on every environment: <br>
[Windows](https://github.com/GyulyVGC/sniffnet/suites/14909529200/artifacts/849640695) |
[macOS](https://github.com/GyulyVGC/sniffnet/suites/14909529200/artifacts/849640694) |
[Linux DEB](https://github.com/GyulyVGC/sniffnet/suites/14909529200/artifacts/849640693) |
[Linux RPM](https://github.com/GyulyVGC/sniffnet/suites/14909529200/artifacts/849640696)
>>>>>>> upstream/advanced-settings

### ***In any case don't hesitate to [open an issue](https://github.com/GyulyVGC/sniffnet/issues), and I will do my best to help you!***

Expand Down
12 changes: 12 additions & 0 deletions resources/themes/catppuccin_frappe.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://github.com/catppuccin/catppuccin
primary = "#303446" # Base
secondary = "#a6d189" # Green
buttons = "#414559" # Surface0
outgoing = "#f4b8e4" # Pink
text_headers = "#232634" # Crust
text_body = "#c6d0f5" # Text
starred = "#e5c890" # Yellow
round_borders_alpha = 0.1
round_containers_alpha = 0.04
chart_badge_alpha = 0.55
nightly = true
12 changes: 12 additions & 0 deletions resources/themes/catppuccin_latte.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://github.com/catppuccin/catppuccin"
primary = "#eff1f5" # Base
secondary = "#1e66f5" # Blue
buttons = "#ccd0da" # Surface0
outgoing = "#ea76cb" # Pink
text_headers = "#dce0e8" # Crust
text_body = "#4c4f69" # Text
starred = "#df8e1d" # Yellow
round_borders_alpha = 0.15
round_containers_alpha = 0.25
chart_badge_alpha = 0.75
nightly = false
12 changes: 12 additions & 0 deletions resources/themes/catppuccin_macchiato.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://github.com/catppuccin/catppuccin
primary = "#24273a" # Base
secondary = "#f5bde6" # Pink
buttons = "#363a4f" # Surface0
outgoing = "#c6a0f6" # Mauve
text_headers = "#181926" # Crust
text_body = "#cad3f5" # Text
starred = "#eed49f" # Yellow
round_borders_alpha = 0.1
round_containers_alpha = 0.15
chart_badge_alpha = 0.75
nightly = true
12 changes: 12 additions & 0 deletions resources/themes/catppuccin_mocha.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://github.com/catppuccin/catppuccin
primary = "#1e1e2e" # Base
secondary = "#89b4fa" # Blue
buttons = "#313244" # Surface0
outgoing = "#f5c2e7" # Pink
text_headers = "#11111b" # Crust
text_body = "#cdd6f4" # Text
starred = "#f9e2af" # Yellow
round_borders_alpha = 0.1
round_containers_alpha = 0.15
chart_badge_alpha = 0.75
nightly = true
11 changes: 11 additions & 0 deletions resources/themes/dracula.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
primary = "#44475a" # Current line
GyulyVGC marked this conversation as resolved.
Show resolved Hide resolved
secondary = "#ff79c6" # Pink
buttons = "#6272a4" # Comment
outgoing = "#8be9fd" # Cyan
text_headers = "#282a36" # Background
text_body = "#f8f8f2" # Foreground
starred = "#f1fa8cb2" # Yellow
round_borders_alpha = 0.1
round_containers_alpha = 0.04
chart_badge_alpha = 0.15
nightly = true
2 changes: 2 additions & 0 deletions src/configs/types/config_advanced_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct ConfigAdvancedSettings {
pub mmdb_country: String,
pub mmdb_asn: String,
pub output_path: PathBuf,
pub style_path: Option<PathBuf>
}

impl ConfigAdvancedSettings {
Expand Down Expand Up @@ -42,6 +43,7 @@ impl Default for ConfigAdvancedSettings {
mmdb_country: String::new(),
mmdb_asn: String::new(),
output_path: get_default_report_directory(),
style_path: None
}
}
}
18 changes: 16 additions & 2 deletions src/configs/types/configs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::gui::styles::types::custom_palette::{CustomPalette, ExtraStyles};
use crate::gui::styles::types::style_type::StyleType;
use crate::{ConfigAdvancedSettings, ConfigDevice, ConfigSettings, ConfigWindow};

#[derive(Default)]
Expand All @@ -10,10 +12,22 @@ pub struct Configs {

impl Configs {
pub fn load() -> Self {
let mut settings = ConfigSettings::load();
let advanced_settings = ConfigAdvancedSettings::load();

if let Some(style_path) = &advanced_settings.style_path {
// Don't clobber the previously set style if the path is broken
if let Ok(style) = CustomPalette::from_file(style_path)
.map(|palette| StyleType::Custom(ExtraStyles::CustomToml(palette)))
{
settings.style = style;
}
}

Configs {
settings: ConfigSettings::load(),
settings,
device: ConfigDevice::load(),
advanced_settings: ConfigAdvancedSettings::load(),
advanced_settings,
window: ConfigWindow::load(),
}
}
Expand Down
Loading