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 ;
@@ -82,20 +84,23 @@ private void setProgressState(Stage stage, Type type) {
8284
8385 @ Override
8486 public void stopProgress () {
87+ validate (stage .get ());
8588 if (this .stage .get () != null ) {
8689 setProgressState (stage .get (), Type .NO_PROGRESS );
8790 }
8891 }
8992
9093 @ Override
9194 public void showIndeterminateProgress () {
95+ validate (stage .get ());
9296 if (this .stage .get () != null ) {
9397 setProgressState (stage .get (), Type .INDETERMINATE );
9498 }
9599 }
96100
97101 @ Override
98102 public void showCustomProgress (long startValue , long endValue , @ NotNull Type type ) {
103+ validate (stage .get ());
99104 if (this .stage .get () != null ) {
100105 final Pointer <Integer > pointer = getPointer (stage .get ());
101106 executor .execute (() -> {
@@ -107,6 +112,7 @@ public void showCustomProgress(long startValue, long endValue, @NotNull Type typ
107112
108113 @ Override
109114 public void setProgressType (@ NotNull Type type ) {
115+ validate (stage .get ());
110116 setProgressState (stage .get (), type );
111117 }
112118
@@ -115,6 +121,28 @@ public void closeOperations() {
115121 executor .submit (() -> iTaskbarList3 .get ().Release ());
116122 }
117123
124+ private void validate (Stage stage ) {
125+ checkSystemSupported ();
126+ checkStageShown (stage );
127+ }
128+
129+ private void checkStageShown (Stage stage ) {
130+ if (!stage .isShowing ()) throw new StageNotShownException (
131+ "The given Stage is not showing and therefore taskbar-progressbar can't be created"
132+ );
133+ }
134+
135+ private void checkSystemSupported () {
136+ if (isNotSupported ()) throw new UnsupportedSystemException (
137+ String .format (
138+ "%s (system: %s, version: %s)" ,
139+ "Your system does not support taskbar-progressbar!" ,
140+ System .getProperty ("os.name" ),
141+ System .getProperty ("os.version" )
142+ )
143+ );
144+ }
145+
118146 private static final class DaemonThread extends Thread {
119147 DaemonThread (Runnable runnable ) {
120148 super (runnable );
0 commit comments