Ejemplo n.º 1
0
func (app *App) CanPerformFirstRun(userInterface ui.UserInterface) bool {
	if caravel.IsSecureURL(app.bootDescriptor.GetDeclaredBaseURL()) {
		return userInterface.AskForSecureFirstRun(app.bootDescriptor)
	}

	return userInterface.AskForUntrustedFirstRun(app.bootDescriptor)
}
Ejemplo n.º 2
0
func (app *App) Launch(command *exec.Cmd, settings config.Settings, userInterface ui.UserInterface) (err error) {
	log.Info("Starting the app...")

	log.Debug("Hiding the user interface...")
	userInterface.Hide()
	log.Notice("User interface hidden")

	if settings.IsSkipAppOutput() {
		return command.Run()
	}
	var outputBytes []byte
	outputBytes, err = command.CombinedOutput()

	if outputBytes != nil && len(outputBytes) > 0 {
		log.Info("------------------------------")
		log.Info(string(outputBytes))
		log.Info("------------------------------")
	}

	return err
}
Ejemplo n.º 3
0
func setupUserInterface(launcher launchers.Launcher, userInterface ui.UserInterface) {
	userInterface.SetApp(launcher.GetTitle())

	log.SetCallback(func(level logging.Level, message string) {
		if level <= logging.INFO {
			userInterface.SetStatus(message)
		}
	})

	userInterface.Show()
}
Ejemplo n.º 4
0
func (app *App) CheckFiles(
	settings config.Settings,
	userInterface ui.UserInterface) (err error) {

	localDescriptor := app.GetLocalDescriptor()
	remoteDescriptor := app.GetRemoteDescriptor()

	if remoteDescriptor == nil {
		log.Notice("Skipping file check, as the remote descriptor is missing")
		return nil
	}

	userInterface.SetHeader("Checking the app files")
	log.Notice("Computing differences...")

	packagesToUpdate := app.getPackagesToUpdate()

	if len(packagesToUpdate) == 0 {
		log.Notice("All the packages are up-to-date")
		return nil
	}

	if localDescriptor != nil && caravel.FileExists(app.GetLocalDescriptorPath()) {
		log.Info("Deleting the local descriptor before starting the update process...")
		err = os.Remove(app.GetLocalDescriptorPath())
		if err != nil {
			return err
		}
		log.Notice("Local descriptor deleted")
	}

	retrieveAllPackages := (len(packagesToUpdate) == len(remoteDescriptor.GetPackageVersions()))
	log.Notice("Must retrieve all the remote packages? %v", retrieveAllPackages)

	if retrieveAllPackages {
		log.Info("Removing app files dir...")
		err = os.RemoveAll(app.filesDirectory)
		if err != nil {
			return err
		}
		log.Notice("App files dir removed")
	}

	for packageIndex, packageName := range packagesToUpdate {
		userInterface.SetHeader(
			fmt.Sprintf("Updating package %v of %v: %v",
				packageIndex+1,
				len(packagesToUpdate),
				packageName))

		log.Notice("Downloading %v...", packageName)

		err = app.installPackage(
			packageName,
			settings,
			func(retrievedSize int64, totalSize int64) {
				log.Notice("Retrieved: %v / %v bytes", retrievedSize, totalSize)
				userInterface.SetProgress(float64(retrievedSize) / float64(totalSize))
			})
		if err != nil {
			return err
		}
	}

	log.Notice("App files checked")
	return nil
}
Ejemplo n.º 5
0
/*
Run is the entry point you must employ to create a custom installer, for example to
employ custom settings or a brand-new user interface, based on any technology
*/
func Run(
	launcher launchers.Launcher,
	userInterface ui.UserInterface,
	bootDescriptor descriptors.AppDescriptor) (err error) {

	settings := launcher.GetSettings()

	//----------------------------------------------------------------------------

	setupUserInterface(launcher, userInterface)
	defer dismissUserInterface(userInterface)

	//----------------------------------------------------------------------------

	userInterface.SetHeader("Performing startup operations")

	log.Debug("The boot descriptor is: %#v", bootDescriptor)

	//----------------------------------------------------------------------------

	userInterface.SetApp(bootDescriptor.GetName())

	//----------------------------------------------------------------------------

	appGallery := apps.NewAppGallery(settings.GetGalleryDirectory())
	log.Debug("The app gallery is: %#v", appGallery)

	//----------------------------------------------------------------------------

	log.Info("Resolving the app...")
	app, err := appGallery.GetApp(bootDescriptor)
	if err != nil {
		return err
	}
	log.Notice("The app directory is: '%v'", app.Directory)

	log.Debug("App is: %#v", app)

	firstRun := !app.DirectoryExists()
	log.Debug("Is this a first run for the app? %v", firstRun)

	//----------------------------------------------------------------------------

	if firstRun {
		log.Info("Now asking the user if the app can run...")

		canRun := app.CanPerformFirstRun(userInterface)
		if !canRun {
			return &ExecutionCanceled{}
		}

		log.Debug("The user agreed to proceed")

		log.Info("Ensuring the app dir is available...")
		err = app.EnsureDirectory()
		if err != nil {
			return err
		}
		log.Notice("App dir available")
	}

	//----------------------------------------------------------------------------

	log.Info("Locking the app dir...")
	err = app.LockDirectory()
	if err != nil {
		return err
	}
	defer func() {
		unlockErr := app.UnlockDirectory()
		if unlockErr != nil {
			log.Warning(unlockErr.Error())
		}
	}()

	log.Notice("App dir locked")

	//----------------------------------------------------------------------------

	log.Info("Checking for conflicting local descriptors...")
	err = app.CheckForConflictingLocalDescriptors()
	if err != nil {
		return err
	}
	log.Notice("No conflicting local descriptors found")

	//----------------------------------------------------------------------------

	log.Info("Resolving the local descriptor...")
	localDescriptor := app.GetLocalDescriptor()

	startedWithLocalDescriptor := localDescriptor != nil
	log.Debug("Started with local descriptor? %v", startedWithLocalDescriptor)

	if startedWithLocalDescriptor {
		log.Info("Checking that local descriptor and boot descriptor actually match...")
		err = descriptors.CheckDescriptorMatch(localDescriptor, bootDescriptor)
		if err != nil {
			return err
		}
		log.Notice("The descriptors match correctly")
	}

	//----------------------------------------------------------------------------

	log.Info("Resolving the remote descriptor...")
	remoteDescriptor := app.GetRemoteDescriptor()

	if remoteDescriptor != nil {
		log.Info("Checking that remote descriptor and boot descriptor actually match...")
		err = descriptors.CheckDescriptorMatch(remoteDescriptor, bootDescriptor)
		if err != nil {
			return err
		}
		log.Notice("The descriptors match correctly")
	}

	//----------------------------------------------------------------------------

	log.Info("Now choosing the reference descriptor...")
	referenceDescriptor, err := app.GetReferenceDescriptor()
	if err != nil {
		return err
	}
	log.Notice("Reference descriptor chosen")

	log.Debug("The reference descriptor is: %#v", referenceDescriptor)

	//----------------------------------------------------------------------------

	err = referenceDescriptor.CheckRequirements()
	if err != nil {
		return err
	}

	//----------------------------------------------------------------------------

	userInterface.SetApp(referenceDescriptor.GetTitle())

	//----------------------------------------------------------------------------

	log.Info("Resolving the OS-specific app command line...")
	commandLine := referenceDescriptor.GetCommandLine()
	log.Notice("Command line resolved")

	log.Debug("Command line is: %v", commandLine)

	//----------------------------------------------------------------------------

	err = app.CheckFiles(settings, userInterface)
	if err != nil {
		return err
	}

	//----------------------------------------------------------------------------

	userInterface.SetHeader("Preparing the command...")

	log.Info("Creating the command...")
	command := app.PrepareCommand(commandLine)
	log.Notice("Command created")

	log.Debug("Command path: %v", command.Path)
	log.Debug("Command arguments: %v", command.Args)

	//----------------------------------------------------------------------------

	referenceDescriptorSaved := app.SaveReferenceDescriptor()

	if !startedWithLocalDescriptor && referenceDescriptorSaved {
		if userInterface.AskForDesktopShortcut(referenceDescriptor) {
			log.Info("Creating desktop shortcut...")

			err = app.CreateDesktopShortcut(launcher, referenceDescriptor)
			if err != nil {
				log.Warning("Could not create desktop shortcut: %v", err)
			} else {
				log.Notice("Desktop shortcut created")
			}
		} else {
			log.Info("The user refused to create a desktop shortcut")
		}
	}

	//----------------------------------------------------------------------------

	app.UnlockDirectory()

	//----------------------------------------------------------------------------

	userInterface.SetHeader("Launching the application")
	userInterface.SetStatus("")

	return app.Launch(command, settings, userInterface)
}
Ejemplo n.º 6
0
func dismissUserInterface(userInterface ui.UserInterface) {
	log.SetCallback(func(level logging.Level, message string) {})

	userInterface.Hide()
}