#include <bundle_cpp.h>
#include "theme/dbus/command.h"
+#include "theme/dbus/request_broker.h"
#include "theme/loader/theme_info.h"
#include "theme/utils/logging.h"
#include "theme_provider/theme_info_proxy.h"
bool PackageEventRequestHandler::UninstallTheme(
const loader::ThemeInfo& theme) {
- return proxy_->RemoveTheme(theme.GetId());
+ bool cur_uninstalled = false;
+ auto cur = proxy_->GetLoadedTheme();
+ if (cur) {
+ if (cur->GetId() == theme.GetId())
+ cur_uninstalled = true;
+ }
+
+ if (!proxy_->RemoveTheme(theme.GetId()))
+ return false;
+
+ if (cur_uninstalled) {
+ auto default_theme = proxy_->GetDefaultTheme();
+ if (default_theme) {
+ if (!proxy_->SetCurrentTheme(default_theme->GetId())) {
+ LOG(ERROR) << "Failed to set default theme as current theme";
+ // return true, we removed theme successfully anyway
+ return true;
+ }
+ // send a signal the current theme changed as default theme
+ if (!dbus::RequestBroker::GetInst().EmitSignal("changed",
+ dbus::Command::CHANGED, default_theme->Serialize()))
+ LOG(ERROR) << "Failed to send theme changed signal";
+ }
+ }
+
+ return true;
}
} // namespace provider