4040import com .spotifyxp .theming .ThemeLoader ;
4141import com .spotifyxp .updater .Updater ;
4242import com .spotifyxp .updater .UpdaterUI ;
43- import com .spotifyxp .utils .*;
43+ import com .spotifyxp .utils .ApplicationUtils ;
44+ import com .spotifyxp .utils .ArchitectureDetection ;
45+ import com .spotifyxp .utils .GraphicalMessage ;
46+ import com .spotifyxp .utils .Utils ;
4447import okhttp3 .*;
4548import org .jetbrains .annotations .NotNull ;
4649import org .jetbrains .annotations .Nullable ;
@@ -64,62 +67,68 @@ public class Initiator {
6467 static final Thread hook = new Thread (PlayerArea ::saveCurrentState , "Save play state" );
6568
6669 public static void main (String [] args ) {
67- PublicValues .argParser .parseArguments (args ); //Parsing the arguments
68- initEvents (); //Initializing the event support
69- new SplashPanel ().show (); //Initializing the splash panel
70- System .setProperty ("http.agent" , ApplicationUtils .getUserAgent ()); //Setting the user agent string that SpotifyXP uses
71- checkDebug (); //Checking if debug is enabled
72- detectOS (); //Detecting the operating system
73- detectArchitecture ();
74- checkSetup ();
75- initLanguageSupport (); //Initializing the language support
76- initConfig (); //Initializing the configuration
7770 try {
78- PublicValues .cache = new Cache (); //Initialize cache
79- } catch (IOException e ) {
80- GraphicalMessage .sorryErrorExit ("Failed to create cache: " + e .getMessage ());
81- }
82- checkLogPrintStream (); //Checking some stuff after config is available
83- setLanguage (); //Set the language to the one specified in the config
84- creatingLock (); //Creating the 'LOCK' file
85- PublicValues .defaultHttpClient = new OkHttpClient .Builder ()
86- .addNetworkInterceptor (new Interceptor () {
87- @ Override
88- public @ NotNull Response intercept (@ NotNull Interceptor .Chain chain ) throws IOException {
89- if (chain .request ().headers ().get ("User-Agent" ).contains ("Spotify/" )) return chain .proceed (chain .request ());
90- return chain .proceed (chain .request ().newBuilder ()
91- .header ("User-Agent" , ApplicationUtils .getUserAgent ())
92- .build ());
93- }
94- })
95- .build (); //Creating the default http client
96- initProxy ();
97- checkTrustStore ();
98- checkUpdate ();
99- if (Flags .videoPlaybackSupport ) initializeVideoPlayback ();
100- loadExtensions (); //Loading extensions if there are any
101- initGEH (); //Initializing the global exception handler
102- storeArguments (args ); //Storing the program arguments in PublicValues.class
103- parseAudioQuality (); //Parsing the audio quality
104- initThemes (); //Initializing the theming support
105- addShutdownHook (); //Adding the shutdown hook
106- initAPI (); //Initializing all the apis used
107- if (PublicValues .enableMediaControl )
108- createKeyListener (); //Starting the key listener (For Play/Pause/Previous/Next)
109- initTrayIcon (); //Creating the tray icon
110- try {
111- initGUI (); //Initializing the GUI
112- } catch (IOException e ) {
71+ PublicValues .argParser .parseArguments (args ); //Parsing the arguments
72+ initEvents (); //Initializing the event support
73+ new SplashPanel ().show (); //Initializing the splash panel
74+ System .setProperty ("http.agent" , ApplicationUtils .getUserAgent ()); //Setting the user agent string that SpotifyXP uses
75+ checkDebug (); //Checking if debug is enabled
76+ detectOS (); //Detecting the operating system
77+ detectArchitecture ();
78+ checkSetup ();
79+ initLanguageSupport (); //Initializing the language support
80+ initConfig (); //Initializing the configuration
81+ try {
82+ PublicValues .cache = new Cache (); //Initialize cache
83+ } catch (IOException e ) {
84+ GraphicalMessage .sorryErrorExit ("Failed to create cache: " + e .getMessage ());
85+ }
86+ checkLogPrintStream (); //Checking some stuff after config is available
87+ setLanguage (); //Set the language to the one specified in the config
88+ creatingLock (); //Creating the 'LOCK' file
89+ PublicValues .defaultHttpClient = new OkHttpClient .Builder ()
90+ .addNetworkInterceptor (new Interceptor () {
91+ @ Override
92+ public @ NotNull Response intercept (@ NotNull Interceptor .Chain chain ) throws IOException {
93+ if (chain .request ().headers ().get ("User-Agent" ).contains ("Spotify/" ))
94+ return chain .proceed (chain .request ());
95+ return chain .proceed (chain .request ().newBuilder ()
96+ .header ("User-Agent" , ApplicationUtils .getUserAgent ())
97+ .build ());
98+ }
99+ })
100+ .build (); //Creating the default http client
101+ initProxy ();
102+ checkTrustStore ();
103+ checkUpdate ();
104+ if (Flags .videoPlaybackSupport ) initializeVideoPlayback ();
105+ loadExtensions (); //Loading extensions if there are any
106+ initGEH (); //Initializing the global exception handler
107+ storeArguments (args ); //Storing the program arguments in PublicValues.class
108+ parseAudioQuality (); //Parsing the audio quality
109+ initThemes (); //Initializing the theming support
110+ addShutdownHook (); //Adding the shutdown hook
111+ initAPI (); //Initializing all the apis used
112+ if (PublicValues .enableMediaControl )
113+ createKeyListener (); //Starting the key listener (For Play/Pause/Previous/Next)
114+ initTrayIcon (); //Creating the tray icon
115+ try {
116+ initGUI (); //Initializing the GUI
117+ } catch (IOException e ) {
118+ ConsoleLogging .Throwable (e );
119+ GraphicalMessage .sorryError ("Critical exception in GUI initialization" );
120+ }
121+ SplashPanel .hide (); //Hiding the splash panel
122+ }catch (Exception e ) {
113123 ConsoleLogging .Throwable (e );
114- GraphicalMessage .sorryError ( "Critical exception in GUI initialization" );
124+ GraphicalMessage .openException ( e );
115125 }
116- SplashPanel .hide (); //Hiding the splash panel
117126 }
118127
119128 static void checkTrustStore () {
120129 try {
121130 Request request = new Request .Builder ()
122- .url ("https://spclient.wg.spotify.com/live-events-view/spotify.liveeventsview.v2.LiveEventsFeedService/GetPage " )
131+ .url ("https://spclient.wg.spotify.com/reachability/check " )
123132 .build ();
124133
125134 PublicValues .defaultHttpClient .newCall (request ).execute ();
@@ -128,7 +137,7 @@ static void checkTrustStore() {
128137 int response = JOptionPane .showConfirmDialog (null , "" , "" , JOptionPane .OK_CANCEL_OPTION , JOptionPane .ERROR_MESSAGE );
129138 if (response == JOptionPane .OK_OPTION ) {
130139 try {
131- ConnectionUtils .openBrowser ("https://github.com/JohnTHaller/RootCertificateUpdatesForLegacyWindows" );
140+ Utils .openBrowser ("https://github.com/JohnTHaller/RootCertificateUpdatesForLegacyWindows" );
132141 } catch (URISyntaxException | IOException ex ) {
133142 throw new RuntimeException (ex );
134143 }
@@ -214,7 +223,7 @@ static void checkDebug() {
214223 }
215224 }
216225
217- static void detectOS () {
226+ static void detectOS () throws IOException {
218227 SplashPanel .linfo .setText ("Detecting operating system..." );
219228 PublicValues .osType = libDetect .getDetectedOS ();
220229 new SupportModuleLoader ().loadModules ();
@@ -242,7 +251,7 @@ static void checkLogPrintStream() {
242251 PublicValues .logPrintStream .checkLogFiles ();
243252 }
244253
245- static void initializeVideoPlayback () {
254+ static void initializeVideoPlayback () throws IOException {
246255 if (Flags .videoPlaybackSupport ) {
247256 try {
248257 Class <?> util = Class .forName ("com.spotifyxp.deps.uk.co.caprica.vlcj.SPXPInit" );
@@ -262,7 +271,7 @@ static void initEvents() {
262271
263272 static void checkUpdate () {
264273 try {
265- if ( new Resources (). readToInputStream ("commit_id.txt" ) == null ) {
274+ if ( Initiator . class . getResourceAsStream ("commit_id.txt" ) == null ) {
266275 PublicValues .updaterDisabled = true ;
267276 return ;
268277 }
@@ -373,9 +382,7 @@ static void createKeyListener() {
373382
374383 static void initAPI () {
375384 SplashPanel .linfo .setText ("Creating api..." );
376- InstanceManager .getSpotifyAPI ();
377385 InstanceManager .getPlayer ();
378- InstanceManager .getPkce ();
379386 SplashPanel .linfo .setText ("Create advanced api key..." );
380387 InstanceManager .getUnofficialSpotifyApi ();
381388 }
0 commit comments