use v6.d;
use DB::SQLite;
use Vlc::Client;
use Lirc::Client;
use Lirc::Commands;
use App::MediaControl::DB;
use App::MediaControl::FS;
use App::MediaControl::Model;
use App::MediaControl::Web;
class App::MediaControl {
has $.config is required;
has Vlc::Client $!vlc;
has Lirc::Client $!lirc-client;
has Lirc::Commands $!lirc;
has App::MediaControl::DB $!db;
has App::MediaControl::FS $!fs;
has App::MediaControl::Model $!model;
has App::MediaControl::Web $!web;
submethod TWEAK {
$!vlc .= new(
password => $!config<vlc><password>,
base-uri => $!config<vlc><base-uri>,
mrl-root => $!config<media><root>,
);
$!lirc-client .= new();
$!lirc .= new(client=>$!lirc-client);
$!db .= new(
pool => DB::SQLite.new(
filename => $!config<db><filename>,
busy-timeout => 20_000,
),
);
$!fs .= new(
root => $!config<media><root>,
extensions => $!config<media><extensions>.Slip,
);
$!model .= new(:$!db,:$!fs);
$!web .= new(
port => $!config<server><port>,
host => $!config<server><host>,
:$!vlc, :$!lirc, :$!model,
);
}
method start() {
$!db.ensure-schema();
$!web.start();
}
method stop() {
$!web.stop();
}
}