update 2024-07-24 14:14:04

This commit is contained in:
kenzok8 2024-07-24 14:14:04 +08:00
parent 41dc81c56d
commit 9f59bc2d10
7 changed files with 104 additions and 74 deletions

View File

@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-airconnect
PKG_VERSION:=1.0.0
PKG_VERSION:=1.0.1
PKG_RELEASE:=1
LUCI_TITLE:=LuCI support for AirConnect

View File

@ -0,0 +1,80 @@
'use strict';
'require form';
'require poll';
'require rpc';
'require uci';
'require view';
'require tools.widgets as widgets';
var callServiceList = rpc.declare({
object: 'service',
method: 'list',
params: ['name'],
expect: { '': {} }
});
function getServiceStatus() {
return L.resolveDefault(callServiceList('airconnect'), {}).then(function (res) {
var isRunning = false;
try {
isRunning = res['airconnect']['instances']['airupnp']['running'] || res['airconnect']['instances']['aircast']['running'];
} catch (e) { }
return isRunning;
});
}
function renderStatus(isRunning) {
var spanTemp = '<em><span style="color:%s"><strong>%s %s</strong></span></em>';
var renderHTML;
if (isRunning) {
renderHTML = spanTemp.format('green', 'AirConnect', _('RUNNING'));
} else {
renderHTML = spanTemp.format('red', 'AirConnect', _('NOT RUNNING'));
}
return renderHTML;
}
return view.extend({
render: function() {
var m, s, o;
m = new form.Map('airconnect', _('AirConnect'),
_('Send audio to UPnP/Sonos/Chromecast players using AirPlay.'));
s = m.section(form.TypedSection);
s.anonymous = true;
s.render = function () {
poll.add(function () {
return L.resolveDefault(getServiceStatus()).then(function (res) {
var view = document.getElementById('service_status');
view.innerHTML = renderStatus(res);
});
});
return E('div', { class: 'cbi-section', id: 'status_bar' }, [
E('p', { id: 'service_status' }, _('Collecting data...'))
]);
}
s = m.section(form.NamedSection, 'config', 'airconnect');
o = s.option(form.Flag, 'enabled', _('Enabled'));
o.default = o.disabled;
o.rmempty = false;
o = s.option(widgets.DeviceSelect, 'interface',
_('Bind interface'));
o.rmempty = false;
o = s.option(form.Flag, 'airupnp', _('UPnP/Sonos'), _('Enable UPnP/Sonos Device Support'));
o.default = o.disabled;
o.rmempty = false;
o = s.option(form.Flag, 'aircast', _('Chromecast'), _('Enable Chromecast Device Support'));
o.default = o.disabled;
o.rmempty = false;
return m.render();
}
});

View File

@ -1,20 +0,0 @@
module("luci.controller.airconnect", package.seeall)
function index()
if not nixio.fs.access("/etc/config/airconnect") then
return
end
local page = entry({"admin", "services", "airconnect"}, cbi("airconnect"), _("AirConnect"))
page.dependent = true
page.acl_depends = { "luci-app-airconnect" }
entry({"admin", "services", "airconnect", "status"}, call("act_status")).leaf = true
end
function act_status()
local e = {}
e.running = luci.sys.call("pgrep aircast >/dev/null") == 0 or luci.sys.call("pgrep airupnp >/dev/null") == 0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end

View File

@ -1,30 +0,0 @@
local i = require 'luci.sys'
local m, e
m = Map('airconnect', translate('AirConnect'))
m.description = translate('Send audio to UPnP/Sonos/Chromecast players using AirPlay.')
m:section(SimpleSection).template = 'airconnect/airconnect_status'
e = m:section(TypedSection, 'airconnect')
e.addremove = false
e.anonymous = true
o = e:option(Flag, 'enabled', translate('Enabled'))
o.rmempty = false
o = e:option(Value, 'interface', translate('Bind interface'))
for t, e in ipairs(i.net.devices()) do
if e ~= 'lo' and not string.match(e, '^docker.*$') and not string.match(e, '^sit.*$') and not string.match(e, '^dummy.*$') and not string.match(e, '^teql.*$') and not string.match(e, '^veth.*$') and not string.match(e, '^ztly.*$') then
o:value(e)
end
end
o.rmempty = false
o = e:option(Flag, 'airupnp', translate('UPnP/Sonos'), translate('Enable UPnP/Sonos Device Support'))
o.rmempty = false
o = e:option(Flag, 'aircast', translate('Chromecast'), translate('Enable Chromecast Device Support'))
o.rmempty = false
return m

View File

@ -1,23 +0,0 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(1, '<%=url([[admin]], [[services]], [[airconnect]], [[status]])%>', null,
function(x, data) {
var tb = document.getElementById('airconnect_status');
if (data && tb) {
if (data.running) {
var links = '<em style=\"color:green\"><b>AirConnect <%:RUNNING%></b></em>';
tb.innerHTML = links;
} else {
tb.innerHTML = '<em style=\"color:red\"><b>AirConnect <%:NOT RUNNING%></b></em>';
}
}
}
);
//]]>
</script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<p id="airconnect_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>

View File

@ -1,3 +1,13 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: PACKAGE VERSION\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: zh_Hans\n"
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "AirConnect"
msgstr "隔空播放"

View File

@ -0,0 +1,13 @@
{
"admin/services/airconnect": {
"title": "AirConnect",
"action": {
"type": "view",
"path": "airconnect"
},
"depends": {
"acl": [ "luci-app-airconnect" ],
"uci": { "airconnect": true }
}
}
}