Skip to content

Conversation

devsnek
Copy link
Contributor

@devsnek devsnek commented Feb 29, 2020

Allows you to specify interface-type=wired/wireless instead of interface=ifname

Closes #339

@codecov
Copy link

codecov bot commented Feb 29, 2020

Codecov Report

Merging #2025 (4b6b690) into master (eb302f9) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2025      +/-   ##
=========================================
- Coverage    7.83%   7.80%   -0.04%     
=========================================
  Files         142     142              
  Lines       10299   10340      +41     
=========================================
  Hits          807     807              
- Misses       9492    9533      +41     
Flag Coverage Δ
unittests 7.80% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
include/adapters/net.hpp 0.00% <ø> (ø)
src/adapters/net.cpp 0.00% <0.00%> (ø)
src/modules/network.cpp 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb302f9...0af0364. Read the comment docs.

Copy link
Member

@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have often thought what it would take to make the network module automatically detect interfaces. And after reviewing this, I came to the conclusion that it is really hard.

You did a good job.

I think we should also check that interfaces aren't virtual when we search for wired or wireless interfaces to not accidentally select the loopback or tunnel interfaces.

As I noted in my comment below, this doesn't have to be perfect and take every edge case into account, it just has to be good enough to work for most people with "normal" setups and your code largely does that. We can always refine the code in the future if people report it not behaving as expected for them.

@devsnek devsnek force-pushed the autodetect-network-interface branch 2 times, most recently from e0af364 to 7465e6b Compare March 3, 2020 04:04
Copy link
Member

@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good. Still need to actually test it though ;)

@devsnek
Copy link
Contributor Author

devsnek commented Mar 4, 2020

@patrick96 how would i go about testing this?

@devsnek devsnek force-pushed the autodetect-network-interface branch from 7465e6b to f33df1c Compare March 4, 2020 03:41
@patrick96
Copy link
Member

Oh sorry. I meant I still need to test it.

@doronbehar

This comment has been minimized.

@doronbehar

This comment has been minimized.

@devsnek
Copy link
Contributor Author

devsnek commented Apr 16, 2020

@patrick96 did you ever get around to testing this?

@devsnek
Copy link
Contributor Author

devsnek commented Jun 23, 2020

@patrick96 bump

@devsnek
Copy link
Contributor Author

devsnek commented Aug 5, 2020

@patrick96 👀

@zampierilucas
Copy link

@patrick96 I would really love to see this go through, there's some way that I can help with testing it.

@KivalM
Copy link

KivalM commented Sep 24, 2020

@patrick96 Really looking forward to this addition.^^

@zampierilucas
Copy link

zampierilucas commented Sep 24, 2020

While we wait for this PR to go through, what a ended up doing was setting up my config file like

[module/network]
type = internal/network
interface = ${env:DEFAULT_NETWORK_INTERFACE}

and on .profile added
export DEFAULT_NETWORK_INTERFACE=`ip route | grep '^default' | awk '{print $5}' | head -n1`
So every time my .profile is sourced, the default interface is updated to the current one, If it changed.

@devsnek
Copy link
Contributor Author

devsnek commented Dec 6, 2020

@patrick96 ping again

@joaquingx
Copy link
Contributor

@joaquingx While we wait for this PR to go through, what a ended up doing was setting up my config file like

[module/network]
type = internal/network
interface = ${env:DEFAULT_NETWORK_INTERFACE}

and on .profile added
export DEFAULT_NETWORK_INTERFACE=`ip route | grep '^default' | awk '{print $5}' | head -n1`
So every time my .profile is sourced, the default interface is updated to the current one, If it changed.

Hey guys :), I suppose to tagging me here is a typo 😅, if possible please change it 🙏

@patrick96 patrick96 self-requested a review December 14, 2020 09:35
Copy link
Member

@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay

I tested the changes and everything seems to work fine.
I also added some small suggestions for error handling.

We recently started tracking the changelog directly in the repo (https://github.com/polybar/polybar/blob/master/CONTRIBUTING.md#changelog). Please add these changes to the changelog (you may need to rebase and force push for this).

I do have some thoughts about the default behavior of the module. But this doesn't have to happen in this PR.
Right now interface-type is required if interface is not specified.
I think, the module should work even if neither is specified. In that case it should just pick a wired or wireless interface.
If you want to work on this, let me know, otherwise I'll open an issue and let someone else take a stab at it.

@devsnek devsnek force-pushed the autodetect-network-interface branch from f33df1c to b91d67b Compare January 3, 2021 02:28
@devsnek
Copy link
Contributor Author

devsnek commented Jan 3, 2021

I think it would be good to leave the no-options config to a separate PR. imo that should try to find whichever interface is "active" which seems out of scope of this.

@devsnek devsnek force-pushed the autodetect-network-interface branch from b91d67b to 4b6b690 Compare January 3, 2021 02:34
@devsnek devsnek force-pushed the autodetect-network-interface branch from 4b6b690 to 0af0364 Compare January 3, 2021 02:34
@patrick96
Copy link
Member

I think it would be good to leave the no-options config to a separate PR. imo that should try to find whichever interface is "active" which seems out of scope of this.

You're right. I also didn't really think about the "active" part. I would have just taken the first available non-virtual interface. I am going to open a new issue for this.

Copy link
Member

@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good now.

Thanks! 🚀

@patrick96 patrick96 merged commit f7c2d83 into polybar:master Jan 3, 2021
@patrick96
Copy link
Member

I have decided against adding active interface detection. Most use cases for that can be covered with three modules:

[module/net-base]
format-disconnected = 
...

[module/net-wired]
inherit = module/net-base
interface-type = wired

[module/net-wireless]
inherit = module/net-base
interface-type = wireless

This will only show active interfaces as well.

@devsnek devsnek deleted the autodetect-network-interface branch January 3, 2021 15:08
@vertisan
Copy link

vertisan commented Feb 1, 2021

When it will be released?

@patrick96
Copy link
Member

Don't know yet

weirane added a commit to weirane/dotfiles that referenced this pull request Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

network module : dynamic interface
7 participants