Skip to content

Commit

Permalink
feat: Added splash screen to Drifty GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
SaptarshiSarkar12 committed Dec 18, 2023
1 parent f2320a7 commit 65b69b4
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/GUI/Forms/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class Constants {
public static final URL DIRECTORY_PNG = Constants.class.getResource("/GUI/Labels/Directory.png");
public static final URL FILENAME_PNG = Constants.class.getResource("/GUI/Labels/Filename.png");
public static final URL DRIFTY_ICON = Constants.class.getResource("/GUI/Icons/AppIcon.png");
public static final URL SPLASH = Constants.class.getResource("/GUI/Splash.png");

/*
Stylesheets
Expand Down
37 changes: 36 additions & 1 deletion src/main/java/GUI/Forms/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
import Utils.MessageBroker;
import Utils.Utility;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.Clipboard;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import static Utils.DriftyConstants.DRIFTY_WEBSITE_URL;
import static javafx.scene.layout.AnchorPane.*;
Expand All @@ -28,6 +33,7 @@ public class Main extends Application {
private static Main guiInstance;
private static MessageBroker msgBroker;
private Stage primaryStage;
private Stage splashStage;
private Scene scene;

public static void main(String[] args) {
Expand All @@ -36,17 +42,39 @@ public static void main(String[] args) {
msgBroker = new MessageBroker();
Environment.setMessageBroker(msgBroker);
msgBroker.msgLogInfo(DriftyConstants.GUI_APPLICATION_STARTED);
Environment.initializeEnvironment();
launch(args);
}

@Override
public void start(Stage primaryStage) {
splashStage = Constants.getStage("Splash", false);
AppSettings.SET.isInitialising(true);
createSplashScene();
Environment.initializeEnvironment();
AppSettings.SET.isInitialising(false);
splashStage.close();
this.primaryStage = Constants.getStage("Drifty GUI", true);
createScene();
guiInstance = this;
}

private void createSplashScene() {
Image splashImage = new Image(Constants.SPLASH.toExternalForm());
ImageView ivSplash = new ImageView(splashImage);
double width = splashImage.getWidth();
double fitWidth = Constants.SCREEN_WIDTH * .45;
ivSplash.setPreserveRatio(true);
ivSplash.setFitWidth(fitWidth);
Pane pane = new Pane();
pane.getChildren().add(ivSplash);
Scene scene = new Scene(pane);
scene.setFill(Color.TRANSPARENT);
splashStage.initStyle(StageStyle.TRANSPARENT);
splashStage.setAlwaysOnTop(true);
splashStage.show();
splashStage.setScene(scene);
}

private void createScene() {
AnchorPane ap = new AnchorPane();
MainGridPane gridPane = new MainGridPane();
Expand All @@ -57,6 +85,13 @@ private void createScene() {
placeControl(menu, 0, 0, 0, -1);
scene = Constants.getScene(ap);
scene.setOnContextMenuRequested(e -> getRightClickContextMenu().show(scene.getWindow(), e.getScreenX(), e.getScreenY()));
while (AppSettings.GET.isInitialising()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
primaryStage.setScene(scene);
primaryStage.show();
menu.setUseSystemMenuBar(true);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/Preferences/Clear.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ public void ytDlpVersion() {
public void spotDLVersion() {
preferences.remove(SPOTDL_VERSION.toString());
}

public void isInitialising() {
preferences.remove(IS_INITIALISING.toString());
}
}
4 changes: 4 additions & 0 deletions src/main/java/Preferences/Get.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ public String ytDlpVersion() {
public String spotDLVersion() {
return preferences.get(SPOTDL_VERSION.toString(), "");
}

public boolean isInitialising() {
return preferences.getBoolean(IS_INITIALISING.toString(), true);
}
}
2 changes: 1 addition & 1 deletion src/main/java/Preferences/Labels.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.prefs.Preferences;

enum Labels {
FOLDERS, MAIN_AUTO_PASTE, LAST_YT_DLP_UPDATE_TIME, LAST_FOLDER, JOBS, MENU_BAR_SYSTEM, ALWAYS_AUTO_PASTE, YT_DLP_VERSION, SPOTDL_VERSION;
FOLDERS, MAIN_AUTO_PASTE, LAST_YT_DLP_UPDATE_TIME, LAST_FOLDER, JOBS, MENU_BAR_SYSTEM, ALWAYS_AUTO_PASTE, YT_DLP_VERSION, SPOTDL_VERSION, IS_INITIALISING;

public static final Preferences PREFERENCES = Preferences.userNodeForPackage(Labels.class);
}
5 changes: 5 additions & 0 deletions src/main/java/Preferences/Set.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ public void spotDLVersion(String version) {
AppSettings.CLEAR.spotDLVersion();
preferences.put(SPOTDL_VERSION.toString(), version);
}

public void isInitialising(boolean isInitialising) {
AppSettings.CLEAR.isInitialising();
preferences.putBoolean(IS_INITIALISING.toString(), isInitialising);
}
}
1 change: 1 addition & 0 deletions src/main/java/Utils/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Backend.CopyExecutables;
import Enums.OS;
import Enums.Program;
import GUI.Forms.Main;
import Preferences.AppSettings;

import java.io.File;
Expand Down

0 comments on commit 65b69b4

Please sign in to comment.