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

Commit 0d9d1b9

Browse files
committed
Add terminate daemon menu item and announcement checker
1 parent 371975c commit 0d9d1b9

File tree

5 files changed

+122
-1
lines changed

5 files changed

+122
-1
lines changed

osumer-daemon/src/main/java/com/github/mob41/osumer/daemon/Daemon.java

+5
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,9 @@ public boolean isOverlayAgreement() throws RemoteException {
356356
return config.isOverlayAgreement();
357357
}
358358

359+
@Override
360+
public void shutdown() throws RemoteException {
361+
System.exit(0);
362+
}
363+
359364
}

osumer-lib/src/main/java/com/github/mob41/osumer/rmi/IDaemon.java

+2
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ public interface IDaemon extends Remote{
3636

3737
public void reloadConfiguration() throws RemoteException, IOException;
3838

39+
public void shutdown() throws RemoteException;
40+
3941
}

osumer-ui/src/main/java/com/github/mob41/osumer/ui/MainController.java

+113
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.net.URI;
88
import java.net.URL;
99
import java.rmi.RemoteException;
10+
import java.text.SimpleDateFormat;
1011
import java.util.ArrayList;
1112
import java.util.Calendar;
1213
import java.util.List;
@@ -26,12 +27,16 @@
2627
import com.github.mob41.osumer.method.MethodResult;
2728
import com.github.mob41.osumer.queue.QueueStatus;
2829
import com.github.mob41.osumer.rmi.IDaemon;
30+
import com.github.mob41.osumer.updater.Announcement;
31+
import com.github.mob41.osumer.updater.AnnouncementChecker;
2932
import com.github.mob41.osumer.updater.UpdateInfo;
3033
import com.github.mob41.osumer.updater.Updater;
3134
import com.github.mob41.osums.Osums;
3235
import com.github.mob41.osums.beatmap.OsuBeatmap;
3336
import com.github.mob41.osums.beatmap.OsuSong;
3437

38+
import javafx.animation.KeyFrame;
39+
import javafx.animation.Timeline;
3540
import javafx.application.Platform;
3641
import javafx.event.ActionEvent;
3742
import javafx.event.EventHandler;
@@ -60,6 +65,7 @@
6065
import javafx.stage.Modality;
6166
import javafx.stage.Stage;
6267
import javafx.stage.StageStyle;
68+
import javafx.util.Duration;
6369
import jfxtras.styles.jmetro8.JMetro;
6470

6571
public class MainController implements Initializable {
@@ -127,6 +133,9 @@ public class MainController implements Initializable {
127133
@FXML
128134
private MenuItem aboutMenuItem;
129135

136+
@FXML
137+
private MenuItem exitMenuItem;
138+
130139
private Configuration config;
131140

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

138147
private Updater updater;
148+
149+
private AnnouncementChecker annChecker;
139150

140151
private boolean checkingUpdate;
152+
153+
private boolean checkingAnnouncements;
154+
155+
private Announcement[] ann;
156+
157+
private int currAnnIndex;
158+
159+
private Timeline updateAnnUiTimeline;
141160

142161
@Override
143162
public void initialize(URL location, ResourceBundle resources) {
@@ -192,6 +211,7 @@ public void handle(ActionEvent event) {
192211
@Override
193212
public void handle(ActionEvent event) {
194213
checkUpdate();
214+
checkAnnouncements();
195215
}
196216
});
197217

@@ -235,6 +255,22 @@ public void handle(ActionEvent event) {
235255
}
236256
});
237257

