1414
1515package com .nativejavafx .taskbar ;
1616
17+ import com .nativejavafx .taskbar .exception .StageNotShownException ;
18+ import com .nativejavafx .taskbar .exception .UnsupportedSystemException ;
1719import com .nativejavafx .taskbar .strategy .HWNDStrategy ;
1820import javafx .stage .Stage ;
1921import org .bridj .Pointer ;
@@ -83,20 +85,23 @@ private void setProgressState(Stage stage, Type type) {
8385
8486 @ Override
8587 public void stopProgress () {
88+ validate (stage .get ());
8689 if (this .stage .get () != null ) {
8790 setProgressState (stage .get (), Type .NO_PROGRESS );
8891 }
8992 }
9093
9194 @ Override
9295 public void showIndeterminateProgress () {
96+ validate (stage .get ());
9397 if (this .stage .get () != null ) {
9498 setProgressState (stage .get (), Type .INDETERMINATE );
9599 }
96100 }
97101
98102 @ Override
99103 public void showCustomProgress (long startValue , long endValue , @ NotNull Type type ) {
104+ validate (stage .get ());
100105 if (this .stage .get () != null ) {
101106 final Pointer <Integer > pointer = getPointer (stage .get ());
102107 executor .execute (() -> {
@@ -108,6 +113,7 @@ public void showCustomProgress(long startValue, long endValue, @NotNull Type typ
108113
109114 @ Override
110115 public void setProgressType (@ NotNull Type type ) {
116+ validate (stage .get ());
111117 setProgressState (stage .get (), type );
112118 }
113119
@@ -116,6 +122,28 @@ public void closeOperations() {
116122 executor .submit (() -> iTaskbarList3 .get ().Release ());
117123 }
118124
125+ private void validate (Stage stage ) {
126+ checkSystemSupported ();
127+ checkStageShown (stage );
128+ }
129+
130+ private void checkStageShown (Stage stage ) {
131+ if (!stage .isShowing ()) throw new StageNotShownException (
132+ "The given Stage is not showing and therefore taskbar-progressbar can't be created"
133+ );
134+ }
135+
136+ private void checkSystemSupported () {
137+ if (isNotSupported ()) throw new UnsupportedSystemException (
138+ String .format (
139+ "%s (system: %s, version: %s)" ,
140+ "Your system does not support taskbar-progressbar!" ,
141+ System .getProperty ("os.name" ),
142+ System .getProperty ("os.version" )
143+ )
144+ );
145+ }
146+
119147 private static final class DaemonThread extends Thread {
120148 DaemonThread (Runnable runnable ) {
121149 super (runnable );
0 commit comments