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 24 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
53 changes: 45 additions & 8 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ iced_lazy = "0.6.1"
plotters-iced = "0.8.0"
maxminddb = "0.23.0"
confy = "0.5.1"
serde = { version = "1.0.175", default_features = false, features = ["derive"] }
serde = { version = "1.0.175", default_features = false, features = ["derive", "rc"] }
rodio = { version = "0.17.1", default_features = false, features = ["mp3"] }
reqwest = { version = "0.11.18", default-features = false, features = ["json", "blocking", "rustls-tls"] }
dns-lookup = "2.0.2"
toml = "0.7.4"

#───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

[dev-dependencies]
rstest = "0.18.1"
serde_test = "1.0.171"

#───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Expand Down
67 changes: 53 additions & 14 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 @@ -233,7 +233,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 @@ -255,13 +255,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 @@ -272,23 +272,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 @@ -360,6 +360,45 @@ 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 that may be loaded from anywhere. Themes support multilingual
descriptions.

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

[description]
EN = "Catppuccin is a colorful, medium contrast pastel theme.\nhttps://github.com/catppuccin/catppuccin"
# Contributed by Emilia
HU = "Catpuccin egy színes, közepes kontrasztú, pasztell téma.\nhttps://github.com/catppuccin/catppuccin"
# Contributed by Bartosz
PL = "Catppuccin to kolorowy i pastelowy motyw o średnim kontraście.\nhttps://github.com/catppuccin/catppuccin"

# Color palettes are in RGBA hexadecimal where the alpha is optional.
[palette]
primary = "#1e1e2e" # Base
secondary = "#89b4fa" # Blue
buttons = "#313244" # Surface0
incoming = "#89b4fa" # Blue
outgoing = "#f5c2e7" # Pink
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 Down Expand Up @@ -400,7 +439,7 @@ Reach out to me, and I'll try to generate an installer for your specific operati

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)
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**
Expand Down
20 changes: 20 additions & 0 deletions resources/themes/catppuccin_frappe.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://github.com/catppuccin/catppuccin
name = "Catppuccin (Frappé)"

[description]
EN = "Soothing pastel theme for the high-spirited!"
# Contributed by Bartosz
PL = "Kojący pastelowy motyw dla porywczych"

[palette]
primary = "#303446" # Base
secondary = "#a6d189" # Green
buttons = "#414559" # Surface0
outgoing = "#f4b8e4" # Pink
text_headers = "#232634" # Crust
text_body = "#c6d0f5" # Text
round_borders = "#99d1db" # Teal
round_containers = "#292c3c" # Mantle
starred = "#e5c890" # Yellow
badge_alpha = 0.75
color_mix_chart = 0.3
22 changes: 22 additions & 0 deletions resources/themes/catppuccin_latte.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://github.com/catppuccin/catppuccin
name = "Catppuccin (Latte)"

[description]
EN = "Soothing pastel theme for the high-spirited!"
# Contributed by Emilia
# HU = "Catpuccin egy színes, közepes kontrasztú, pasztell téma.\nhttps://github.com/catppuccin/catppuccin"
# Contributed by Bartosz
PL = "Kojący pastelowy motyw dla porywczych"

[palette]
primary = "#eff1f5" # Base
secondary = "#1e66f5" # Blue
buttons = "#ccd0da" # Surface0
outgoing = "#ea76cb" # Pink
text_headers = "#dce0e8" # Crust
text_body = "#4c4f69" # Text
round_borders = "#7287fd" # Lavender
round_containers = "#e6e9ef" # Mantle
starred = "#df8e1d" # Yellow
badge_alpha = 0.75
color_mix_chart = 0.3
20 changes: 20 additions & 0 deletions resources/themes/catppuccin_macchiato.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://github.com/catppuccin/catppuccin
name = "Catppuccin (Macchiato)"

[description]
EN = "Soothing pastel theme for the high-spirited!"
# Contributed by Bartosz
PL = "Kojący pastelowy motyw dla porywczych"

[palette]
primary = "#24273a" # Base
secondary = "#f5bde6" # Pink
buttons = "#363a4f" # Surface0
outgoing = "#c6a0f6" # Mauve
text_headers = "#181926" # Crust
text_body = "#cad3f5" # Text
round_borders = "#b7bdf8" # Lavender
round_containers = "#1e2030" # Mantle
starred = "#eed49f" # Yellow
badge_alpha = 0.75
color_mix_chart = 0.3
22 changes: 22 additions & 0 deletions resources/themes/catppuccin_mocha.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://github.com/catppuccin/catppuccin
name = "Catppuccin (Mocha)"

[description]
EN = "Soothing pastel theme for the high-spirited!"
# Contributed by Emilia
# HU = "Catpuccin egy színes, közepes kontrasztú, pasztell téma.\nhttps://github.com/catppuccin/catppuccin"
# Contributed by Bartosz
PL = "Kojący pastelowy motyw dla porywczych"

[palette]
primary = "#1e1e2e" # Base
secondary = "#89b4fa" # Blue
buttons = "#313244" # Surface0
outgoing = "#f5c2e7" # Pink
text_headers = "#11111b" # Crust
text_body = "#cdd6f4" # Text
round_borders = "#b4befe" # Lavender
round_containers = "#181825" # Mantle
starred = "#f9e2af" # Yellow
badge_alpha = 0.75
color_mix_chart = 0.3
18 changes: 18 additions & 0 deletions resources/themes/dracula.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://draculatheme.com/contribute
name = "Dracula"

[description]
EN = "Dark theme for high productivity"

[palette]
primary = "#44475a" # Current line
secondary = "#ff79c6" # Pink
buttons = "#6272a4" # Comment
outgoing = "#8be9fd" # Cyan
text_headers = "#44475a" # Current line
text_body = "#f8f8f2" # Foreground
round_borders = "#bd93f9" # Purple
round_containers = "#44475a" # Current line
starred = "#f1fa8c" # Yellow
badge_alpha = 0.75
color_mix_chart = 0.3
4 changes: 2 additions & 2 deletions src/chart/types/traffic_chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct TrafficChart {
}

impl TrafficChart {
pub fn new(style: StyleType, language: Language) -> Self {
pub fn new(style: &StyleType, language: Language) -> Self {
TrafficChart {
ticks: 0,
sent_bytes: VecDeque::default(),
Expand Down Expand Up @@ -89,7 +89,7 @@ impl TrafficChart {
self.language = language;
}

pub fn change_colors(&mut self, style: StyleType) {
pub fn change_colors(&mut self, style: &StyleType) {
self.color_font = to_rgb_color(get_colors(style).text_body);
self.color_incoming = to_rgb_color(get_colors(style).secondary);
self.color_outgoing = to_rgb_color(get_colors(style).outgoing);
Expand Down
Loading