init luarocks

This commit is contained in:
Aire-One 2024-10-31 21:19:34 +01:00
parent f147f9b4c8
commit 603204c064
5 changed files with 92 additions and 75 deletions

View File

@ -15,6 +15,7 @@
"luacheckrc", "luacheckrc",
"luadoc", "luadoc",
"luarocks", "luarocks",
"lunarmodules",
"mktemp", "mktemp",
"mousegrabber", "mousegrabber",
"rockspec", "rockspec",

View File

@ -46,6 +46,6 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: leafo/gh-actions-lua@v9 - uses: luarocks/gh-actions-lua@v10
- uses: leafo/gh-actions-luarocks@v4 - uses: luarocks/gh-actions-luarocks@v5
- run: luarocks lint awesome-slot-dev-1.rockspec - run: luarocks lint awesome-battery_widget-dev-1.rockspec

View File

@ -10,7 +10,7 @@ jobs:
needs: affected needs: affected
if: >- if: >-
${{ ${{
github.repository == 'Aire-One/awesome-slot' && github.repository == 'Aire-One/awesome-battery_widget' &&
( github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/') ) && ( github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/') ) &&
needs.affected.outputs.rockspecs needs.affected.outputs.rockspecs
}} }}

View File

@ -0,0 +1,22 @@
package = "awesome-battery_widget"
version = "dev-1"
source = {
url = "git+https://github.com/Aire-One/awesome-battery_widget.git",
}
description = {
summary = "A UPowerGlib based battery widget for the Awesome WM with a basic widget template mechanism! 🔋",
homepage = "https://github.com/Aire-One/awesome-battery_widget",
license = "*** please specify a license ***",
}
build = {
type = "builtin",
modules = {
["awesome-battery_widget.init"] = "src/awesome-battery_widget/init.lua",
},
copy_directories = {
"doc",
},
}

View File

@ -1,22 +1,21 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- A battery widget based on the UPower deamon. -- A battery widget based on the UPower daemon.
-- --
-- @author Aire-One -- @author Aire-One
-- @copyright 2020 Aire-One -- @copyright 2020 Aire-One
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
local upower = require('lgi').require('UPowerGlib') local upower = require("lgi").require "UPowerGlib"
local gtable = require 'gears.table' local gtable = require "gears.table"
local gtimer = require 'gears.timer' local gtimer = require "gears.timer" -- cspell: ignore gtimer
local wbase = require 'wibox.widget.base' local wbase = require "wibox.widget.base" -- cspell: ignore wbase
local setmetatable = setmetatable -- luacheck: ignore setmetatable local setmetatable = setmetatable -- luacheck: ignore setmetatable
local battery_widget = {} local battery_widget = {}
local mt = {} local mt = {}
--- Helper to get the path of all connected power devices. --- Helper to get the path of all connected power devices.
-- @treturn table The list of all power devices path. -- @treturn table The list of all power devices path.
-- @staticfct battery_widget.list_devices -- @staticfct battery_widget.list_devices
@ -51,7 +50,7 @@ end
-- @treturn string The BAT0 device path. -- @treturn string The BAT0 device path.
-- @staticfct battery_widget.get_BAT0_device_path -- @staticfct battery_widget.get_BAT0_device_path
function battery_widget.get_BAT0_device_path() function battery_widget.get_BAT0_device_path()
local bat0_path = '/org/freedesktop/UPower/devices/battery_BAT0' local bat0_path = "/org/freedesktop/UPower/devices/battery_BAT0"
return bat0_path return bat0_path
end end
@ -65,15 +64,14 @@ end
-- @staticfct battery_widget.to_clock -- @staticfct battery_widget.to_clock
function battery_widget.to_clock(seconds) function battery_widget.to_clock(seconds)
if seconds <= 0 then if seconds <= 0 then
return '00:00'; return "00:00"
else else
local hours = string.format('%02.f', math.floor(seconds/3600)); local hours = string.format("%02.f", math.floor(seconds / 3600))
local mins = string.format('%02.f', math.floor(seconds/60 - hours*60)); local mins = string.format("%02.f", math.floor(seconds / 60 - hours * 60))
return hours .. ':' .. mins return hours .. ":" .. mins
end end
end end
--- Gives the default widget to use if user didn't specify one. --- Gives the default widget to use if user didn't specify one.
-- The default widget used is an `empty_widget` instance. -- The default widget used is an `empty_widget` instance.
-- @treturn widget The default widget to use. -- @treturn widget The default widget to use.
@ -81,17 +79,15 @@ local function default_template ()
return wbase.empty_widget() return wbase.empty_widget()
end end
--- The device monitored by the widget. --- The device monitored by the widget.
-- @property device -- @property device
-- @tparam UPowerGlib.Device device -- @tparam UPowerGlib.Device device
--- Emited when the UPower device notify an update. --- Emitted when the UPower device notify an update.
-- @signal upower::update -- @signal upower::update
-- @tparam battery_widget widget The widget. -- @tparam battery_widget widget The widget.
-- @tparam UPowerGlib.Device device The Upower device. -- @tparam UPowerGlib.Device device The Upower device.
--- battery_widget constructor. --- battery_widget constructor.
-- --
-- This function creates a new `battery_widget` instance. This widget watches -- This function creates a new `battery_widget` instance. This widget watches
@ -109,31 +105,29 @@ end
function battery_widget.new(args) function battery_widget.new(args)
args = gtable.crush({ args = gtable.crush({
widget_template = default_template(), widget_template = default_template(),
device_path = '', device_path = "",
use_display_device = false use_display_device = false,
}, args or {}) }, args or {})
local widget = wbase.make_widget_from_value(args.widget_template) local widget = wbase.make_widget_from_value(args.widget_template)
widget.device = args.use_display_device widget.device = args.use_display_device and upower.Client():get_display_device()
and upower.Client():get_display_device()
or battery_widget.get_device(args.device_path) or battery_widget.get_device(args.device_path)
-- Attach signals: -- Attach signals:
widget.device.on_notify = function(d) widget.device.on_notify = function(d)
widget:emit_signal('upower::update', d) widget:emit_signal("upower::update", d)
end end
-- Call an update cycle if the user asked to instan update the widget. -- Call an update cycle if the user asked to instant update the widget.
if args.instant_update then if args.instant_update then
gtimer.delayed_call(widget.emit_signal, widget, 'upower::update', widget.device) gtimer.delayed_call(widget.emit_signal, widget, "upower::update", widget.device)
end end
return widget return widget
end end
function mt.__call(_, ...)
function mt.__call(self, ...)
return battery_widget.new(...) return battery_widget.new(...)
end end