Allow disabling themes

This commit is contained in:
Jill Stingray 2020-06-14 14:08:50 +03:00
parent ebc618452f
commit c18ceae61c
2 changed files with 15 additions and 7 deletions

View file

@ -7,13 +7,15 @@ class Themepack
private $ver; private $ver;
private $meta; private $meta;
private $home; private $home;
private $enabled;
function __construct(string $id, string $ver, object $meta) function __construct(string $id, string $ver, bool $enabled, object $meta)
{ {
$this->id = $id; $this->id = $id;
$this->ver = $ver; $this->ver = $ver;
$this->meta = $meta; $this->meta = $meta;
$this->home = OPENVK_ROOT . "/themepacks/$id"; $this->home = OPENVK_ROOT . "/themepacks/$id";
$this->enabled = $enabled;
} }
function getId(): string function getId(): string
@ -21,6 +23,11 @@ class Themepack
return $this->id; return $this->id;
} }
function isEnabled(): bool
{
return $this->enabled;
}
function getName(?string $lang = NULL): string function getName(?string $lang = NULL): string
{ {
if(!$this->meta->name) if(!$this->meta->name)
@ -71,6 +78,6 @@ class Themepack
if($manifest->openvk_version > Themepacks::THEMPACK_ENGINE_VERSION) if($manifest->openvk_version > Themepacks::THEMPACK_ENGINE_VERSION)
throw new Exceptions\IncompatibleThemeException("Theme is built for newer OVK (themeEngine" . $manifest->openvk_version . ")"); throw new Exceptions\IncompatibleThemeException("Theme is built for newer OVK (themeEngine" . $manifest->openvk_version . ")");
return new static($manifest->id, $manifest->version, (object) $manifest->metadata); return new static($manifest->id, $manifest->version, (bool) ($manifest->enabled ?? true), (object) $manifest->metadata);
} }
} }

View file

@ -46,7 +46,8 @@ class Themepacks implements \ArrayAccess
function getThemeList(): \Traversable function getThemeList(): \Traversable
{ {
foreach($this->loadedThemepacks as $id => $theme) foreach($this->loadedThemepacks as $id => $theme)
yield $id => ($theme->getName(Session::i()->get("lang", "ru"))); if($theme->isEnabled())
yield $id => ($theme->getName(Session::i()->get("lang", "ru")));
} }
/* ArrayAccess */ /* ArrayAccess */