applets: Pass in the LibraryAppletMode each applet's constructor

merge-requests/60/head
Morph 2021-02-06 02:31:13 +07:00
parent 0f40c8c634
commit d1e40dd244
13 changed files with 58 additions and 33 deletions

@ -1135,13 +1135,13 @@ ILibraryAppletCreator::~ILibraryAppletCreator() = default;
void ILibraryAppletCreator::CreateLibraryApplet(Kernel::HLERequestContext& ctx) { void ILibraryAppletCreator::CreateLibraryApplet(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
const auto applet_id = rp.PopRaw<Applets::AppletId>(); const auto applet_id = rp.PopRaw<Applets::AppletId>();
const auto applet_mode = rp.PopRaw<u32>(); const auto applet_mode = rp.PopRaw<Applets::LibraryAppletMode>();
LOG_DEBUG(Service_AM, "called with applet_id={:08X}, applet_mode={:08X}", applet_id, LOG_DEBUG(Service_AM, "called with applet_id={:08X}, applet_mode={:08X}", applet_id,
applet_mode); applet_mode);
const auto& applet_manager{system.GetAppletManager()}; const auto& applet_manager{system.GetAppletManager()};
const auto applet = applet_manager.GetApplet(applet_id); const auto applet = applet_manager.GetApplet(applet_id, applet_mode);
if (applet == nullptr) { if (applet == nullptr) {
LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id); LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id);

@ -241,31 +241,31 @@ void AppletManager::ClearAll() {
frontend = {}; frontend = {};
} }
std::shared_ptr<Applet> AppletManager::GetApplet(AppletId id) const { std::shared_ptr<Applet> AppletManager::GetApplet(AppletId id, LibraryAppletMode mode) const {
switch (id) { switch (id) {
case AppletId::Auth: case AppletId::Auth:
return std::make_shared<Auth>(system, *frontend.parental_controls); return std::make_shared<Auth>(system, mode, *frontend.parental_controls);
case AppletId::Controller: case AppletId::Controller:
return std::make_shared<Controller>(system, *frontend.controller); return std::make_shared<Controller>(system, mode, *frontend.controller);
case AppletId::Error: case AppletId::Error:
return std::make_shared<Error>(system, *frontend.error); return std::make_shared<Error>(system, mode, *frontend.error);
case AppletId::ProfileSelect: case AppletId::ProfileSelect:
return std::make_shared<ProfileSelect>(system, *frontend.profile_select); return std::make_shared<ProfileSelect>(system, mode, *frontend.profile_select);
case AppletId::SoftwareKeyboard: case AppletId::SoftwareKeyboard:
return std::make_shared<SoftwareKeyboard>(system, *frontend.software_keyboard); return std::make_shared<SoftwareKeyboard>(system, mode, *frontend.software_keyboard);
case AppletId::Web: case AppletId::Web:
case AppletId::Shop: case AppletId::Shop:
case AppletId::OfflineWeb: case AppletId::OfflineWeb:
case AppletId::LoginShare: case AppletId::LoginShare:
case AppletId::WebAuth: case AppletId::WebAuth:
return std::make_shared<WebBrowser>(system, *frontend.web_browser); return std::make_shared<WebBrowser>(system, mode, *frontend.web_browser);
case AppletId::PhotoViewer: case AppletId::PhotoViewer:
return std::make_shared<PhotoViewer>(system, *frontend.photo_viewer); return std::make_shared<PhotoViewer>(system, mode, *frontend.photo_viewer);
default: default:
UNIMPLEMENTED_MSG( UNIMPLEMENTED_MSG(
"No backend implementation exists for applet_id={:02X}! Falling back to stub applet.", "No backend implementation exists for applet_id={:02X}! Falling back to stub applet.",
static_cast<u8>(id)); static_cast<u8>(id));
return std::make_shared<StubApplet>(system, id); return std::make_shared<StubApplet>(system, id, mode);
} }
} }

@ -62,6 +62,14 @@ enum class AppletId : u32 {
MyPage = 0x1A, MyPage = 0x1A,
}; };
enum class LibraryAppletMode : u32 {
AllForeground = 0,
Background = 1,
NoUI = 2,
BackgroundIndirectDisplay = 3,
AllForegroundInitiallyHidden = 4,
};
class AppletDataBroker final { class AppletDataBroker final {
public: public:
explicit AppletDataBroker(Kernel::KernelCore& kernel_); explicit AppletDataBroker(Kernel::KernelCore& kernel_);
@ -200,7 +208,7 @@ public:
void SetDefaultAppletsIfMissing(); void SetDefaultAppletsIfMissing();
void ClearAll(); void ClearAll();
std::shared_ptr<Applet> GetApplet(AppletId id) const; std::shared_ptr<Applet> GetApplet(AppletId id, LibraryAppletMode mode) const;
private: private:
AppletFrontendSet frontend; AppletFrontendSet frontend;

@ -45,8 +45,9 @@ static Core::Frontend::ControllerParameters ConvertToFrontendParameters(
}; };
} }
Controller::Controller(Core::System& system_, const Core::Frontend::ControllerApplet& frontend_) Controller::Controller(Core::System& system_, LibraryAppletMode applet_mode_,
: Applet{system_.Kernel()}, frontend{frontend_}, system{system_} {} const Core::Frontend::ControllerApplet& frontend_)
: Applet{system_.Kernel()}, applet_mode{applet_mode_}, frontend{frontend_}, system{system_} {}
Controller::~Controller() = default; Controller::~Controller() = default;

