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 ¶
- Browsers MUST implement the BrowserModule interface.
- 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
- Variables
- func Disable(id ModID)
- func Disabled(id ModID) bool
- func RegisterBrowser(bm BrowserModule)
- func RegisterModule(module Module)
- func SetupBrowser(browser BrowserModule, c *Context, p *profiles.Profile) error
- func SetupModule(mod Module, c *Context) error
- func SetupWatchers(browserConf *BrowserConfig, watches ...*watch.Watch) (bool, error)
- func SetupWatchersWithReducer(browserConf *BrowserConfig, reducerChanLen int, watches ...*watch.Watch) (bool, error)
- type Browser
- type BrowserConfig
- type BrowserModule
- type BrowserType
- type Context
- type Detected
- type Detector
- type DumbPreLoader
- type ErrModDisabled
- type Initializer
- type Listener
- type ModID
- type ModInfo
- type ModMsg
- type ModMsgType
- type Module
- type MsgListener
- type PreLoader
- type ProfileInitializer
- type ProfilePrefs
- type Shutdowner
Constants ¶
const ( MissingPath string = "path error" // non existing path or path error MissingCredentials string = "missing credentials" )
const ( MsgTriggerSync = iota MsgHello MsgPanic MsgSyncPeers )
types of messages passed between modules
const DispatcherID = "dispatcher"
Variables ¶
var ( ErrMissingCredentials = errors.New("missing credentials") ErrWatcherSetup = errors.New("could not setup file watcher") )
var ModMsgBus = make(chan ModMsg) // Channel for intra-process message passing
var ( MsgDispatcher = modMsgDispatcher{ // contains filtered or unexported fields } )
var (
ReducerChanLen = 1000
)
reducer channel length, bigger means less sensitivity to events
Functions ¶
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:
- Initializer.Init() : state initialization
- PreLoader.Load(): initial preloading of bookmarks
func SetupModule ¶
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).
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 ¶
browser modules need to implement Browser interface
func GetBrowserModules ¶
func GetBrowserModules() []BrowserModule
type BrowserType ¶
type BrowserType uint8
type Detector ¶
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 ¶
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
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 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
type MsgListener ¶ added in v1.1.0
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 ¶
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