Exemplo n.º 1
0
func (app *App) CreateDesktopShortcut(launcher launchers.Launcher, referenceDescriptor descriptors.AppDescriptor) (err error) {
	desktopDir, err := caravel.GetUserDesktop()
	if err != nil {
		return err
	}

	if !caravel.DirectoryExists(desktopDir) {
		return fmt.Errorf("Expected desktop dir '%v' not found", desktopDir)
	}

	shortcutFileName := caravel.FormatFileName(referenceDescriptor.GetName()) + ".desktop"
	log.Debug("Shortcut file name: '%v'", shortcutFileName)

	shortcutFilePath := filepath.Join(desktopDir, shortcutFileName)

	log.Info("Creating desktop shortcut: '%v'...", shortcutFilePath)

	shortcutFile, err := os.OpenFile(shortcutFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0700)
	if err != nil {
		return err
	}
	defer func() {
		shortcutFile.Close()
		if err != nil {
			os.Remove(shortcutFilePath)
		}
	}()

	actualIconPath := app.GetActualIconPath(launcher)

	shortcutContent := fmt.Sprintf(linuxShortcutContent,
		referenceDescriptor.GetName(),
		referenceDescriptor.GetDescription(),
		launcher.GetExecutable(),
		app.GetLocalDescriptorPath(),
		actualIconPath)

	_, err = shortcutFile.Write([]byte(shortcutContent))
	if err != nil {
		return err
	}

	log.Notice("Desktop shortcut created")

	return nil
}
Exemplo n.º 2
0
func (app *App) CreateDesktopShortcut(launcher launchers.Launcher, referenceDescriptor descriptors.AppDescriptor) (err error) {
	desktopDir, err := caravel.GetUserDesktop()
	if err != nil {
		return err
	}

	if !caravel.DirectoryExists(desktopDir) {
		return fmt.Errorf("Expected desktop dir '%v' not found", desktopDir)
	}

	scriptFileName := caravel.FormatFileName(referenceDescriptor.GetName())
	log.Debug("Bash shortcut name: '%v'", scriptFileName)

	scriptFilePath := filepath.Join(desktopDir, scriptFileName)
	log.Info("Creating Bash shortcut: '%v'...", scriptFilePath)

	scriptFile, err := os.OpenFile(scriptFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0700)
	if err != nil {
		return err
	}
	defer func() {
		scriptFile.Close()

		if err != nil {
			os.Remove(scriptFilePath)
		}
	}()

	scriptContent := fmt.Sprintf(macScriptContentFormat,
		launcher.GetExecutable(),
		app.localDescriptorPath)

	_, err = scriptFile.Write([]byte(scriptContent))
	if err != nil {
		return err
	}

	log.Notice("Bash shortcut script created")

	return nil
}
Exemplo n.º 3
0
func NewGtkUserInterface(launcher launchers.Launcher) (userInterface *GtkUserInterface, err error) {
	userInterface = &GtkUserInterface{
		launcher: launcher,
	}

	gladeDescriptorPath := filepath.Join(
		filepath.Dir(launcher.GetExecutable()),
		"moondeploy.glade")

	runOnUIThreadAndWait(func() interface{} {
		builder, err := gtk.BuilderNew()
		if err != nil {
			panic(err)
		}

		err = builder.AddFromFile(gladeDescriptorPath)
		if err != nil {
			panic(err)
		}

		windowObject, err := builder.GetObject("mainWindow")
		if err != nil {
			panic(err)
		}
		window := windowObject.(*gtk.Window)
		userInterface.window = window

		launcher := userInterface.launcher

		window.SetTitle(launcher.GetTitle())
		window.SetIconFromFile(launcher.GetIconPathAsPng())

		window.Connect("destroy", func() {
			window.Destroy()
			userInterface.window = nil
			gtk.MainQuit()
			userInterface.closedByUser = true
		})

		appLabelObject, err := builder.GetObject("appLabel")
		if err != nil {
			panic(err)
		}
		userInterface.appLabel = appLabelObject.(*gtk.Label)

		headerLabelObject, err := builder.GetObject("headerLabel")
		if err != nil {
			panic(err)
		}
		userInterface.headerLabel = headerLabelObject.(*gtk.Label)

		statusLabelObject, err := builder.GetObject("statusLabel")
		if err != nil {
			panic(err)
		}
		userInterface.statusLabel = statusLabelObject.(*gtk.Label)

		progressBarObject, err := builder.GetObject("progressBar")
		if err != nil {
			panic(err)
		}
		userInterface.progressBar = progressBarObject.(*gtk.ProgressBar)

		return nil
	})

	return userInterface, nil
}