Ejemplo n.º 1
0
func TestNewPack(t *testing.T) {
	appname := "Audio"

	// Load package.
	pack, e := packages.NewAppletPackageUser(logger, appDir, appname, packages.TypeGoInternal, packages.SourceApplet)
	assert.NoError(t, e, "NewAppletPackageUser")
	validatePack(t, pack)

	// Read values.
	assert.Equal(t, appname, pack.DisplayedName, "DisplayedName")
	assert.Equal(t, "SQP", pack.Author, "Author")
	assert.Equal(t, "0.0.4", pack.Version, "Version")
	assert.Equal(t, 6, pack.Category, "Category")
	assert.False(t, pack.IsMultiInstance, "IsMultiInstance")
	assert.True(t, pack.ActAsLauncher, "ActAsLauncher")
	assert.True(t, strings.HasPrefix(pack.Description, "Pulseaudio"), "Description")
}
Ejemplo n.º 2
0
func (ed *Editor) save(appID int) error {
	pack := ed.packs[appID]

	if len(ed.edits) == 0 || pack == nil {
		return nil
	}

	group := pack.Source.Group()
	newver := ""

	// Update version first in applet config file.
	// When an upgrade is requested, we have to change versions in both files,
	// so the config upgrade becomes mandatory.
	if delta, upVer := ed.edits[fieldVersion]; upVer {
		var e error
		newver, e = packages.FormatNewVersion(pack.Version, delta.(int))
		if e != nil {
			return e
		}
		filename := filepath.Join(pack.Path, pack.DisplayedName+".conf")
		e = config.SetFileVersion(ed.log, filename, "Icon", pack.Version, newver)
		if e != nil {
			return e
		}
	}

	// Update edited fields.
	filename := filepath.Join(pack.Path, pack.Source.File())
	e := config.SetToFile(ed.log, filename, func(cfg cdtype.ConfUpdater) (e error) {
		for k, v := range ed.edits {
			switch k {
			case fieldVersion:
				e = cfg.Set(group, "version", newver)

			case fieldCategory:
				e = cfg.Set(group, "category", v.(int))

			case fieldActAsLauncher:
				e = cfg.Set(group, "act as launcher", v.(bool))

			case fieldMultiInstance:
				e = cfg.Set(group, "multi-instance", v.(bool))
			}
			if e != nil {
				return e
			}
		}
		return nil
	})
	if e != nil {
		return e
	}

	// Reload data from disk.
	pack, e = packages.NewAppletPackageUser(ed.log,
		filepath.Dir(pack.Path), filepath.Base(pack.Path),
		pack.Type, pack.Source)

	if e != nil {
		return e
	}
	ed.packs[appID] = pack
	ed.edits = nil
	return nil
}