@ -106,7 +106,8 @@ static_assert(sizeof(ControllerSupportResultInfo) == 0xC,
class Controller final : public Applet { class Controller final : public Applet {
public: public:
explicit Controller(Core::System& system_, const Core::Frontend::ControllerApplet& frontend_); explicit Controller(Core::System& system_, LibraryAppletMode applet_mode_,
const Core::Frontend::ControllerApplet& frontend_);
~Controller() override; ~Controller() override;
void Initialize() override; void Initialize() override;
@ -119,6 +120,7 @@ public:
void ConfigurationComplete(); void ConfigurationComplete();
private: private:
LibraryAppletMode applet_mode;
const Core::Frontend::ControllerApplet& frontend; const Core::Frontend::ControllerApplet& frontend;
Core::System& system; Core::System& system;

@ -86,8 +86,9 @@ ResultCode Decode64BitError(u64 error) {
} // Anonymous namespace } // Anonymous namespace
Error::Error(Core::System& system_, const Core::Frontend::ErrorApplet& frontend_) Error::Error(Core::System& system_, LibraryAppletMode applet_mode_,
: Applet{system_.Kernel()}, frontend{frontend_}, system{system_} {} const Core::Frontend::ErrorApplet& frontend_)
: Applet{system_.Kernel()}, applet_mode{applet_mode_}, frontend{frontend_}, system{system_} {}
Error::~Error() = default; Error::~Error() = default;

@ -25,7 +25,8 @@ enum class ErrorAppletMode : u8 {
class Error final : public Applet { class Error final : public Applet {
public: public:
explicit Error(Core::System& system_, const Core::Frontend::ErrorApplet& frontend_); explicit Error(Core::System& system_, LibraryAppletMode applet_mode_,
const Core::Frontend::ErrorApplet& frontend_);
~Error() override; ~Error() override;
void Initialize() override; void Initialize() override;
@ -40,6 +41,7 @@ public:
private: private:
union ErrorArguments; union ErrorArguments;
LibraryAppletMode applet_mode;
const Core::Frontend::ErrorApplet& frontend; const Core::Frontend::ErrorApplet& frontend;
ResultCode error_code = RESULT_SUCCESS; ResultCode error_code = RESULT_SUCCESS;
ErrorAppletMode mode = ErrorAppletMode::ShowError; ErrorAppletMode mode = ErrorAppletMode::ShowError;

@ -37,8 +37,9 @@ static void LogCurrentStorage(AppletDataBroker& broker, std::string_view prefix)
} }
} }
Auth::Auth(Core::System& system_, Core::Frontend::ParentalControlsApplet& frontend_) Auth::Auth(Core::System& system_, LibraryAppletMode applet_mode_,
: Applet{system_.Kernel()}, frontend{frontend_}, system{system_} {} Core::Frontend::ParentalControlsApplet& frontend_)
: Applet{system_.Kernel()}, applet_mode{applet_mode_}, frontend{frontend_}, system{system_} {}
Auth::~Auth() = default; Auth::~Auth() = default;
@ -152,8 +153,9 @@ void Auth::AuthFinished(bool is_successful) {
broker.SignalStateChanged(); broker.SignalStateChanged();
} }
PhotoViewer::PhotoViewer(Core::System& system_, const Core::Frontend::PhotoViewerApplet& frontend_) PhotoViewer::PhotoViewer(Core::System& system_, LibraryAppletMode applet_mode_,
: Applet{system_.Kernel()}, frontend{frontend_}, system{system_} {} const Core::Frontend::PhotoViewerApplet& frontend_)
: Applet{system_.Kernel()}, applet_mode{applet_mode_}, frontend{frontend_}, system{system_} {}
PhotoViewer::~PhotoViewer() = default; PhotoViewer::~PhotoViewer() = default;
@ -202,8 +204,8 @@ void PhotoViewer::ViewFinished() {
broker.SignalStateChanged(); broker.SignalStateChanged();
} }
StubApplet::StubApplet(Core::System& system_, AppletId id_) StubApplet::StubApplet(Core::System& system_, AppletId id_, LibraryAppletMode applet_mode_)
: Applet{system_.Kernel()}, id{id_}, system{system_} {} : Applet{system_.Kernel()}, id{id_}, applet_mode{applet_mode_}, system{system_} {}
StubApplet::~StubApplet() = default; StubApplet::~StubApplet() = default;

@ -20,7 +20,8 @@ enum class AuthAppletType : u32 {
class Auth final : public Applet { class Auth final : public Applet {
public: public:
explicit Auth(Core::System& system_, Core::Frontend::ParentalControlsApplet& frontend_); explicit Auth(Core::System& system_, LibraryAppletMode applet_mode_,
Core::Frontend::ParentalControlsApplet& frontend_);
~Auth() override; ~Auth() override;
void Initialize() override; void Initialize() override;
@ -32,6 +33,7 @@ public:
void AuthFinished(bool is_successful = true); void AuthFinished(bool is_successful = true);
private: private:
LibraryAppletMode applet_mode;
Core::Frontend::ParentalControlsApplet& frontend; Core::Frontend::ParentalControlsApplet& frontend;
Core::System& system; Core::System& system;
bool complete = false; bool complete = false;
@ -50,7 +52,8 @@ enum class PhotoViewerAppletMode : u8 {
class PhotoViewer final : public Applet { class PhotoViewer final : public Applet {
public: public:
explicit PhotoViewer(Core::System& system_, const Core::Frontend::PhotoViewerApplet& frontend_); explicit PhotoViewer(Core::System& system_, LibraryAppletMode applet_mode_,
const Core::Frontend::PhotoViewerApplet& frontend_);
~PhotoViewer() override; ~PhotoViewer() override;
void Initialize() override; void Initialize() override;
@ -62,6 +65,7 @@ public:
void ViewFinished(); void ViewFinished();
private: private:
LibraryAppletMode applet_mode;
const Core::Frontend::PhotoViewerApplet& frontend; const Core::Frontend::PhotoViewerApplet& frontend;
bool complete = false; bool complete = false;
PhotoViewerAppletMode mode = PhotoViewerAppletMode::CurrentApp; PhotoViewerAppletMode mode = PhotoViewerAppletMode::CurrentApp;
@ -70,7 +74,7 @@ private:
class StubApplet final : public Applet { class StubApplet final : public Applet {
public: public:
explicit StubApplet(Core::System& system_, AppletId id_); explicit StubApplet(Core::System& system_, AppletId id_, LibraryAppletMode applet_mode_);
~StubApplet() override; ~StubApplet() override;
void Initialize() override; void Initialize() override;
@ -82,6 +86,7 @@ public:
private: private:
AppletId id; AppletId id;
LibraryAppletMode applet_mode;
Core::System& system; Core::System& system;
}; };

@ -15,9 +15,9 @@ namespace Service::AM::Applets {
constexpr ResultCode ERR_USER_CANCELLED_SELECTION{ErrorModule::Account, 1}; constexpr ResultCode ERR_USER_CANCELLED_SELECTION{ErrorModule::Account, 1};
ProfileSelect::ProfileSelect(Core::System& system_, ProfileSelect::ProfileSelect(Core::System& system_, LibraryAppletMode applet_mode_,
const Core::Frontend::ProfileSelectApplet& frontend_) const Core::Frontend::ProfileSelectApplet& frontend_)
: Applet{system_.Kernel()}, frontend{frontend_}, system{system_} {} : Applet{system_.Kernel()}, applet_mode{applet_mode_}, frontend{frontend_}, system{system_} {}
ProfileSelect::~ProfileSelect() = default; ProfileSelect::~ProfileSelect() = default;

@ -33,7 +33,7 @@ static_assert(sizeof(UserSelectionOutput) == 0x18, "UserSelectionOutput has inco
class ProfileSelect final : public Applet { class ProfileSelect final : public Applet {
public: public:
explicit ProfileSelect(Core::System& system_, explicit ProfileSelect(Core::System& system_, LibraryAppletMode applet_mode_,
const Core::Frontend::ProfileSelectApplet& frontend_); const Core::Frontend::ProfileSelectApplet& frontend_);
~ProfileSelect() override; ~ProfileSelect() override;
@ -47,6 +47,7 @@ public:
void SelectionComplete(std::optional<Common::UUID> uuid); void SelectionComplete(std::optional<Common::UUID> uuid);
private: private:
LibraryAppletMode applet_mode;
const Core::Frontend::ProfileSelectApplet& frontend; const Core::Frontend::ProfileSelectApplet& frontend;
UserSelectionConfig config; UserSelectionConfig config;

@ -208,8 +208,9 @@ void ExtractSharedFonts(Core::System& system) {
} // namespace } // namespace
WebBrowser::WebBrowser(Core::System& system_, const Core::Frontend::WebBrowserApplet& frontend_) WebBrowser::WebBrowser(Core::System& system_, LibraryAppletMode applet_mode_,
: Applet{system_.Kernel()}, frontend(frontend_), system{system_} {} const Core::Frontend::WebBrowserApplet& frontend_)
: Applet{system_.Kernel()}, applet_mode{applet_mode_}, frontend(frontend_), system{system_} {}
WebBrowser::~WebBrowser() = default; WebBrowser::~WebBrowser() = default;

@ -25,7 +25,8 @@ namespace Service::AM::Applets {
class WebBrowser final : public Applet { class WebBrowser final : public Applet {
public: public:
WebBrowser(Core::System& system_, const Core::Frontend::WebBrowserApplet& frontend_); WebBrowser(Core::System& system_, LibraryAppletMode applet_mode_,
const Core::Frontend::WebBrowserApplet& frontend_);
~WebBrowser() override; ~WebBrowser() override;
@ -63,6 +64,7 @@ private:
void ExecuteWifi(); void ExecuteWifi();
void ExecuteLobby(); void ExecuteLobby();
LibraryAppletMode applet_mode;
const Core::Frontend::WebBrowserApplet& frontend; const Core::Frontend::WebBrowserApplet& frontend;
bool complete{false}; bool complete{false};