utils

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CheckRoot = func() error {
	currentUser, err := userCurrent()
	if err != nil {
		return fmt.Errorf("failed to get current user: %v", err)
	}

	if currentUser.Uid != "0" {
		return fmt.Errorf("the requested operation requires superuser privileges. use `sudo %s`", strings.Join(os.Args[0:], " "))
	}
	return nil
}
View Source
var GetBinPath = func() (string, error) {
	defaultCandidates := []string{
		"/usr/bin",
		"/usr/local/bin",
		"/bin",
		"/nix/var/nix/profiles/default/bin",
	}

	pathEnv := os.Getenv("PATH")
	paths := strings.Split(pathEnv, ":")

	for _, candidate := range defaultCandidates {
		for _, p := range paths {
			if p == candidate {
				if info, err := os.Stat(p); err == nil && info.IsDir() {
					return p, nil
				}
			}
		}
	}

	return "", fmt.Errorf("no supported bin path found: %+v", defaultCandidates)
}
View Source
var IsPackageInstalled = func(name string) bool {
	_, err := execLookPath(name)
	return err == nil
}

Check if package is installed

Functions

func AskForLocales added in v0.0.3

func AskForLocales(defaultLocales ...[]string) []string

func EnsureStringAndValid added in v0.0.3

func EnsureStringAndValid(name string, value interface{}, err error) (string, error)

func GetDataFromMetadata

func GetDataFromMetadata(key string) (interface{}, error)

GetDataFromMetadata reads metadata.json and returns the requested key's value from the KPlugin section

func GetDevDest

func GetDevDest() (string, error)

Get development destination path

func IsInstalled

func IsInstalled() (bool, string, error)

Check if plasmoid is installed

func IsLinked

func IsLinked() bool

check if plasmoid is linked

func IsQmlFile added in v0.0.4

func IsQmlFile(filename string) bool

func IsValidPlasmoid

func IsValidPlasmoid() bool

func LoadConfigRC

func LoadConfigRC() types.Config

func UpdateMetadata

func UpdateMetadata(key string, value interface{}, sectionOpt ...string) error

UpdateMetadata updates a key in the metadata.json file.

Parameters:

  • key: The key inside the section to update or create.
  • value: The new value to assign to the key.
  • section: The top-level section in metadata.json where the key is located. By default, this is "KPlugin", which is the standard location for Plasmoid metadata. If you're updating a key at the root level of the JSON, pass "." as the section.

Behavior:

  • If the section does not exist, it will be created automatically.
  • If the file cannot be read or parsed, a descriptive error will be returned.
  • The resulting JSON will be indented for readability.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL