@@ -2,22 +2,30 @@ package funkin.backend.system.updating;
22
33import funkin .backend .system .github .GitHub ;
44import funkin .backend .system .github .GitHubRelease ;
5+ #if ALLOW_MULTITHREADING
6+ import funkin .backend .utils .ThreadUtil ;
7+ #end
58
69import lime .app .Application ;
710
8- import sys .thread .Mutex ;
9- import sys .thread .Thread ;
1011import sys .FileSystem ;
1112
1213import haxe .io .Path ;
1314
15+ #if (target.threaded)
16+ import sys .thread .Thread ;
17+ import sys .thread .Mutex ;
18+ #end
19+
1420using funkin .backend .system .github .GitHub ;
1521
1622class UpdateUtil {
1723 public static var lastUpdateCheck : Null <UpdateCheckCallback >;
1824
25+ #if (target.threaded)
1926 private static var __waitCallbacks : Array <UpdateCheckCallback -> Void >;
2027 private static var __mutex : Mutex ;
28+ #end
2129
2230 public static function init () {
2331 // deletes old bak file if it exists
@@ -26,26 +34,34 @@ class UpdateUtil {
2634 if (FileSystem .exists (bakPath )) FileSystem .deleteFile (bakPath );
2735 #end
2836
37+ #if (target.threaded)
2938 __waitCallbacks = [];
3039 __mutex = new Mutex ();
31- Thread .create (checkForUpdates .bind (true , false ));
40+
41+ #if ALLOW_MULTITHREADING ThreadUtil .execAsync #else Thread .create #end(checkForUpdates .bind (true , false ));
42+ #end
3243 }
3344
3445 public static function waitForUpdates (force = false , callback : UpdateCheckCallback -> Void , lazy = false ) {
46+ #if (target.threaded)
3547 if (__mutex .tryAcquire ()) {
3648 __mutex .release ();
3749 if (__shouldCheck (lazy ) || force ) {
3850 __waitCallbacks .push (callback );
39- Thread .create (checkForUpdates .bind (force , false ));
51+ #if ALLOW_MULTITHREADING ThreadUtil . execAsync #else Thread .create #end (checkForUpdates .bind (force , false ));
4052 }
4153 else
4254 callback (lastUpdateCheck );
4355 }
4456 else
4557 __waitCallbacks .push (callback );
58+ #else
59+ callback (checkForUpdates (true , false ));
60+ #end
4661 }
4762
4863 public static function checkForUpdates (force = false , lazy = false ): UpdateCheckCallback {
64+ #if (target.threaded)
4965 var wasAcquired = ! __mutex .tryAcquire ();
5066 if (wasAcquired ) __mutex .acquire ();
5167
@@ -60,8 +76,19 @@ class UpdateUtil {
6076 FlxG .signals .preUpdate .addOnce (__callWaitCallbacks );
6177
6278 return lastUpdateCheck ;
79+ #else
80+ if (! __shouldCheck (lazy )) return lastUpdateCheck ;
81+ return lastUpdateCheck = __checkForUpdates ();
82+ #end
6383 }
6484
85+ #if (target.threaded)
86+ static function __callWaitCallbacks () {
87+ for (callback in __waitCallbacks ) callback (lastUpdateCheck );
88+ __waitCallbacks .resize (0 );
89+ }
90+ #end
91+
6592 static function __checkForUpdates (): UpdateCheckCallback {
6693 var curTag = ' v' + (Flags .VERSION == null ? Application .current .meta .get (' version' ) : Flags .VERSION ), error = false ;
6794 var newUpdates = __doReleaseFiltering (GitHub .getReleases (Flags .REPO_OWNER , Flags .REPO_NAME , (e ) -> {
@@ -82,11 +109,6 @@ class UpdateUtil {
82109 static function __shouldCheck (lazy : Bool ): Bool
83110 return lastUpdateCheck == null || ! lazy && (!lastUpdateCheck .newUpdate || Date .now ().getTime () - lastUpdateCheck .date .getTime () > 1800000 );
84111
85- static function __callWaitCallbacks () {
86- for (callback in __waitCallbacks ) callback (lastUpdateCheck );
87- __waitCallbacks .resize (0 );
88- }
89-
90112 static function __doReleaseFiltering (releases : Array <GitHubRelease >, currentVersionTag : String ) {
91113 releases = releases .filterReleases (Options .betaUpdates , false );
92114 if (releases .length <= 0 )
0 commit comments