Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic Multiple Client support #127

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions app-core/src/main/java/com/mercury/platform/core/ChatHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.ptr.IntByReference;
import org.apache.commons.lang3.SystemUtils;

import javax.swing.*;
Expand All @@ -23,6 +24,9 @@
import java.awt.event.KeyEvent;
import java.io.IOException;

import java.util.ArrayList;
import java.util.List;


public class ChatHelper implements AsSubscriber {
private Robot robot;
Expand Down Expand Up @@ -204,12 +208,45 @@ private void findInStashTab(String toBeFound) {
final int SWP_NOMOVE = 0x0002;
final int SWP_SHOWWINDOW = 0x0040;

static public ArrayList<DesktopWindow> getPoeWindows() {
ArrayList<DesktopWindow> windows = new ArrayList<DesktopWindow>();
WindowUtils.getAllWindows(false).forEach(window -> {
char[] className = new char[512];
User32.INSTANCE.GetClassName(window.getHWND(), className, 512);

if (Native.toString(className).equals("POEWindowClass")) {
windows.add(window);
}
});

return windows;
}

static public int getWindowPid(DesktopWindow window) {
IntByReference winpid = new IntByReference();
User32.INSTANCE.GetWindowThreadProcessId(window.getHWND(), winpid);

return winpid.getValue();
}

static public ArrayList<Integer> getPoeWindowPids() {
ArrayList<DesktopWindow> windows = getPoeWindows();
ArrayList<Integer> pids = new ArrayList<Integer>();

windows.forEach(window -> { pids.add(getWindowPid(window)); });
return pids;
}

private void gameToFront() {
int pid = Configuration.get().applicationConfiguration().get().getGamePid();

if (SystemUtils.IS_OS_WINDOWS) {
WindowUtils.getAllWindows(false).forEach(window -> {
char[] className = new char[512];
User32.INSTANCE.GetClassName(window.getHWND(), className, 512);
if (Native.toString(className).equals("POEWindowClass")) {
getPoeWindows().forEach(window -> {
int winpid = getWindowPid(window);

boolean pidMatch = (pid == 0) || (pid == winpid);

if (pidMatch) {
User32.INSTANCE.ShowWindow(window.getHWND(), 5);

boolean isAtFront = User32.INSTANCE.SetForegroundWindow(window.getHWND());
Expand All @@ -227,6 +264,7 @@ private void gameToFront() {
User32.INSTANCE.SetFocus(window.getHWND());
}
});

// User32.INSTANCE.EnumWindows((hWnd, arg1) -> {
// char[] className = new char[512];
// User32.INSTANCE.GetClassName(hWnd, className, 512);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ApplicationDescriptor implements Serializable {
private int maxOpacity;
private int fadeTime;
private String gamePath;
private int gamePid;
private String pushbulletAccessToken;
private boolean showOnStartUp;
private boolean itemsGridEnable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mercury.platform.ui.components.panel.settings.page;


import com.mercury.platform.core.ChatHelper;
import com.mercury.platform.core.misc.WhisperNotifierStatus;
import com.mercury.platform.shared.CloneHelper;
import com.mercury.platform.shared.PushBulletManager;
Expand All @@ -12,13 +13,15 @@
import com.mercury.platform.ui.components.fields.font.FontStyle;
import com.mercury.platform.ui.manager.HideSettingsManager;
import com.mercury.platform.ui.misc.AppThemeColor;
import org.checkerframework.checker.units.qual.A;

import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Arrays;

public class GeneralSettingsPagePanel extends SettingsPagePanel {
private PlainConfigurationService<ApplicationDescriptor> applicationConfig;
Expand All @@ -29,6 +32,19 @@ public class GeneralSettingsPagePanel extends SettingsPagePanel {
private JSlider minSlider;
private JSlider maxSlider;

private String[] PidStrings;
private ArrayList<Integer> Pids;

private void updatePoePids() {
ArrayList<String> PidOptions = new ArrayList<String>(Arrays.asList(
"Always Switch (old behavior)",
"Never switch"));
Pids = ChatHelper.getPoeWindowPids();
Pids.forEach(pid -> { PidOptions.add(String.format("PID: %d", pid.intValue())); });
PidStrings = new String[PidOptions.size()];
PidStrings = PidOptions.toArray(PidStrings);
}

@Override
public void onViewInit() {
super.onViewInit();
Expand Down Expand Up @@ -105,6 +121,32 @@ public void keyTyped(KeyEvent e) {
JButton changeButton = this.componentsFactory.getBorderedButton("Change");
poeFolderPanel.add(changeButton, BorderLayout.LINE_END);

updatePoePids();
JComboBox poePidPicker = this.componentsFactory.getComboBox(PidStrings);
poePidPicker.setSelectedItem(this.applicationSnapshot.getNotifierStatus().asPretty());
poePidPicker.addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
updatePoePids();
poePidPicker.setModel(new DefaultComboBoxModel(PidStrings));
}

@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {}
});

poePidPicker.addActionListener(action -> {
int sel = poePidPicker.getSelectedIndex();

switch (sel) {
case 0: applicationSnapshot.setGamePid(0); break;
case 1: applicationSnapshot.setGamePid(-1); break;
default: applicationSnapshot.setGamePid(Pids.get(sel - 2));
}
});

JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
changeButton.addActionListener(e -> {
Expand Down Expand Up @@ -153,6 +195,8 @@ public void keyTyped(KeyEvent e) {
root.add(this.componentsFactory.wrapToSlide(notifierStatusPicker, AppThemeColor.ADR_BG, 0, 0, 0, 2));
root.add(this.componentsFactory.getTextLabel("Path of Exile folder: ", FontStyle.REGULAR, 16));
root.add(this.componentsFactory.wrapToSlide(poeFolderPanel, AppThemeColor.ADR_BG, 0, 0, 2, 2));
root.add(this.componentsFactory.getTextLabel("Multi-client switching: ", FontStyle.REGULAR, 16));
root.add(this.componentsFactory.wrapToSlide(poePidPicker, AppThemeColor.ADR_BG, 0, 0, 2, 2));
root.add(this.componentsFactory.getTextLabel("Pushbullet AccessToken ", FontStyle.REGULAR, 16));
root.add(this.componentsFactory.wrapToSlide(pushbulletPanel, AppThemeColor.ADR_BG, 0, 0, 0, 2));

Expand Down
6 changes: 3 additions & 3 deletions release_files/release_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>gui</headerType>
<jar>C:\repo\github\MercuryTrade\release_files\MercuryTrade.jar</jar>
<outfile>C:\repo\github\MercuryTrade\release_files\MercuryTrade.exe</outfile>
<jar>.\release_files\MercuryTrade.jar</jar>
<outfile>.\release_files\MercuryTrade.exe</outfile>
<errTitle>MercuryTrade needs java to work. Please install java first</errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
Expand All @@ -13,7 +13,7 @@
<stayAlive>false</stayAlive>
<restartOnCrash>false</restartOnCrash>
<manifest></manifest>
<icon>C:\repo\github\MercuryTrade\release_files\app-icon.ico</icon>
<icon>.\release_files\app-icon.ico</icon>
<singleInstance>
<mutexName>MercuryTrade</mutexName>
<windowTitle>MercuryTrade</windowTitle>
Expand Down