Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Commit

Permalink
Add terminate daemon menu item and announcement checker
Browse files Browse the repository at this point in the history
  • Loading branch information
a1aw committed Jul 1, 2020
1 parent 371975c commit 0d9d1b9
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,9 @@ public boolean isOverlayAgreement() throws RemoteException {
return config.isOverlayAgreement();
}

@Override
public void shutdown() throws RemoteException {
System.exit(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public interface IDaemon extends Remote{

public void reloadConfiguration() throws RemoteException, IOException;

public void shutdown() throws RemoteException;

}
113 changes: 113 additions & 0 deletions osumer-ui/src/main/java/com/github/mob41/osumer/ui/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.net.URI;
import java.net.URL;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
Expand All @@ -26,12 +27,16 @@
import com.github.mob41.osumer.method.MethodResult;
import com.github.mob41.osumer.queue.QueueStatus;
import com.github.mob41.osumer.rmi.IDaemon;
import com.github.mob41.osumer.updater.Announcement;
import com.github.mob41.osumer.updater.AnnouncementChecker;
import com.github.mob41.osumer.updater.UpdateInfo;
import com.github.mob41.osumer.updater.Updater;
import com.github.mob41.osums.Osums;
import com.github.mob41.osums.beatmap.OsuBeatmap;
import com.github.mob41.osums.beatmap.OsuSong;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
Expand Down Expand Up @@ -60,6 +65,7 @@
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;
import jfxtras.styles.jmetro8.JMetro;

public class MainController implements Initializable {
Expand Down Expand Up @@ -127,6 +133,9 @@ public class MainController implements Initializable {
@FXML
private MenuItem aboutMenuItem;

@FXML
private MenuItem exitMenuItem;

private Configuration config;

private IDaemon d;
Expand All @@ -136,8 +145,18 @@ public class MainController implements Initializable {
private QueueStatus[] queues;

private Updater updater;

private AnnouncementChecker annChecker;

private boolean checkingUpdate;

private boolean checkingAnnouncements;

private Announcement[] ann;

private int currAnnIndex;

private Timeline updateAnnUiTimeline;

@Override
public void initialize(URL location, ResourceBundle resources) {
Expand Down Expand Up @@ -192,6 +211,7 @@ public void handle(ActionEvent event) {
@Override
public void handle(ActionEvent event) {
checkUpdate();
checkAnnouncements();
}
});

Expand Down Expand Up @@ -235,6 +255,22 @@ public void handle(ActionEvent event) {
}
});

exitMenuItem.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
try {
d.shutdown();
d = null;
} catch (RemoteException e) {
//e.printStackTrace();
//Alert alert = new Alert(AlertType.ERROR, "Could not shutdown daemon. Please do this manually in task manager by terminating Java VM.", ButtonType.OK);
//alert.showAndWait();
}
Platform.exit();
}
});

docsMenuItem.setOnAction(new EventHandler<ActionEvent>() {

@Override
Expand Down Expand Up @@ -355,8 +391,13 @@ protected void setConfiguration(Configuration config) {
updater = new Updater(config);
checkingUpdate = false;

annChecker = new AnnouncementChecker();
checkingAnnouncements = false;
ann = null;

//TODO do freq check
checkUpdate();
checkAnnouncements();
}

protected void setDaemon(IDaemon d) {
Expand Down Expand Up @@ -696,6 +737,78 @@ private UpdateInfo getUpdateInfoByConfig() throws WithDumpException {
return updater.getLatestVersion();
}
}

public void checkAnnouncements() {
if (checkingAnnouncements) {
return;
}

checkingAnnouncements = true;
Thread thread = new Thread() {
public void run() {
Platform.runLater(new Runnable() {
@Override
public void run() {
announcementLabel.setText("Loading announcements...");
}
});

if (updateAnnUiTimeline != null) {
updateAnnUiTimeline.stop();
}

currAnnIndex = -1;
ann = null;
try {
ann = annChecker.getAnnouncements();
} catch (WithDumpException e) {
Platform.runLater(new Runnable() {
@Override
public void run() {
announcementLabel.setText("Error checking announcements. See dump for more details.");
}
});
checkingAnnouncements = false;
return;
}

nextAnnouncement();
updateAnnUiTimeline = new Timeline(new KeyFrame(Duration.seconds(15), new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
if (ann == null) {
updateAnnUiTimeline.stop();
return;
}
nextAnnouncement();
}

}));
updateAnnUiTimeline.setCycleCount(Timeline.INDEFINITE);
updateAnnUiTimeline.play();

checkingAnnouncements = false;
}
};
thread.start();
}

private void nextAnnouncement() {
currAnnIndex = (currAnnIndex + 1) % ann.length;

Announcement a = ann[currAnnIndex];
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
String text = "[" + f.format(a.getTime().getTime()) + "] " + a.getText();
Platform.runLater(new Runnable() {

@Override
public void run() {
announcementLabel.setText(text);
}

});
}

public void checkUpdate() {
if (checkingUpdate) {
Expand Down
1 change: 1 addition & 0 deletions osumer-ui/src/main/resources/view/RootLayout.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
</Menu>
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="closeMenuItem" mnemonicParsing="false" text="Close" />
<MenuItem fx:id="exitMenuItem" mnemonicParsing="false" text="Exit and terminate daemon" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Tue Jun 30 23:13:51 CST 2020
#Wed Jul 01 16:55:22 CST 2020
version=2.0.0-SNAPSHOT
groupId=com.github.mob41
m2e.projectName=osums-server
Expand Down

0 comments on commit 0d9d1b9

Please sign in to comment.