1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 16:58:51 -05:00

Run sysinfo script on startup whenever GroovyPad is displayed

This commit is contained in:
Reinhard Pointner 2016-10-19 19:48:00 +08:00
parent d965a5bf88
commit 3c3d06543a
2 changed files with 16 additions and 7 deletions

View File

@ -44,6 +44,8 @@ import net.filebot.util.TeePrintStream;
public class GroovyPad extends JFrame {
public static final String DEFAULT_SCRIPT = "runScript 'sysinfo'";
public GroovyPad() throws IOException {
super("Groovy Pad");
@ -146,7 +148,7 @@ public class GroovyPad extends JFrame {
File pad = ApplicationFolder.AppData.resolve(name);
if (!pad.exists()) {
// use this default value so people can easily submit bug reports with fn:sysinfo logs
ScriptShellMethods.saveAs("runScript 'sysinfo'", pad);
ScriptShellMethods.saveAs(DEFAULT_SCRIPT, pad);
}
return FileLocation.create(pad);
}
@ -166,17 +168,21 @@ public class GroovyPad extends JFrame {
private Runner currentRunner = null;
protected void runScript(ActionEvent evt) {
public void runScript(ActionEvent evt) {
// persist script file and clear output
try {
editor.save();
} catch (IOException e) {
// won't happen
debug.log(Level.WARNING, e, e::getMessage);
}
output.setText("");
output.setText("");
runScript(editor.getText());
}
public void runScript(String script) {
if (currentRunner == null || currentRunner.isDone()) {
currentRunner = new Runner(editor.getText()) {
currentRunner = new Runner(script) {
@Override
protected void done() {

View File

@ -112,12 +112,15 @@ public class MainFrame extends JFrame {
pad.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
MainFrame.this.setVisible(false);
setVisible(false);
// run default script on startup
pad.runScript(GroovyPad.DEFAULT_SCRIPT);
};
@Override
public void windowClosing(WindowEvent e) {
MainFrame.this.setVisible(true);
setVisible(true);
};
});