From 8623b85ac8ecb19dcd18eb9b334806333a53a6d9 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 14 Sep 2022 17:47:31 +0200 Subject: [PATCH] Add support to `/devtools` command --- docs/_developer_onboarding.md | 2 +- library/ui-strings/src/main/res/values/strings.xml | 1 + .../main/java/im/vector/app/features/command/Command.kt | 1 + .../java/im/vector/app/features/command/CommandParser.kt | 7 +++++++ .../java/im/vector/app/features/command/ParsedCommand.kt | 1 + .../app/features/home/room/detail/TimelineFragment.kt | 3 +++ .../home/room/detail/composer/MessageComposerViewModel.kt | 4 ++++ 7 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/_developer_onboarding.md b/docs/_developer_onboarding.md index 2b446a950d..640a2d7665 100644 --- a/docs/_developer_onboarding.md +++ b/docs/_developer_onboarding.md @@ -215,7 +215,7 @@ Rageshake can be very useful to get logs from a release version of the applicati - Element Android has a `developer mode` in the `Settings/Advanced settings`. Other useful options are available here; - Show hidden Events can also help to debug feature. When devepor mode is enabled, it is possible to view the source (= the Json content) of any Events; -- Type `/devtools` in Element Web to access a developer menu. On Element Android, available in the Menu of a Room timeline, after enabling developer mode; +- Type `/devtools` in a Room composer to access a developer menu. There are some other entry points. Developer mode has to be enabled; - Hidden debug menu: when developer mode is enabled and on debug build, there are some extra screens that can be accessible using the green wheel. In those screens, it will be possible to toggle some feature flags; - Using logcat, filtering with `onResume` can help you to understand what screen are currently displayed on your device. Searching for string displayed on the screen can also help to find the running code in the codebase. - When this is possible, prefer using `sealed interface` instead of `sealed class`; diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index 6a87ce82f4..23c97661a1 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -1402,6 +1402,7 @@ Changes your avatar in this current room only On/Off markdown To fix Matrix Apps management + Open the developer tools screen Displays information about a user Markdown has been enabled. diff --git a/vector/src/main/java/im/vector/app/features/command/Command.kt b/vector/src/main/java/im/vector/app/features/command/Command.kt index 20c8f9d8fe..433ee32eeb 100644 --- a/vector/src/main/java/im/vector/app/features/command/Command.kt +++ b/vector/src/main/java/im/vector/app/features/command/Command.kt @@ -52,6 +52,7 @@ enum class Command( MARKDOWN("/markdown", null, "", R.string.command_description_markdown, false, false), RAINBOW("/rainbow", null, "", R.string.command_description_rainbow, false, true), RAINBOW_EMOTE("/rainbowme", null, "", R.string.command_description_rainbow_emote, false, true), + DEVTOOLS("/devtools", null, "", R.string.command_description_devtools, true, false), CLEAR_SCALAR_TOKEN("/clear_scalar_token", null, "", R.string.command_description_clear_scalar_token, false, false), SPOILER("/spoiler", null, "", R.string.command_description_spoiler, false, true), SHRUG("/shrug", null, "", R.string.command_description_shrug, false, true), diff --git a/vector/src/main/java/im/vector/app/features/command/CommandParser.kt b/vector/src/main/java/im/vector/app/features/command/CommandParser.kt index be3cabfc18..9cbb6c7978 100644 --- a/vector/src/main/java/im/vector/app/features/command/CommandParser.kt +++ b/vector/src/main/java/im/vector/app/features/command/CommandParser.kt @@ -317,6 +317,13 @@ class CommandParser @Inject constructor() { ParsedCommand.ErrorSyntax(Command.MARKDOWN) } } + Command.DEVTOOLS.matches(slashCommand) -> { + if (messageParts.size == 1) { + ParsedCommand.DevTools + } else { + ParsedCommand.ErrorSyntax(Command.DEVTOOLS) + } + } Command.CLEAR_SCALAR_TOKEN.matches(slashCommand) -> { if (messageParts.size == 1) { ParsedCommand.ClearScalarToken diff --git a/vector/src/main/java/im/vector/app/features/command/ParsedCommand.kt b/vector/src/main/java/im/vector/app/features/command/ParsedCommand.kt index 4571deb54f..eba9994218 100644 --- a/vector/src/main/java/im/vector/app/features/command/ParsedCommand.kt +++ b/vector/src/main/java/im/vector/app/features/command/ParsedCommand.kt @@ -60,6 +60,7 @@ sealed interface ParsedCommand { data class ChangeAvatarForRoom(val url: String) : ParsedCommand data class SetMarkdown(val enable: Boolean) : ParsedCommand object ClearScalarToken : ParsedCommand + object DevTools : ParsedCommand data class SendSpoiler(val message: String) : ParsedCommand data class SendShrug(val message: CharSequence) : ParsedCommand data class SendLenny(val message: CharSequence) : ParsedCommand diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt index 8b6429abb1..3213bf81fe 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt @@ -1810,6 +1810,9 @@ class TimelineFragment : dismissLoadingDialog() views.composerLayout.setTextIfDifferent("") when (parsedCommand) { + is ParsedCommand.DevTools -> { + navigator.openDevTools(requireContext(), timelineArgs.roomId) + } is ParsedCommand.SetMarkdown -> { showSnackWithMessage(getString(if (parsedCommand.enable) R.string.markdown_has_been_enabled else R.string.markdown_has_been_disabled)) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt index 7d67ec8c60..30e45bd40b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt @@ -255,6 +255,10 @@ class MessageComposerViewModel @AssistedInject constructor( is ParsedCommand.SetUserPowerLevel -> { handleSetUserPowerLevel(parsedCommand) } + is ParsedCommand.DevTools -> { + _viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk(parsedCommand)) + popDraft() + } is ParsedCommand.ClearScalarToken -> { // TODO _viewEvents.post(MessageComposerViewEvents.SlashCommandNotImplemented)