Add -noinapp option to disable Steam "in game" visibility (fix #4314)

Some minor changes in this commit includes the usage of
std::unique_ptr for the Pimpl-idiom in steam::SteamAPI class and
renaming the SteamAPI::initialized() to SteamAPI::isInitialized() to
avoid confusion reading the code.

Forum post:
https://steamcommunity.com/app/431730/discussions/2/7260435303111061192/
This commit is contained in:
David Capello 2024-02-21 12:47:27 -03:00
parent 5337a728be
commit 0d5075ff93
7 changed files with 53 additions and 17 deletions

View File

@ -775,7 +775,10 @@ if(ENABLE_UPDATER)
endif()
if(ENABLE_STEAM)
add_definitions(-DENABLE_STEAM)
# We need the ENABLE_STEAM flag in main module too so AppOptions are
# equal in both modules, app-lib and main (that's why this flag is
# marked as PUBLIC).
target_compile_definitions(app-lib PUBLIC -DENABLE_STEAM)
target_link_libraries(app-lib steam-lib)
endif()

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -328,6 +328,11 @@ int App::initialize(const AppOptions& options)
app_configure_drm();
#endif
#ifdef ENABLE_STEAM
if (options.noInApp())
m_inAppSteam = false;
#endif
// Load modules
m_modules = std::make_unique<Modules>(createLogInDesktop, preferences());
m_legacy = std::make_unique<LegacyModules>(isGui() ? REQUIRE_INTERFACE: 0);
@ -510,9 +515,18 @@ void App::run()
// Initialize Steam API
#ifdef ENABLE_STEAM
steam::SteamAPI steam;
if (steam.initialized())
os::instance()->activateApp();
std::unique_ptr<steam::SteamAPI> steam;
if (m_inAppSteam) {
steam = std::make_unique<steam::SteamAPI>();
if (steam->isInitialized())
os::instance()->activateApp();
}
else {
// We tried to load the Steam SDK without calling
// SteamAPI_InitSafe() to check if we could run the program
// without "in game" indication but still capturing screenshots
// on Steam, and that wasn't the case.
}
#endif
#if defined(_DEBUG) || defined(ENABLE_DEVMODE)

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -142,6 +142,9 @@ namespace app {
std::unique_ptr<LegacyModules> m_legacy;
bool m_isGui;
bool m_isShell;
#ifdef ENABLE_STEAM
bool m_inAppSteam = true;
#endif
std::unique_ptr<MainWindow> m_mainWindow;
base::paths m_files;
#ifdef ENABLE_UI

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -79,6 +79,9 @@ AppOptions::AppOptions(int argc, const char* argv[])
, m_exportTileset(m_po.add("export-tileset").description("Export only tilesets from visible tilemap layers"))
, m_verbose(m_po.add("verbose").mnemonic('v').description("Explain what is being done"))
, m_debug(m_po.add("debug").description("Extreme verbose mode and\ncopy log to desktop"))
#ifdef ENABLE_STEAM
, m_noInApp(m_po.add("noinapp").description("Disable \"in game\" visibility on Steam\nDoesn't count playtime"))
#endif
#ifdef _WIN32
, m_disableWintab(m_po.add("disable-wintab").description("Don't load wintab32.dll library"))
#endif
@ -121,6 +124,13 @@ bool AppOptions::hasExporterParams() const
m_po.enabled(m_sheet);
}
#ifdef ENABLE_STEAM
bool AppOptions::noInApp() const
{
return m_po.enabled(m_noInApp);
}
#endif
#ifdef _WIN32
bool AppOptions::disableWintab() const
{

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -95,6 +95,9 @@ public:
const Option& exportTileset() const { return m_exportTileset; }
bool hasExporterParams() const;
#ifdef ENABLE_STEAM
bool noInApp() const;
#endif
#ifdef _WIN32
bool disableWintab() const;
#endif
@ -166,6 +169,9 @@ private:
Option& m_verbose;
Option& m_debug;
#ifdef ENABLE_STEAM
Option& m_noInApp;
#endif
#ifdef _WIN32
Option& m_disableWintab;
#endif

View File

@ -134,7 +134,7 @@ public:
unloadLib();
}
bool initialized() const {
bool isInitialized() const {
return m_initialized;
}
@ -239,7 +239,7 @@ SteamAPI* SteamAPI::instance()
}
SteamAPI::SteamAPI()
: m_impl(new Impl)
: m_impl(std::make_unique<Impl>())
{
ASSERT(g_instance == nullptr);
g_instance = this;
@ -247,15 +247,13 @@ SteamAPI::SteamAPI()
SteamAPI::~SteamAPI()
{
delete m_impl;
ASSERT(g_instance == this);
g_instance = nullptr;
}
bool SteamAPI::initialized() const
bool SteamAPI::isInitialized() const
{
return m_impl->initialized();
return m_impl->isInitialized();
}
void SteamAPI::runCallbacks()

View File

@ -1,5 +1,5 @@
// Aseprite Steam Wrapper
// Copyright (c) 2020 Igara Studio S.A.
// Copyright (c) 2020-2024 Igara Studio S.A.
// Copyright (c) 2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -9,6 +9,8 @@
#define STEAM_STEAM_H_INCLUDED
#pragma once
#include <memory>
namespace steam {
class SteamAPI {
@ -18,7 +20,7 @@ public:
SteamAPI();
~SteamAPI();
bool initialized() const;
bool isInitialized() const;
void runCallbacks();
bool writeScreenshot(void* rgbBuffer,
@ -27,7 +29,7 @@ public:
private:
class Impl;
Impl* m_impl;
std::unique_ptr<Impl> m_impl;
};
} // namespace steam