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

@ -1,21 +1,21 @@
name: Upload rock to LuaRocks name: Upload rock to LuaRocks
on: on:
push: push:
jobs: jobs:
affected: affected:
uses: lunarmodules/.github/.github/workflows/list_affected_rockspecs.yml@main uses: lunarmodules/.github/.github/workflows/list_affected_rockspecs.yml@main
upload: upload:
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
}} }}
uses: lunarmodules/.github/.github/workflows/upload_to_luarocks.yml@main uses: lunarmodules/.github/.github/workflows/upload_to_luarocks.yml@main
with: with:
rockspecs: ${{ needs.affected.outputs.rockspecs }} rockspecs: ${{ needs.affected.outputs.rockspecs }}
secrets: secrets:
apikey: ${{ secrets.LUAROCKS_APIKEY }} apikey: ${{ secrets.LUAROCKS_APIKEY }}

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,34 +1,33 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- 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
function battery_widget.list_devices() function battery_widget.list_devices()
local ret = {} local ret = {}
local devices = upower.Client():get_devices() local devices = upower.Client():get_devices()
for _,d in ipairs(devices) do for _, d in ipairs(devices) do
table.insert(ret, d:get_object_path()) table.insert(ret, d:get_object_path())
end end
return ret return ret
end end
--- Helper function to get a device instance from its path. --- Helper function to get a device instance from its path.
@ -36,23 +35,23 @@ end
-- @treturn UPowerGlib.Device|nil The device if it was found, `nil` otherwise. -- @treturn UPowerGlib.Device|nil The device if it was found, `nil` otherwise.
-- @staticfct battery_widget.get_device -- @staticfct battery_widget.get_device
function battery_widget.get_device(path) function battery_widget.get_device(path)
local devices = upower.Client():get_devices() local devices = upower.Client():get_devices()
for _,d in ipairs(devices) do for _, d in ipairs(devices) do
if d:get_object_path() == path then if d:get_object_path() == path then
return d return d
end end
end end
return nil return nil
end end
--- Helper function to easily get the default BAT0 device path without. --- Helper function to easily get the default BAT0 device path without.
-- @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
--- Helper function to convert seconds into a human readable clock string. --- Helper function to convert seconds into a human readable clock string.
@ -64,34 +63,31 @@ end
-- @treturn string The human readable generated clock string. -- @treturn string The human readable generated clock string.
-- @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.
local function default_template () 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
@ -106,35 +102,33 @@ end
-- widget creation. -- widget creation.
-- @treturn battery_widget The battery_widget instance build. -- @treturn battery_widget The battery_widget instance build.
-- @constructorfct battery_widget.new -- @constructorfct battery_widget.new
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
return setmetatable(battery_widget, mt) return setmetatable(battery_widget, mt)