From bb046666fc6c5897de643450e5c13e8359897ef5 Mon Sep 17 00:00:00 2001 From: tobias <thinkdifferent055@gmail.com> Date: Thu, 12 Oct 2023 22:41:39 +0200 Subject: [PATCH] #195 - Add method to fetch current page over web api --- .../plugin/api/websocket/WebSocketHandler.scala | 3 ++- .../methods/CurrentPageRequestMethod.scala | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/methods/CurrentPageRequestMethod.scala diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/WebSocketHandler.scala b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/WebSocketHandler.scala index 8a67fc24..1b89cdf4 100644 --- a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/WebSocketHandler.scala +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/WebSocketHandler.scala @@ -22,7 +22,8 @@ class WebSocketHandler { "cart-action" -> new CartActionMethod, "page-action" -> new PageActionMethod, "navigate-action" -> new NavigateActionMethod, - "stop-action" -> new StopActionMethod + "stop-action" -> new StopActionMethod, + "current-page-request" -> new CurrentPageRequestMethod ) @OnWebSocketConnect def connected(session: Session): Unit = { diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/methods/CurrentPageRequestMethod.scala b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/methods/CurrentPageRequestMethod.scala new file mode 100644 index 00000000..8e2a399a --- /dev/null +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/methods/CurrentPageRequestMethod.scala @@ -0,0 +1,16 @@ +package de.tobias.playpad.plugin.api.websocket.methods + +import com.google.gson.JsonObject +import de.tobias.playpad.PlayPadPlugin +import de.tobias.playpad.plugin.api.websocket.MethodExecutable +import de.tobias.playpad.plugin.api.websocket.message.Message +import org.eclipse.jetty.websocket.api.Session + +class CurrentPageRequestMethod extends MethodExecutable { + + override def execute(session: Session, message: Message): JsonObject = { + val response = new JsonObject() + response.addProperty("page", PlayPadPlugin.getInstance().getMainViewController.getPage) + response + } +} -- GitLab