modules

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Modules allow the extension of gosuki to handle other types of browsers or source of data that can be turned into bookmarks.

Module Types

  1. Browsers MUST implement the BrowserModule interface.
  2. Simple modules MUST implement the Module interface.

# Generic Modules A module must at least implement one of: - watch.Poller - watch.WatchLoader - (optionally) modules.MsgListener OR just implement modules.MsgListener

Index

Constants

View Source
const (
	MissingPath        string = "path error" // non existing path or path error
	MissingCredentials string = "missing credentials"
)
View Source
const (
	MsgTriggerSync = iota
	MsgHello
	MsgPanic

	MsgSyncPeers
)

types of messages passed between modules

View Source
const DispatcherID = "dispatcher"

Variables

View Source
var (
	ErrMissingCredentials = errors.New("missing credentials")
	ErrWatcherSetup       = errors.New("could not setup file watcher")
)
View Source
var ModMsgBus = make(chan ModMsg) // Channel for intra-process message passing
View Source
var (
	MsgDispatcher = modMsgDispatcher{
		// contains filtered or unexported fields
	}
)
View Source
var (
	ReducerChanLen = 1000
)

reducer channel length, bigger means less sensitivity to events

Functions

func Disable

func Disable(id ModID)

func Disabled

func Disabled(id ModID) bool

func RegisterBrowser

func RegisterBrowser(bm BrowserModule)

func RegisterModule

func RegisterModule(module Module)

func SetupBrowser

func SetupBrowser(browser BrowserModule, c *Context, p *profiles.Profile) error

SetupBrowser() is called for every browser module. It sets up the browser and calls the following methods if they are implemented by the module:

  1. Initializer.Init() : state initialization
  2. PreLoader.Load(): initial preloading of bookmarks

func SetupModule

func SetupModule(mod Module, c *Context) error

SetupModule() is called for each registered module. The following methods, if implemented, are called in order:

1. Initializer.Init(): state initialization

2. PreLoader.Load(): Initial pre loading of data before any runtime loop

func SetupWatchers

func SetupWatchers(browserConf *BrowserConfig, watches ...*watch.Watch) (bool, error)

SetupWatchers sets up a filesystem watch using the provided []Watch elements Returns true if a new watcher was created. false if it was previously created or if the browser does not need a watcher (UseFileWatcher == false).

func SetupWatchersWithReducer

func SetupWatchersWithReducer(browserConf *BrowserConfig,
	reducerChanLen int,
	watches ...*watch.Watch) (bool, error)

Types

type Browser

type Browser interface {
	// Returns a pointer to an initialized browser config
	Config() *BrowserConfig
}

type BrowserConfig

type BrowserConfig struct {
	Name string

	// Path to the browser base config directory
	BaseDir string

	// Absolute path to the browser's bookmark directory
	BkDir string

	// Name of bookmarks file
	BkFile string

	// In memory sqlite db (named `memcache`).
	// Used to keep a browser's state of bookmarks across jobs.
	BufferDB *database.DB

	// Fast query db using an RB-Tree hashmap.
	// It represents a URL index of the last running job
	URLIndex index.HashTree

	// Pointer to the root of the node tree
	// The node tree is built again for every Run job on a browser
	NodeTree *tree.Node

	// Watch for changes on the bookmark file
	UseFileWatcher bool

	// Hooks registered by the browser module identified by name
	UseHooks []string
	// contains filtered or unexported fields
}

BrowserConfig is the main browser configuration shared by all browser modules.

func (BrowserConfig) BookmarkPath

func (b BrowserConfig) BookmarkPath() (string, error)

BookmarkPath returns the absolute path to the bookmark file. It expands the path by concatenating the base directory and bookmarks file, then checks if it exists.

func (BrowserConfig) CallHooks

func (b BrowserConfig) CallHooks(obj any) error

CallHooks calls all registered hooks for this browser for the given *tree.Node or *gosuki.Bookmark. The hooks are called in the order they were registered. This is usually done within the parsing logic of a browser module, typically in the Run() method. These hooks will be called everytime browser bookmarks are parsed.

func (*BrowserConfig) GetWatcher

