Skip to content

Commit eacbfde

Browse files
committed
Add userAgent property to IEngine
1 parent 59b91a6 commit eacbfde

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

include/scratchcpp/iengine.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ class LIBSCRATCHCPP_EXPORT IEngine
358358

359359
/*! Returns the map of scripts (each top level block has a Script object). */
360360
virtual const std::unordered_map<std::shared_ptr<Block>, std::shared_ptr<Script>> &scripts() const = 0;
361+
362+
/*! Returns the user agent of the last person to edit the project. */
363+
virtual const std::string &userAgent() const = 0;
364+
365+
/*! Sets the user agent of the last person to edit the project. */
366+
virtual void setUserAgent(const std::string &agent) = 0;
361367
};
362368

363369
} // namespace libscratchcpp

src/engine/internal/engine.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,16 @@ BlockSectionContainer *Engine::blockSectionContainer(IBlockSection *section) con
14301430
return nullptr;
14311431
}
14321432

1433+
const std::string &Engine::userAgent() const
1434+
{
1435+
return m_userAgent;
1436+
}
1437+
1438+
void Engine::setUserAgent(const std::string &agent)
1439+
{
1440+
m_userAgent = agent;
1441+
}
1442+
14331443
void Engine::finalize()
14341444
{
14351445
m_eventLoopMutex.lock();

src/engine/internal/engine.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ class Engine : public IEngine
157157
BlockSectionContainer *blockSectionContainer(const std::string &opcode) const;
158158
BlockSectionContainer *blockSectionContainer(IBlockSection *section) const;
159159

160+
const std::string &userAgent() const override;
161+
void setUserAgent(const std::string &agent) override;
162+
160163
IClock *m_clock = nullptr;
161164

162165
private:
@@ -227,6 +230,7 @@ class Engine : public IEngine
227230
std::unordered_map<std::shared_ptr<Block>, std::shared_ptr<Script>> m_scripts;
228231
std::vector<BlockFunc> m_functions;
229232
std::recursive_mutex m_eventLoopMutex;
233+
std::string m_userAgent;
230234

231235
std::unordered_map<Target *, std::vector<Script *>> m_greenFlagHats;
232236
std::unordered_map<Target *, std::vector<Script *>> m_backdropChangeHats;

test/engine/engine_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,15 @@ TEST(EngineTest, StopOtherScriptsInSprite)
17671767
ASSERT_EQ(GET_VAR(stage, "l")->value().toInt(), 110);
17681768
}
17691769

1770+
TEST(EngineTest, UserAgent)
1771+
{
1772+
Engine engine;
1773+
ASSERT_TRUE(engine.userAgent().empty());
1774+
1775+
engine.setUserAgent("test");
1776+
ASSERT_EQ(engine.userAgent(), "test");
1777+
}
1778+
17701779
TEST(EngineTest, NoCrashAfterStop)
17711780
{
17721781
// Regtest for #186

test/mocks/enginemock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ class EngineMock : public IEngine
134134
MOCK_METHOD(void, setExtensions, (const std::vector<std::string> &), (override));
135135

136136
MOCK_METHOD(const ScriptMap &, scripts, (), (const, override));
137+
138+
MOCK_METHOD(const std::string &, userAgent, (), (const, override));
139+
MOCK_METHOD(void, setUserAgent, (const std::string &), (override));
137140
};
138141

139142
} // namespace libscratchcpp

0 commit comments

Comments
 (0)