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

net: Use local variable devices instead of net.devices #559

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions widget/net.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ local string = string
local function factory(args)
args = args or {}

local net = { widget = args.widget or wibox.widget.textbox(), devices = {} }
local net = { widget = args.widget or wibox.widget.textbox() }
local devices = {}
local timeout = args.timeout or 2
local units = args.units or 1024 -- KB
local notify = args.notify or "on"
Expand Down Expand Up @@ -51,7 +52,7 @@ local function factory(args)

for _, dev in ipairs(net.iface) do
local dev_now = {}
local dev_before = net.devices[dev] or { last_t = 0, last_r = 0 }
local dev_before = devices[dev] or { last_t = 0, last_r = 0 }
local now_t = tonumber(helpers.first_line(string.format("/sys/class/net/%s/statistics/tx_bytes", dev)) or 0)
local now_r = tonumber(helpers.first_line(string.format("/sys/class/net/%s/statistics/rx_bytes", dev)) or 0)

Expand Down Expand Up @@ -85,7 +86,7 @@ local function factory(args)
dev_now.ethernet = false
end

net.devices[dev] = dev_now
devices[dev] = dev_now

-- Notify only once when connection is lost
if string.match(dev_now.carrier, "0") and notify == "on" and helpers.get_map(dev) then
Expand Down