Add support for Ctrl-V pasting on login screen
Based on what field is currently selected, add support for pasting to that field with standard Ctrl-V keybinding (disabled by default). Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -22,15 +22,35 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.usernamesyncer;
|
package net.runelite.client.plugins.loginscreen;
|
||||||
|
|
||||||
import net.runelite.client.config.Config;
|
import net.runelite.client.config.Config;
|
||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
@ConfigGroup("rememberusername")
|
@ConfigGroup("loginscreen")
|
||||||
public interface UsernameSyncerConfig extends Config
|
public interface LoginScreenConfig extends Config
|
||||||
{
|
{
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "syncusername",
|
||||||
|
name = "Sync username",
|
||||||
|
description = "Syncs the username that is currently remembered between computers"
|
||||||
|
)
|
||||||
|
default boolean syncUsername()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "pasteenabled",
|
||||||
|
name = "Ctrl-V paste",
|
||||||
|
description = "Enables Ctrl+V pasting on the login screen"
|
||||||
|
)
|
||||||
|
default boolean pasteEnabled()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "username",
|
keyName = "username",
|
||||||
name = "",
|
name = "",
|
||||||
@@ -22,11 +22,16 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.usernamesyncer;
|
package net.runelite.client.plugins.loginscreen;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.datatransfer.DataFlavor;
|
||||||
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.io.IOException;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
@@ -34,21 +39,26 @@ import net.runelite.api.GameState;
|
|||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.SessionOpen;
|
import net.runelite.api.events.SessionOpen;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
|
import net.runelite.client.input.KeyListener;
|
||||||
|
import net.runelite.client.input.KeyManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Username Syncer",
|
name = "Login Screen",
|
||||||
description = "Save your username to the config, allowing it to be synced"
|
description = "Provides various enhancements for login screen"
|
||||||
)
|
)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class UsernameSyncerPlugin extends Plugin
|
public class LoginScreenPlugin extends Plugin implements KeyListener
|
||||||
{
|
{
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private UsernameSyncerConfig config;
|
private LoginScreenConfig config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private KeyManager keyManager;
|
||||||
|
|
||||||
private String usernameCache;
|
private String usernameCache;
|
||||||
|
|
||||||
@@ -56,23 +66,34 @@ public class UsernameSyncerPlugin extends Plugin
|
|||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
applyUsername();
|
applyUsername();
|
||||||
|
keyManager.registerKeyListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutDown() throws Exception
|
protected void shutDown() throws Exception
|
||||||
{
|
{
|
||||||
client.getPreferences().setRememberedUsername(usernameCache);
|
if (config.syncUsername())
|
||||||
|
{
|
||||||
|
client.getPreferences().setRememberedUsername(usernameCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
keyManager.unregisterKeyListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
UsernameSyncerConfig getConfig(ConfigManager configManager)
|
LoginScreenConfig getConfig(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
return configManager.getConfig(UsernameSyncerConfig.class);
|
return configManager.getConfig(LoginScreenConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameStateChanged(GameStateChanged event)
|
public void onGameStateChanged(GameStateChanged event)
|
||||||
{
|
{
|
||||||
|
if (!config.syncUsername())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.getGameState() == GameState.LOGIN_SCREEN)
|
if (event.getGameState() == GameState.LOGIN_SCREEN)
|
||||||
{
|
{
|
||||||
applyUsername();
|
applyUsername();
|
||||||
@@ -105,6 +126,11 @@ public class UsernameSyncerPlugin extends Plugin
|
|||||||
|
|
||||||
private void applyUsername()
|
private void applyUsername()
|
||||||
{
|
{
|
||||||
|
if (!config.syncUsername())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
GameState gameState = client.getGameState();
|
GameState gameState = client.getGameState();
|
||||||
if (gameState == GameState.LOGIN_SCREEN)
|
if (gameState == GameState.LOGIN_SCREEN)
|
||||||
{
|
{
|
||||||
@@ -124,4 +150,51 @@ public class UsernameSyncerPlugin extends Plugin
|
|||||||
client.getPreferences().setRememberedUsername(username);
|
client.getPreferences().setRememberedUsername(username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e)
|
||||||
|
{
|
||||||
|
if (!config.pasteEnabled() || client.getGameState() != GameState.LOGIN_SCREEN)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_V && e.isControlDown())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final String data = Toolkit
|
||||||
|
.getDefaultToolkit()
|
||||||
|
.getSystemClipboard()
|
||||||
|
.getData(DataFlavor.stringFlavor)
|
||||||
|
.toString()
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
// 0 is username, 1 is password
|
||||||
|
if (client.getCurrentLoginField() == 0)
|
||||||
|
{
|
||||||
|
client.setUsername(data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
client.setPassword(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (UnsupportedFlavorException | IOException ex)
|
||||||
|
{
|
||||||
|
log.warn("failed to fetch clipboard data", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user