Skip to content
Snippets Groups Projects
Commit 7eb19951 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

#187 - Add new page-action, navigate-action method to web api

parent 043623d6
Branches
Tags
No related merge requests found
......@@ -19,7 +19,9 @@ class WebSocketHandler {
"project-current" -> new ProjectCurrentMethod,
"project-open" -> new ProjectOpenMethod,
"pad-status-change" -> new PadStatusChangeMethod,
"cart-action" -> new CartActionMethod
"cart-action" -> new CartActionMethod,
"page-action" -> new PageActionMethod,
"navigate-action" -> new NavigateActionMethod
)
@OnWebSocketConnect def connected(session: Session): Unit = {
......
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 javafx.application.Platform
import org.eclipse.jetty.websocket.api.Session
class NavigateActionMethod extends MethodExecutable {
override def execute(session: Session, message: Message): JsonObject = {
val mainViewController = PlayPadPlugin.getInstance.getMainViewController
message.payload.get("action").getAsString match {
case "PREVIOUS" =>
Platform.runLater(() => mainViewController.showPage(mainViewController.getPage - 1))
case "NEXT" =>
Platform.runLater(() => mainViewController.showPage(mainViewController.getPage + 1))
case _ =>
}
null
}
}
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 javafx.application.Platform
import org.eclipse.jetty.websocket.api.Session
class PageActionMethod extends MethodExecutable {
override def execute(session: Session, message: Message): JsonObject = {
val project = PlayPadPlugin.getInstance.getCurrentProject
val mainViewController = PlayPadPlugin.getInstance.getMainViewController
val targetPage = message.payload.get("page").getAsInt
if (targetPage < 0 || targetPage >= project.getPages.size) return null
Platform.runLater(() => mainViewController.showPage(targetPage))
return null
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment