mcd

package module
v0.0.0-...-cc38c68 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2018 License: MPL-2.0 Imports: 8 Imported by: 0

README

mcd-go

A library to read values from MCD (Mission Control Desktop) configuration files for Firefox addons. This is strongly designed to implement native messaging host applications.

This is a workaround alternative of missing storage.managed. See also the bug 1230802. After the API is landed, you should migrate to it.

Usage

import (
  "github.com/clear-code/mcd-go"

  "log"
  "encoding/json"
  "github.com/lhside/chrome-go"
)

type ReadConfigsResponse struct {
  Foo  string `json:"foo,omitempty"`
  Bar  int64  `json:"bar,omitempty"`
  Bazz bool   `json:"bazz,omitempty"`
}

func ReadConfigs() {
  configs, err := mcd.New()
  if err != nil {
    log.Fatal(err)
  }

  response := &ReadConfigsResponse{}

  foo, err := configs.GetStringValue("[email protected]")
  if err == nil { response.Foo = foo }
  bar, err := configs.GetIntegerValue("[email protected]")
  if err == nil { response.Bar = bar }
  bazz, err := configs.GetBooleanValue("[email protected]")
  if err == nil { response.Bazz = bazz }

  body, err := json.Marshal(response)
  if err != nil {
    log.Fatal(err)
  }
  err = chrome.Post(body, os.Stdout)
  if err != nil {
    log.Fatal(err)
  }
}

Restrictions

  • This just loads the first *.cfg file under the Firefox's directory.
    • If there are multiple files, others are simply ignored even if one of them is actually used.
    • Even if the *.cfg file is not used, this always loads it.
  • This just loads the failover.jsc file in the default Firefox profile placed under %AppData%\Mozilla\Profiles\*.default, as the remote configuration file. In other words, this doesn't fetch actual remote configuration file specified via autoadmin.global_config_url.
    • If you actually use different profile, this doesn't detect it.
  • Loaded configuration files are parsed in a sandbox.
    • Only limited directives are available.
    • User values in the profile are not accessible.
    • Components.utils.import() and other internal features don't work. If your configuration file depends on such internal technologies, this cannot load values correctly.

License

MPL 2.0

Documentation

Index

Constants

View Source
const PROCESS_VM_READ = 1 << 4

Variables

View Source
var DebugLogs []string

Functions

func GetFailoverJscPath

func GetFailoverJscPath() (path string, err error)

func GetFirstMatchedFile

func GetFirstMatchedFile(pattern string) (path string, err error)

func GetLocalConfigPath

func GetLocalConfigPath() (path string, err error)

func GetPathToRunningApp

func GetPathToRunningApp() (path string, err error)

func ReadLocalConfigs

func ReadLocalConfigs() (configs string)

func ReadRemoteConfigs

func ReadRemoteConfigs() (configs string)

Types

type Configs

type Configs struct {
	DebugLogs []string
	// contains filtered or unexported fields
}

func New

func New() (configs Configs, err error)

func (Configs) GetBooleanValue

func (c Configs) GetBooleanValue(key string) (booleanValue bool, err error)

func (Configs) GetIntegerValue

func (c Configs) GetIntegerValue(key string) (integerValue int64, err error)

func (Configs) GetStringValue

func (c Configs) GetStringValue(key string) (stringValue string, err error)

Jump to

Keyboard shortcuts

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