func (b *BrowserConfig) GetWatcher() *watch.WatchDescriptor

func (BrowserConfig) RebuildIndex

func (b BrowserConfig) RebuildIndex()

Rebuilds the memory url index after parsing all bookmarks. Keeps the memory url index in sync with last known state of browser bookmarks

type BrowserModule

type BrowserModule interface {
	Browser
	Module
}

browser modules need to implement Browser interface

func GetBrowserModules

func GetBrowserModules() []BrowserModule

type BrowserType

type BrowserType uint8

type Context

type Context struct {
	context.Context

	Cli *cli.Command
}

type Detected

type Detected struct {
	Flavour string

	// Canonical path to the browser config directory
	BasePath string
}

type Detector

type Detector interface {
	// List of detected browser instances
	Detect() ([]Detected, error)
}

Browsers must offer a way to detect if they are installed on the system and display path to their base directory. Note that if the browser module already implements profiles.ProfileManager, implementing this interface is redundant.

type DumbPreLoader

type DumbPreLoader interface {
	PreLoad() ([]*gosuki.Bookmark, error)
}

This type of PreLoader simply returns a list of bookmarks and has no knwoledge of the loading and syncrhonization primitives. Mostly useful for simple modules (see `modules.BookmarksImporter`).

type ErrModDisabled added in v1.1.1

type ErrModDisabled struct {
	Reason string
	Err    error
}

func (*ErrModDisabled) Error added in v1.1.1

func (e *ErrModDisabled) Error() string

type Initializer

type Initializer interface {

	// Init() is the first method called after a browser instance is created
	// and registered.
	// A pointer to
	// Return ok, error
	Init(*Context) error
}

Initialize the module before any data loading or callbacks If a module wants to do any preparation and prepare custom state before Loader.Load() is called and before any Watchable.Run() or other callbacks are executed.

type Listener added in v1.1.0

type Listener struct {
	Ctx   context.Context
	Queue chan ModMsg
	MsgListener
}

Listener is a Work unit for modules that implement the MsgListener interface

func (Listener) Run added in v1.1.0

func (lw Listener) Run(m manager.UnitManager)

type ModID

type ModID string

type ModInfo

type ModInfo struct {
	ID ModID // Id of this module

	// New returns a pointer to a new instance of a gosuki module.
	// Browser modules MUST implement this method.
	New func() Module
}

Information related to the browser module

type ModMsg added in v1.1.0

type ModMsg struct {
	Type    ModMsgType
	To      ModID
	Payload any
}

ModMsg is a message exchanged between modules

type ModMsgType added in v1.1.0

type ModMsgType int

type Module

type Module interface {
	ModInfo() ModInfo
}

Every new module needs to register as a Module using this interface

func GetModules

func GetModules() []Module

Returns a list of registerd modules

type MsgListener added in v1.1.0

type MsgListener interface {
	MsgListen(context.Context, <-chan ModMsg)
}

MsgListener is a module that can listen to messages from other mods

type PreLoader

type PreLoader interface {

	// PreLoad() will be called right after a browser is initialized
	PreLoad(*Context) error
}

PreLoader is an interface for modules which is run only once when the module starts. It should have the same effect as Watchable.Run(). Run() is automatically called for watched events, Load() is called once before starting to watch events.

PreLoader allows modules to do a first pass of bookmark loading logic before the watcher threads is spawned

type ProfileInitializer

type ProfileInitializer interface {
	Init(*Context, *profiles.Profile) error
}

ProfileInitializer is similar to Initializer but is called with a profile. This is useful for modules that need to do some custom initialization for a specific profile.

type ProfilePrefs

type ProfilePrefs struct {
	// Whether to watch all the profiles for multi-profile modules
	WatchAllProfiles bool `toml:"watch-all-profiles" mapstructure:"watch-all-profiles"`

	Profile string `toml:"profile" mapstructure:"profile"`
}

The profile preferences for modules with builtin profile management.

type Shutdowner

type Shutdowner interface {
	watch.Shutdowner
}

Modules which implement this interface need to handle all shuttind down and cleanup logic in the defined methods. This is usually called at the end of the module instance lifetime

Jump to

Keyboard shortcuts

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