2021-10-30 22:05:24 +02:00
package io.gitlab.jfronny.inceptum.cli ;
import io.gitlab.jfronny.inceptum.Inceptum ;
import io.gitlab.jfronny.inceptum.InceptumGui ;
2021-10-31 16:59:25 +01:00
import io.gitlab.jfronny.inceptum.model.inceptum.CommandArguments ;
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateInfo ;
2021-10-31 18:55:51 +01:00
import io.gitlab.jfronny.inceptum.util.Utils ;
2021-10-31 18:17:43 +01:00
import io.gitlab.jfronny.inceptum.windows.MainWindow ;
2021-10-31 16:59:25 +01:00
import java.io.IOException ;
2021-10-31 18:55:51 +01:00
import java.net.URI ;
2021-10-31 16:59:25 +01:00
import java.net.URISyntaxException ;
2021-10-30 22:05:24 +02:00
public class GuiCommand extends Command {
public GuiCommand ( ) {
super ( " Displays the Inceptum UI " , " gui " , " show " ) ;
}
@Override
2021-10-31 16:59:25 +01:00
public void invoke ( CommandArguments args ) {
2021-10-30 22:05:24 +02:00
Inceptum . IS_GUI = true ;
2021-10-31 16:59:25 +01:00
UpdateInfo update = UpdateCheckCommand . getUpdate ( ) ;
2021-10-31 18:17:43 +01:00
InceptumGui . main ( args , ( ) - > {
if ( update = = null ) {
InceptumGui . WINDOWS . add ( new MainWindow ( ) ) ;
2021-10-31 18:55:51 +01:00
} else if ( args . wrapped ) {
2021-10-31 18:17:43 +01:00
Inceptum . showOkCancel ( " An update was found. Should it be installed automatically? " , " Update found " , ( ) - > {
try {
UpdateCheckCommand . update ( update , true ) ;
InceptumGui . exit ( ) ;
} catch ( IOException | URISyntaxException e ) {
Inceptum . showError ( " Could not download update " , e ) ;
}
} , ( ) - > InceptumGui . WINDOWS . add ( new MainWindow ( ) ) ) ;
2021-10-31 18:55:51 +01:00
} else {
Inceptum . showOkCancel ( " An update was found. Automatic installs are not supported without the wrapper but you can download it nonetheless " , " Update found " , ( ) - > {
try {
Utils . openWebBrowser ( new URI ( update . url ( ) ) ) ;
InceptumGui . exit ( ) ;
} catch ( URISyntaxException e ) {
Inceptum . showError ( " Could not download update " , e ) ;
}
} , ( ) - > InceptumGui . WINDOWS . add ( new MainWindow ( ) ) ) ;
2021-10-31 18:17:43 +01:00
}
} ) ;
2021-10-30 22:05:24 +02:00
}
@Override
public boolean enableLog ( ) {
return true ;
}
}