Skip to content

Commit

Permalink
Fixed Arknighs onClick not triggering any dialog;
Browse files Browse the repository at this point in the history
Fixed some SIFIdols crashing for an illegal char in url;
First implementation of low battery event/dialog with current battery percentage;
Improved BootFailedFrame with a new style;
First implementation of CommandExecutor, now MMS can execute System utility commands;
First Windows startup procedure, now MMS can start at boot natively;
Other minor internal fixes;
  • Loading branch information
KaikyuTest committed Jan 30, 2020
1 parent 0c1cc23 commit 06de8d2
Show file tree
Hide file tree
Showing 17 changed files with 371 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/config/
/resources/
/.idea/
/logs/
20 changes: 11 additions & 9 deletions src/main/java/com/kitsunecode/mms/core/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.kitsunecode.mms.core;

import com.kitsunecode.mms.core.adapters.IWaifuAdapter;
import com.kitsunecode.mms.core.entities.swing.BootFailedFrame;
import com.kitsunecode.mms.core.utils.FileWatcher;
import com.kitsunecode.mms.core.entities.swing.Secretary;
import com.kitsunecode.mms.core.utils.Settings;
Expand All @@ -13,7 +12,7 @@ public class Main {

private static Secretary secretary = null;

private static void inizialize() {
private static void initialize() {
if (secretary != null) {
secretary.close();
}
Expand All @@ -25,17 +24,20 @@ private static void inizialize() {

System.out.println("Starting " + adapter + " with name " + name);

try {
Util.catchMoeMoeExceptionsAndExit(() -> {
IWaifuAdapter waifu = Util.getWaifuFromAdapterName(adapter, name);
secretary = new Secretary(waifu);
} catch (Exception e) {
e.printStackTrace();
BootFailedFrame frame = new BootFailedFrame(e);
}
});
}

public static void main(String[] args) {
inizialize();
new FileWatcher(Paths.get(Settings.configPath), Main::inizialize).watch();

Util.catchMoeMoeExceptionsAndExit(() -> {
Util.logToFile();
Util.startupProcedure();
});

initialize();
new FileWatcher(Paths.get(Settings.configPath), Main::initialize).watch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;


public abstract class IWaifuAdapter {

private static final String ON_IDLE_EVENT_KEY = "onIdle";
private static final String ON_LOGIN_EVENT_KEY = "onLogin";
private static final String ON_CLICK_EVENT_KEY = "onClick";
private static final String ON_LOW_BATTERY_EVENT_KEY = "onLowBattery";
private static final String ON_HIGH_CPU_USAGE_KEY = "onHighCpu";

private long startTimeMillis;

Expand Down Expand Up @@ -140,7 +143,7 @@ public List<Dialog> getDialogs() {
}

public List<Dialog> getDialogs(String event) {
return this.data.getDialogs();
return this.data.getDialogs().stream().filter(e -> e.getEvent().equals(event)).collect(Collectors.toList());
}

public String getShowableName() {
Expand All @@ -159,6 +162,14 @@ public String onIdleEventKey() {
return ON_IDLE_EVENT_KEY;
}

public String onLowBatteryEventKey() {
return ON_LOW_BATTERY_EVENT_KEY;
}

public String onHighCpuUsageKey() {
return ON_HIGH_CPU_USAGE_KEY;
}

public String onLoginEventKey() {
return ON_LOGIN_EVENT_KEY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private List<Dialog> getDialogsFromWiki(Document doc, String section, String mms
private List<String> getIdolSkinUrls(Document doc) {
return Selector.select(SKIN_LINKS, doc).stream()
.filter(e -> e.text().toLowerCase().contains("transparent: "))
.map(e -> "https:" + e.attr("href"))
.map(e -> "https:" + e.attr("href").split("\\?")[0])
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String getVoiceTitleMMSCompatible() {
if (voiceTitle.contains("Greeting")) {
return voiceTitle.replace("Greeting", "onLogin");
}
return voiceTitle.replace(voiceTitle, "any");
return voiceTitle.replace(voiceTitle, "onClick");
}

public String getVoiceUrl() {
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/com/kitsunecode/mms/core/entities/CommandOutput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.kitsunecode.mms.core.entities;

public class CommandOutput {

private String stdout;
private String stderr;
private int exitCode;
private boolean hasException;
private Throwable exception;

public CommandOutput(String stdout, String stderr, int exitCode) {
this.stderr = stderr;
this.stdout = stdout;
this.exitCode = exitCode;
}

public CommandOutput(Throwable exception) {
this.exception = exception;
this.hasException = true;
}

public String getStdout() {
return stdout;
}

public String getStderr() {
return stderr;
}

public int getExitCode() {
return exitCode;
}

public boolean hasException() {
return hasException;
}

public Throwable getException() {
return exception;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.io.InputStream;
import java.util.Random;

public class BootFailedFrame extends JFrame {
public class BootFailedFrame extends JDialog {

private static final String[] ERRORS = new String[]{
"That hurts! &gt;~&lt;",
Expand All @@ -25,50 +25,52 @@ public class BootFailedFrame extends JFrame {
};

private int fullWidth = 565;
private int fullHeight = 565;
private int fullHeight = 700;

private int width = 565;
private int height = 434;
private int height = 450;

private int fontSize = 18;
private Color msgBgColor = new Color(0.0f, 0.0f, 0.0f, 0.95f);
private Color msgFgColor = Color.white;
private String fontName = "Arial";
private Color msgFgColor = new Color(1.0f, 1.0f, 1.0f, 0.60f);
private String fontName = "Bahnschrift Light";


public BootFailedFrame(Exception ex) {
super("Moe Moe Error");
// super();"Moe Moe Error"

String error = ex.getMessage();

setLayout(null);
setResizable(false);
setSize(new Dimension(width, height));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setSize(new Dimension(width, height + 200));
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setUndecorated(true);
setBackground(new Color(0,0,0,0));
JLabel pane = new JLabel();

InputStream is = BootFailedFrame.class.getClassLoader().getResourceAsStream("images/error-waifu.jpg");
InputStream is = BootFailedFrame.class.getClassLoader().getResourceAsStream("images/error-waifu-lq.png");
if (is != null) {
try {
pane.setIcon(new ImageIcon(ImageIO.read(is)));
pane.setVerticalAlignment(SwingConstants.TOP);
} catch (IOException e) {
// Ignore
e.printStackTrace();
}
}

pane.setBounds(0, 0, fullWidth, fullHeight);
pane.setSize(new Dimension(width, height));

String errorsMsg = ERRORS[new Random().nextInt(ERRORS.length)];

String errorFull = "<html><div style='text-align: center;'><p style='padding-left: 16px; padding-right: 16px;'>&Prime;" + error + "&Prime;<br><br>" + errorsMsg + "</p></div></html>";
String errorFull = "<html><div style='text-align: center;'><p style='padding-left: 16px; padding-right: 16px;'><font size='4'>An error occurred during the execution:</font><br>&Prime;" + error + "&Prime;<br><br><font size='2'>Click anywhere to close...</font></p></div></html>";
JLabel textMsg = new JLabel(errorFull, SwingConstants.CENTER);
textMsg.setFont(new Font(fontName, Font.PLAIN, fontSize));
textMsg.setBackground(msgBgColor);
textMsg.setForeground(msgFgColor);
textMsg.setOpaque(true);
textMsg.setVisible(true);
textMsg.setBounds(0, 300, 564, 100);
textMsg.setBounds(0, 400, 564, (error.length() >= 100) ? 180 : 120);
textMsg.setBorder(BorderFactory.createMatteBorder(2,2,2,2, new Color(1,1,1, 0.5f)));

add(textMsg, BorderLayout.CENTER);
add(pane, BorderLayout.CENTER);
Expand Down Expand Up @@ -98,15 +100,31 @@ public void mouseExited(MouseEvent mouseEvent) { }
}
}

setLocationRelativeTo(null);
addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
dispose();
}

setVisible(true);
@Override
public void mousePressed(MouseEvent mouseEvent) { }

@Override
public void mouseReleased(MouseEvent mouseEvent) { }

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(1);
@Override
public void mouseEntered(MouseEvent mouseEvent) {
}

@Override
public void mouseExited(MouseEvent mouseEvent) {
}
});

setLocationRelativeTo(null);

setModal(true);
setVisible(true);

}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.kitsunecode.mms.core.entities.swing;

import com.kitsunecode.mms.core.adapters.IWaifuAdapter;
import com.kitsunecode.mms.core.entities.CommandOutput;
import com.kitsunecode.mms.core.entities.Dialog;
import com.kitsunecode.mms.core.utils.Settings;
import com.kitsunecode.mms.core.utils.*;
import com.kitsunecode.mms.core.entities.WaifuData;
import com.kitsunecode.mms.core.utils.AudioUtils;
import com.kitsunecode.mms.core.utils.Util;

import javax.imageio.ImageIO;
import javax.swing.*;
Expand All @@ -16,6 +15,10 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;

Expand Down Expand Up @@ -78,6 +81,10 @@ public Secretary(IWaifuAdapter waifu) throws Exception {
onLogin(); // Say Hi!
}

if (Settings.isExtraDialogsEnabled()) {
extraDialogsThread();
}

}

@Override
Expand Down Expand Up @@ -128,14 +135,29 @@ private void idle() {
}).start();
}


private void extraDialogsThread() {
// CommandExecutor executor = new CommandExecutor();
// new Thread(() -> {
// while (running) {
// try {
// speak( waifuInterface.getDialogs(waifuInterface.onLowBatteryEventKey()));
// Util.sleep(Settings.getWaifuEventsRefreshRate());
// } catch (Exception e) {
// e.printStackTrace();
// return;
// }
// }
// }).start();
}

private void onLogin() {
new Thread(() -> {
Util.sleep(Settings.getWaifuWelcomeDelay());
speak(waifuInterface.getDialogs(waifuInterface.onLoginEventKey()));
}).start();
}


private Image loadSkin(int index) throws IOException {

if (index < 0) {
Expand Down Expand Up @@ -259,15 +281,16 @@ public void speak(List<com.kitsunecode.mms.core.entities.Dialog> dialogs) {
SwingUtilities.invokeLater(() -> {
secretaryLabel.speak(true);

String text = Util.parseDialog(dialog.getDialog());

baloon.setText(
Settings.getBaloonFormatString().replace("[[text]]",
dialog.getDialog() + "<br>&zwnj;")
Settings.getBaloonFormatString().replace("[[text]]",text + "<br>&zwnj;")
);

// Activate baloon only if there is text to show
baloon.toggle(!dialog.getDialog().equals(""));
baloon.toggle(!text.equals(""));
speekingThread = new Thread(() -> {
if (Settings.isVoiceEnabled() && dialog.getAudio() != null && !dialog.getAudio().equals("")) {
if (Settings.isVoiceEnabled() && dialog.getAudio() != null && !text.equals("")) {
audioUtils.play(this, dialog.getAudio(), Settings.getVoiceVolume());
} else {
Util.sleep(Settings.getDialogsBaloonNoVoiceDuration());
Expand Down
Loading

0 comments on commit 06de8d2

Please sign in to comment.