258+
exitMenuItem.setOnAction(new EventHandler<ActionEvent>() {
259+
260+
@Override
261+
public void handle(ActionEvent event) {
262+
try {
263+
d.shutdown();
264+
d = null;
265+
} catch (RemoteException e) {
266+
//e.printStackTrace();
267+
//Alert alert = new Alert(AlertType.ERROR, "Could not shutdown daemon. Please do this manually in task manager by terminating Java VM.", ButtonType.OK);
268+
//alert.showAndWait();
269+
}
270+
Platform.exit();
271+
}
272+
});
273+
238274
docsMenuItem.setOnAction(new EventHandler<ActionEvent>() {
239275

240276
@Override
@@ -355,8 +391,13 @@ protected void setConfiguration(Configuration config) {
355391
updater = new Updater(config);
356392
checkingUpdate = false;
357393

394+
annChecker = new AnnouncementChecker();
395+
checkingAnnouncements = false;
396+
ann = null;
397+
358398
//TODO do freq check
359399
checkUpdate();
400+
checkAnnouncements();
360401
}
361402

362403
protected void setDaemon(IDaemon d) {
@@ -696,6 +737,78 @@ private UpdateInfo getUpdateInfoByConfig() throws WithDumpException {
696737
return updater.getLatestVersion();
697738
}
698739
}
740+
741+
public void checkAnnouncements() {
742+
if (checkingAnnouncements) {
743+
return;
744+
}
745+
746+
checkingAnnouncements = true;
747+
Thread thread = new Thread() {
748+
public void run() {
749+
Platform.runLater(new Runnable() {
750+
@Override
751+
public void run() {
752+
announcementLabel.setText("Loading announcements...");
753+
}
754+
});
755+
756+
if (updateAnnUiTimeline != null) {
757+
updateAnnUiTimeline.stop();
758+
}
759+
760+
currAnnIndex = -1;
761+
ann = null;
762+
try {
763+
ann = annChecker.getAnnouncements();
764+
} catch (WithDumpException e) {
765+
Platform.runLater(new Runnable() {
766+
@Override
767+
public void run() {
768+
announcementLabel.setText("Error checking announcements. See dump for more details.");
769+
}
770+
});
771+
checkingAnnouncements = false;
772+
return;
773+
}
774+
775+
nextAnnouncement();
776+
updateAnnUiTimeline = new Timeline(new KeyFrame(Duration.seconds(15), new EventHandler<ActionEvent>() {
777+
778+
@Override
779+
public void handle(ActionEvent event) {
780+
if (ann == null) {
781+
updateAnnUiTimeline.stop();
782+
return;
783+
}
784+
nextAnnouncement();
785+
}
786+
787+
}));
788+
updateAnnUiTimeline.setCycleCount(Timeline.INDEFINITE);
789+
updateAnnUiTimeline.play();
790+
791+
checkingAnnouncements = false;
792+
}
793+
};
794+
thread.start();
795+
}
796+
797+
private void nextAnnouncement() {
798+
currAnnIndex = (currAnnIndex + 1) % ann.length;
799+
800+
Announcement a = ann[currAnnIndex];
801+
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
802+
String text = "[" + f.format(a.getTime().getTime()) + "] " + a.getText();
803+
Platform.runLater(new Runnable() {
804+
805+
@Override
806+
public void run() {
807+
announcementLabel.setText(text);
808+
}
809+
810+
});
811+
}
699812

700813
public void checkUpdate() {
701814
if (checkingUpdate) {

osumer-ui/src/main/resources/view/RootLayout.fxml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
</Menu>
4848
<SeparatorMenuItem mnemonicParsing="false" />
4949
<MenuItem fx:id="closeMenuItem" mnemonicParsing="false" text="Close" />
50+
<MenuItem fx:id="exitMenuItem" mnemonicParsing="false" text="Exit and terminate daemon" />
5051
</items>
5152
</Menu>
5253
<Menu mnemonicParsing="false" text="Help">

osums-server/target/classes/META-INF/maven/com.github.mob41/osums-server/pom.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Generated by Maven Integration for Eclipse
2-
#Tue Jun 30 23:13:51 CST 2020
2+
#Wed Jul 01 16:55:22 CST 2020
33
version=2.0.0-SNAPSHOT
44
groupId=com.github.mob41
55
m2e.projectName=osums-server

0 commit comments

Comments
 (0)