chrome profile manager, refactored firefox config
- BUG: firefox watch all cmd flag not available in daemon.go due to using a new instance - Updated/fixed saving & loading to toml config file - wip module cmd flag
This commit is contained in:
parent
8a233ca9a6
commit
c825972cfd
@ -41,10 +41,11 @@ import (
|
|||||||
|
|
||||||
"github.com/buger/jsonparser"
|
"github.com/buger/jsonparser"
|
||||||
|
|
||||||
"git.blob42.xyz/gosuki/gosuki/internal/database"
|
|
||||||
"git.blob42.xyz/gosuki/gosuki/hooks"
|
"git.blob42.xyz/gosuki/gosuki/hooks"
|
||||||
|
"git.blob42.xyz/gosuki/gosuki/internal/database"
|
||||||
"git.blob42.xyz/gosuki/gosuki/internal/logging"
|
"git.blob42.xyz/gosuki/gosuki/internal/logging"
|
||||||
"git.blob42.xyz/gosuki/gosuki/pkg/modules"
|
"git.blob42.xyz/gosuki/gosuki/pkg/modules"
|
||||||
|
"git.blob42.xyz/gosuki/gosuki/pkg/profiles"
|
||||||
"git.blob42.xyz/gosuki/gosuki/pkg/tree"
|
"git.blob42.xyz/gosuki/gosuki/pkg/tree"
|
||||||
"git.blob42.xyz/gosuki/gosuki/pkg/watch"
|
"git.blob42.xyz/gosuki/gosuki/pkg/watch"
|
||||||
)
|
)
|
||||||
@ -135,11 +136,8 @@ func (ch *Chrome) Init(_ *modules.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ch *Chrome) setupWatchers() error {
|
func (ch *Chrome) setupWatchers() error {
|
||||||
bookmarkDir, err := ch.BookmarkDir()
|
bookmarkDir := ch.BkDir
|
||||||
log.Debugf("Watching path: %s", bookmarkDir)
|
log.Debugf("Watching path: %s", bookmarkDir)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
bookmarkPath := filepath.Join(bookmarkDir, ch.BkFile)
|
bookmarkPath := filepath.Join(bookmarkDir, ch.BkFile)
|
||||||
// Setup watcher
|
// Setup watcher
|
||||||
w := &watch.Watch{
|
w := &watch.Watch{
|
||||||
@ -455,6 +453,8 @@ func (ch *Chrome) Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Load() will be called right after a browser is initialized
|
// Load() will be called right after a browser is initialized
|
||||||
func (ch *Chrome) Load() error {
|
func (ch *Chrome) Load() error {
|
||||||
go ch.Run()
|
go ch.Run()
|
||||||
@ -479,3 +479,4 @@ var _ modules.Loader = (*Chrome)(nil)
|
|||||||
var _ watch.WatchRunner = (*Chrome)(nil)
|
var _ watch.WatchRunner = (*Chrome)(nil)
|
||||||
var _ hooks.HookRunner = (*Chrome)(nil)
|
var _ hooks.HookRunner = (*Chrome)(nil)
|
||||||
var _ watch.Stats = (*Chrome)(nil)
|
var _ watch.Stats = (*Chrome)(nil)
|
||||||
|
var _ profiles.ProfileManager = (*Chrome)(nil)
|
||||||
|
54
browsers/chrome/chrome_test.go
Normal file
54
browsers/chrome/chrome_test.go
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// Copyright (c) 2023 Chakib Ben Ziane <contact@blob42.xyz> and [`gosuki` contributors](https://github.com/blob42/gosuki/graphs/contributors).
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
//
|
||||||
|
// This file is part of GoSuki.
|
||||||
|
//
|
||||||
|
// GoSuki is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// GoSuki is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with gosuki. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
package chrome
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.blob42.xyz/gosuki/gosuki/internal/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
const statePath = "~/.config/google-chrome/Local State"
|
||||||
|
|
||||||
|
func TestLoadLocalState(t *testing.T) {
|
||||||
|
var state *StateData
|
||||||
|
fullPath, err := utils.ExpandPath(statePath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
state, err = loadLocalState(fullPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("\nstate:\n%+v\n", state)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetProfiles(t *testing.T) {
|
||||||
|
ch := &Chrome{}
|
||||||
|
profiles, err := ch.GetProfiles(ChromeStable)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, prof := range profiles {
|
||||||
|
fmt.Printf("\nprofiles:\n%#v\n", prof)
|
||||||
|
fmt.Println(prof.AbsolutePath())
|
||||||
|
}
|
||||||
|
}
|
@ -22,31 +22,61 @@
|
|||||||
package chrome
|
package chrome
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.blob42.xyz/gosuki/gosuki/internal/config"
|
||||||
"git.blob42.xyz/gosuki/gosuki/pkg/modules"
|
"git.blob42.xyz/gosuki/gosuki/pkg/modules"
|
||||||
"git.blob42.xyz/gosuki/gosuki/pkg/parsing"
|
"git.blob42.xyz/gosuki/gosuki/pkg/parsing"
|
||||||
|
"git.blob42.xyz/gosuki/gosuki/pkg/profiles"
|
||||||
"git.blob42.xyz/gosuki/gosuki/pkg/tree"
|
"git.blob42.xyz/gosuki/gosuki/pkg/tree"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BrowserName = "chrome"
|
BrowserName = ChromeStable
|
||||||
ChromeBaseDir = "$HOME/.config/google-chrome"
|
ChromeBaseDir = "$HOME/.config/google-chrome"
|
||||||
DefaultProfile = "Default"
|
DefaultProfile = "Default"
|
||||||
RootNodeName = "ROOT"
|
RootNodeName = "ROOT"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type ChromeConfig struct {
|
type ChromeConfig struct {
|
||||||
Profile string
|
|
||||||
*modules.BrowserConfig `toml:"-"`
|
*modules.BrowserConfig `toml:"-"`
|
||||||
modules.ProfilePrefs `toml:"profile_options"`
|
modules.ProfilePrefs `toml:"profile_options" mapstructure:"profile_options"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ChromeCfg = &ChromeConfig{
|
ProfileManager = &ChromeProfileManager{}
|
||||||
Profile: DefaultProfile,
|
|
||||||
|
ChromeCfg = NewChromeConfig()
|
||||||
|
)
|
||||||
|
|
||||||
|
func setBookmarkDir(cc *ChromeConfig) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// load profile from config
|
||||||
|
var profile *profiles.Profile
|
||||||
|
|
||||||
|
// In chrome we need to identify the profiles by their ID to get the correct
|
||||||
|
// path
|
||||||
|
if profile, err = ProfileManager.GetProfileByID(BrowserName, cc.Profile); err != nil {
|
||||||
|
log.Warning(err)
|
||||||
|
} else {
|
||||||
|
bookmarkDir, err := profile.AbsolutePath()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cc.BkDir = bookmarkDir
|
||||||
|
log.Debugf("Using profile %s", bookmarkDir)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewChromeConfig() *ChromeConfig {
|
||||||
|
|
||||||
|
config := &ChromeConfig{
|
||||||
BrowserConfig: &modules.BrowserConfig{
|
BrowserConfig: &modules.BrowserConfig{
|
||||||
Name: BrowserName,
|
Name: BrowserName,
|
||||||
Type: modules.TChrome,
|
Type: modules.TChrome,
|
||||||
BkDir: "$HOME/.config/google-chrome/Default",
|
|
||||||
BkFile: "Bookmarks",
|
BkFile: "Bookmarks",
|
||||||
NodeTree: &tree.Node{
|
NodeTree: &tree.Node{
|
||||||
Name: RootNodeName,
|
Name: RootNodeName,
|
||||||
@ -57,6 +87,16 @@ var (
|
|||||||
UseFileWatcher: true,
|
UseFileWatcher: true,
|
||||||
UseHooks: []string{"tags_from_name", "notify-send"},
|
UseHooks: []string{"tags_from_name", "notify-send"},
|
||||||
},
|
},
|
||||||
//TODO: profile
|
ProfilePrefs: modules.ProfilePrefs{
|
||||||
|
Profile: DefaultProfile,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
setBookmarkDir(config)
|
||||||
|
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
config.RegisterConfigurator(BrowserName, config.AsConfigurator(ChromeCfg))
|
||||||
|
}
|
||||||
|
167
browsers/chrome/profiles.go
Normal file
167
browsers/chrome/profiles.go
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
// Copyright (c) 2023 Chakib Ben Ziane <contact@blob42.xyz> and [`gosuki` contributors](https://github.com/blob42/gosuki/graphs/contributors).
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
//
|
||||||
|
// This file is part of GoSuki.
|
||||||
|
//
|
||||||
|
// GoSuki is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// GoSuki is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with gosuki. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
package chrome
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"git.blob42.xyz/gosuki/gosuki/internal/utils"
|
||||||
|
"git.blob42.xyz/gosuki/gosuki/pkg/profiles"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Chrome state file.
|
||||||
|
// The state file is a json file containing the last used profile and the list
|
||||||
|
// of profiles. Equivalent to the profiles.ini file for mozilla browsers.
|
||||||
|
const StateFile = "Local State"
|
||||||
|
|
||||||
|
// Chrome flavour names
|
||||||
|
const (
|
||||||
|
ChromeStable = "chrome"
|
||||||
|
ChromeUnstable = "chrome-unstable"
|
||||||
|
//TODO:
|
||||||
|
// Chromium = "chromium"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
var (
|
||||||
|
ChromeBrowsers = map[string]profiles.BrowserFlavour{
|
||||||
|
ChromeStable: {ChromeStable, "~/.config/google-chrome" },
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Helper struct to manage chrome profiles
|
||||||
|
// profiles.ProfileManager is implemented at the browser level
|
||||||
|
type ChromeProfileManager struct {}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns all profiles for a given flavour
|
||||||
|
func (*ChromeProfileManager) GetProfiles(flavour string) ([]*profiles.Profile, error) {
|
||||||
|
var result []*profiles.Profile
|
||||||
|
|
||||||
|
f, ok := ChromeBrowsers[flavour]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unknown flavour <%s>", flavour)
|
||||||
|
}
|
||||||
|
statePath, err := utils.ExpandPath(f.BaseDir, StateFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
state, err := loadLocalState(statePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for id, profile := range state.Profile.InfoCache {
|
||||||
|
result = append(result, &profiles.Profile{
|
||||||
|
Id: id,
|
||||||
|
Name: profile.Name,
|
||||||
|
Path: id,
|
||||||
|
BaseDir: f.BaseDir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Chrome) GetProfiles(flavour string) ([]*profiles.Profile, error) {
|
||||||
|
return ProfileManager.GetProfiles(flavour)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns all flavours supported by this browser
|
||||||
|
func (*Chrome) ListFlavours() []profiles.BrowserFlavour {
|
||||||
|
var result []profiles.BrowserFlavour
|
||||||
|
|
||||||
|
// detect local flavours
|
||||||
|
for _, v := range ChromeBrowsers {
|
||||||
|
if v.Detect() {
|
||||||
|
result = append(result, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// If should watch all profiles
|
||||||
|
func (chrome *Chrome) WatchAllProfiles() bool {
|
||||||
|
return chrome.ChromeConfig.WatchAllProfiles
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (cpm *ChromeProfileManager) GetProfileByID (flavour string, id string) (*profiles.Profile, error) {
|
||||||
|
profiles, err := cpm.GetProfiles(flavour)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range profiles {
|
||||||
|
if p.Id == id {
|
||||||
|
return p, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("profile %s not found", id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notifies the module to use a custom profile
|
||||||
|
//NOTE: this is implemented at the browser Level
|
||||||
|
func (c *Chrome) UseProfile(p profiles.Profile) error {
|
||||||
|
c.Profile = p.Name
|
||||||
|
|
||||||
|
// setup the bookmark dir
|
||||||
|
if bookmarkDir, err := p.AbsolutePath(); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
c.BkDir = bookmarkDir
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type StateData struct {
|
||||||
|
LastUsed string
|
||||||
|
Profile struct {
|
||||||
|
InfoCache map[string]profiles.Profile `json:"info_cache"`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func loadLocalState(path string) (*StateData, error) {
|
||||||
|
var state StateData
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
data, err := io.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &state)
|
||||||
|
return &state, err
|
||||||
|
}
|
@ -23,7 +23,7 @@
|
|||||||
package firefox
|
package firefox
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"git.blob42.xyz/gosuki/gosuki/internal/config"
|
"git.blob42.xyz/gosuki/gosuki/internal/config"
|
||||||
"git.blob42.xyz/gosuki/gosuki/internal/database"
|
"git.blob42.xyz/gosuki/gosuki/internal/database"
|
||||||
@ -32,9 +32,6 @@ import (
|
|||||||
"git.blob42.xyz/gosuki/gosuki/pkg/parsing"
|
"git.blob42.xyz/gosuki/gosuki/pkg/parsing"
|
||||||
"git.blob42.xyz/gosuki/gosuki/pkg/profiles"
|
"git.blob42.xyz/gosuki/gosuki/pkg/profiles"
|
||||||
"git.blob42.xyz/gosuki/gosuki/pkg/tree"
|
"git.blob42.xyz/gosuki/gosuki/pkg/tree"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
|
||||||
"github.com/mitchellh/mapstructure"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -44,6 +41,7 @@ const (
|
|||||||
|
|
||||||
// Default flavour to use
|
// Default flavour to use
|
||||||
BrowserName = mozilla.FirefoxFlavour
|
BrowserName = mozilla.FirefoxFlavour
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -73,25 +71,24 @@ var (
|
|||||||
// config file options will only be accepted if they are defined here.
|
// config file options will only be accepted if they are defined here.
|
||||||
type FirefoxConfig struct {
|
type FirefoxConfig struct {
|
||||||
// Default data source name query options for `places.sqlite` db
|
// Default data source name query options for `places.sqlite` db
|
||||||
PlacesDSN database.DsnOptions
|
PlacesDSN database.DsnOptions `toml:"-"`
|
||||||
Profile string
|
|
||||||
|
|
||||||
modules.ProfilePrefs `toml:"profile_options"`
|
modules.ProfilePrefs `toml:"profile_options" mapstructure:"profile_options"`
|
||||||
|
|
||||||
//TEST: ignore this field in config.Configurator interface
|
//TEST: ignore this field in config.Configurator interface
|
||||||
// Embed base browser config
|
// Embed base browser config
|
||||||
*modules.BrowserConfig `toml:"-"`
|
*modules.BrowserConfig `toml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//REFACT: move logic to modules package and use interface as input
|
||||||
func setBookmarkDir(fc *FirefoxConfig) {
|
func setBookmarkDir(fc *FirefoxConfig) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// load the default profile from the one defined in the config
|
// load profile from config
|
||||||
var profile *profiles.Profile
|
var profile *profiles.Profile
|
||||||
if profile, err = FirefoxProfileManager.GetProfileByName(BrowserName, fc.Profile); err != nil {
|
if profile, err = FirefoxProfileManager.GetProfileByName(BrowserName, fc.Profile); err != nil {
|
||||||
log.Fatal(err)
|
log.Warning(err)
|
||||||
}
|
} else {
|
||||||
|
|
||||||
bookmarkDir, err := profile.AbsolutePath()
|
bookmarkDir, err := profile.AbsolutePath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -99,15 +96,16 @@ func setBookmarkDir(fc *FirefoxConfig) {
|
|||||||
|
|
||||||
fc.BkDir = bookmarkDir
|
fc.BkDir = bookmarkDir
|
||||||
log.Debugf("Using profile %s", bookmarkDir)
|
log.Debugf("Using profile %s", bookmarkDir)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFirefoxConfig() *FirefoxConfig {
|
func NewFirefoxConfig() *FirefoxConfig {
|
||||||
|
|
||||||
config := &FirefoxConfig{
|
cfg := &FirefoxConfig{
|
||||||
BrowserConfig: &modules.BrowserConfig{
|
BrowserConfig: &modules.BrowserConfig{
|
||||||
Name: BrowserName,
|
Name: BrowserName,
|
||||||
Type: modules.TFirefox,
|
Type: modules.TFirefox,
|
||||||
BkDir: "",
|
|
||||||
BkFile: mozilla.PlacesFile,
|
BkFile: mozilla.PlacesFile,
|
||||||
NodeTree: &tree.Node{
|
NodeTree: &tree.Node{
|
||||||
Name: mozilla.RootName,
|
Name: mozilla.RootName,
|
||||||
@ -128,49 +126,47 @@ func NewFirefoxConfig() *FirefoxConfig {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// default profile to use, can be selected as cli argument
|
// default profile to use, can be selected as cli argument
|
||||||
|
|
||||||
|
ProfilePrefs: modules.ProfilePrefs{
|
||||||
Profile: DefaultProfile,
|
Profile: DefaultProfile,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
setBookmarkDir(config)
|
setBookmarkDir(cfg)
|
||||||
|
|
||||||
return config
|
// Set WatchAllProfiles that was set by user in flags
|
||||||
|
// if userConf := config.GetModule(BrowserName); userConf != nil {
|
||||||
|
// watchAll, err := userConf.Get("WatchAllProfiles")
|
||||||
|
// if err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// } else {
|
||||||
|
// cfg.WatchAllProfiles = watchAll.(bool)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fc *FirefoxConfig) Set(opt string, v interface{}) error {
|
|
||||||
// log.Debugf("setting option %s = %v", opt, v)
|
|
||||||
s := structs.New(fc)
|
|
||||||
f, ok := s.FieldOk(opt)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("%s option not defined", opt)
|
|
||||||
}
|
|
||||||
|
|
||||||
return f.Set(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fc *FirefoxConfig) Get(opt string) (interface{}, error) {
|
|
||||||
s := structs.New(fc)
|
|
||||||
f, ok := s.FieldOk(opt)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("%s option not defined", opt)
|
|
||||||
}
|
|
||||||
|
|
||||||
return f.Value(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fc *FirefoxConfig) Dump() map[string]interface{} {
|
|
||||||
s := structs.New(fc)
|
|
||||||
return s.Map()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fc *FirefoxConfig) String() string {
|
|
||||||
s := structs.New(fc)
|
|
||||||
return fmt.Sprintf("%v", s.Map())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fc *FirefoxConfig) MapFrom(src interface{}) error {
|
|
||||||
return mapstructure.Decode(src, fc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
config.RegisterConfigurator(BrowserName, FFConfig)
|
config.RegisterConfigurator(BrowserName, config.AsConfigurator(FFConfig))
|
||||||
|
config.RegisterConfReadyHooks(func(*cli.Context) error{
|
||||||
|
// log.Debugf("%#v", config.GetAll().Dump())
|
||||||
|
|
||||||
|
|
||||||
|
//FIX: WatchAllProfiles option not set when instanciating new
|
||||||
|
//browser in daemon.go
|
||||||
|
// Recover Watch All Profiles value
|
||||||
|
if userConf := config.GetModule(BrowserName); userConf != nil {
|
||||||
|
watchAll, err := userConf.Get("WatchAllProfiles")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
} else {
|
||||||
|
FFConfig.WatchAllProfiles = watchAll.(bool)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -245,6 +245,7 @@ func (f *Firefox) scanModifiedBookmarks(since timestamp) ([]*MozBookmark, error)
|
|||||||
|
|
||||||
|
|
||||||
func NewFirefox() *Firefox {
|
func NewFirefox() *Firefox {
|
||||||
|
|
||||||
return &Firefox{
|
return &Firefox{
|
||||||
FirefoxConfig: FFConfig,
|
FirefoxConfig: FFConfig,
|
||||||
places: &database.DB{},
|
places: &database.DB{},
|
||||||
@ -270,7 +271,7 @@ func (f Firefox) fullId() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implements the profiles.ProfileManager interface
|
// Implements the profiles.ProfileManager interface
|
||||||
func (f *Firefox) GetProfiles(flavour string) ([]*profiles.Profile, error) {
|
func (*Firefox) GetProfiles(flavour string) ([]*profiles.Profile, error) {
|
||||||
return FirefoxProfileManager.GetProfiles(flavour)
|
return FirefoxProfileManager.GetProfiles(flavour)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,18 +294,23 @@ func (f *Firefox) UseProfile(p profiles.Profile) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Firefox) cloneConfig() {
|
|
||||||
f.FirefoxConfig = NewFirefoxConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO!: Duplicate logic with initFirefoxConfig (config.go)
|
|
||||||
func (f *Firefox) Init(ctx *modules.Context, p *profiles.Profile) error {
|
func (f *Firefox) Init(ctx *modules.Context, p *profiles.Profile) error {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
|
// setup profile from config
|
||||||
|
profile, err := FirefoxProfileManager.GetProfileByName(BrowserName, f.Profile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
bookmarkDir, err := profile.AbsolutePath()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f.BkDir = bookmarkDir
|
||||||
return f.init(ctx)
|
return f.init(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// for new profile use a new config
|
// use a new config for this profile
|
||||||
f.cloneConfig()
|
f.FirefoxConfig = NewFirefoxConfig()
|
||||||
f.Profile = p.Name
|
f.Profile = p.Name
|
||||||
|
|
||||||
|
|
||||||
@ -322,11 +328,8 @@ func (f *Firefox) Init(ctx *modules.Context, p *profiles.Profile) error {
|
|||||||
func (f *Firefox) init(ctx *modules.Context) error {
|
func (f *Firefox) init(ctx *modules.Context) error {
|
||||||
log.Infof("initializing <%s>", f.fullId())
|
log.Infof("initializing <%s>", f.fullId())
|
||||||
|
|
||||||
watchedPath, err := f.BookmarkDir()
|
watchedPath := f.BkDir
|
||||||
log.Debugf("Watching path: %s", watchedPath)
|
log.Debugf("Watching path: %s", watchedPath)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup watcher
|
// Setup watcher
|
||||||
w := &watch.Watch{
|
w := &watch.Watch{
|
||||||
|
@ -151,6 +151,7 @@ func startDaemon(c *cli.Context) error {
|
|||||||
log.Criticalf("TODO: module <%s> is not a BrowserModule", mod.ID)
|
log.Criticalf("TODO: module <%s> is not a BrowserModule", mod.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//BUG: WatchAllProfiles `module` flag option not working here
|
||||||
// if the module is a profile manager and is watching all profiles
|
// if the module is a profile manager and is watching all profiles
|
||||||
// call runModule for each profile
|
// call runModule for each profile
|
||||||
bpm, ok := browser.(profiles.ProfileManager)
|
bpm, ok := browser.(profiles.ProfileManager)
|
||||||
|
@ -38,7 +38,7 @@ import (
|
|||||||
_ "git.blob42.xyz/gosuki/gosuki/browsers/firefox"
|
_ "git.blob42.xyz/gosuki/gosuki/browsers/firefox"
|
||||||
|
|
||||||
// Load chrome browser module
|
// Load chrome browser module
|
||||||
// _ "git.blob42.xyz/gosuki/gosuki/browsers/chrome"
|
_ "git.blob42.xyz/gosuki/gosuki/browsers/chrome"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.GetLogger("")
|
var log = logging.GetLogger("")
|
||||||
|
@ -76,7 +76,7 @@ var listProfilesCmd = &cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("%-10s \t %s\n", p.Name, pPath)
|
fmt.Printf("%-10s[id:%s]\t %s\n", p.Name, p.Id, pPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
@ -24,11 +24,12 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"fmt"
|
||||||
|
|
||||||
"git.blob42.xyz/gosuki/gosuki/internal/logging"
|
"git.blob42.xyz/gosuki/gosuki/internal/logging"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/fatih/structs"
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -75,50 +76,52 @@ func (c Config) MapFrom(src interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AutoConfigurator struct{
|
||||||
|
c interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ac AutoConfigurator) Set(opt string, v interface{}) error {
|
||||||
|
// log.Debugf("setting option %s = %v", opt, v)
|
||||||
|
s := structs.New(ac.c)
|
||||||
|
f, ok := s.FieldOk(opt)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("%s option not defined", opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return f.Set(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ac AutoConfigurator) Get(opt string) (interface{}, error) {
|
||||||
|
s := structs.New(ac.c)
|
||||||
|
f, ok := s.FieldOk(opt)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("%s option not defined", opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return f.Value(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ac AutoConfigurator) Dump() map[string]interface{} {
|
||||||
|
s := structs.New(ac.c)
|
||||||
|
return s.Map()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ac AutoConfigurator) MapFrom(src interface{}) error {
|
||||||
|
log.Debugf("mapping from: %#v ", src)
|
||||||
|
log.Debugf("mapping to: %#v ", ac.c)
|
||||||
|
return mapstructure.Decode(src, ac.c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AsConfigurator(c interface{}) Configurator {
|
||||||
|
return AutoConfigurator{c}
|
||||||
|
}
|
||||||
|
|
||||||
// Register a global option ie. under [global] in toml file
|
// Register a global option ie. under [global] in toml file
|
||||||
func RegisterGlobalOption(key string, val interface{}) {
|
func RegisterGlobalOption(key string, val interface{}) {
|
||||||
log.Debugf("Registring global option %s = %v", key, val)
|
log.Debugf("Registring global option %s = %v", key, val)
|
||||||
configs[GlobalConfigName].Set(key, val)
|
configs[GlobalConfigName].Set(key, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup cli flag for global options
|
|
||||||
func SetupGlobalFlags() []cli.Flag {
|
|
||||||
log.Debugf("Setting up global flags")
|
|
||||||
flags := []cli.Flag{}
|
|
||||||
for k, v := range configs[GlobalConfigName].Dump() {
|
|
||||||
log.Debugf("Registering global flag %s = %v", k, v)
|
|
||||||
|
|
||||||
// Register the option as a cli flag
|
|
||||||
switch val := v.(type) {
|
|
||||||
case string:
|
|
||||||
flags = append(flags, &cli.StringFlag{
|
|
||||||
Category: "_",
|
|
||||||
Name: k,
|
|
||||||
Value: val,
|
|
||||||
})
|
|
||||||
|
|
||||||
case int:
|
|
||||||
flags = append(flags, &cli.IntFlag{
|
|
||||||
Category: "_",
|
|
||||||
Name: k,
|
|
||||||
Value: val,
|
|
||||||
})
|
|
||||||
|
|
||||||
case bool:
|
|
||||||
flags = append(flags, &cli.BoolFlag{
|
|
||||||
Category: "_",
|
|
||||||
Name: k,
|
|
||||||
Value: val,
|
|
||||||
})
|
|
||||||
|
|
||||||
default:
|
|
||||||
log.Fatalf("unsupported type for global option %s", k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return flags
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterModuleOpt(module string, opt string, val interface{}) error {
|
func RegisterModuleOpt(module string, opt string, val interface{}) error {
|
||||||
log.Debugf("Setting option for module <%s>: %s = %v", module, opt, val)
|
log.Debugf("Setting option for module <%s>: %s = %v", module, opt, val)
|
||||||
dest := configs[module]
|
dest := configs[module]
|
||||||
@ -126,48 +129,27 @@ func RegisterModuleOpt(module string, opt string, val interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get all configs as a map[string]interface{}
|
// Get all configs as a map[string]interface{}
|
||||||
// FIX: only print exported fields, parse tags for hidden fields
|
|
||||||
func GetAll() Config {
|
func GetAll() Config {
|
||||||
result := make(Config)
|
result := make(Config)
|
||||||
for k, c := range configs {
|
for k, c := range configs {
|
||||||
|
// if its an AutoConfigurator, use its c field
|
||||||
|
if ac, ok := c.(AutoConfigurator); ok {
|
||||||
|
result[k] = ac.c
|
||||||
|
} else {
|
||||||
result[k] = c
|
result[k] = c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetModule(module string) Configurator {
|
||||||
// Create a toml config file
|
if c, ok := configs[module]; ok {
|
||||||
func InitConfigFile() error {
|
return c
|
||||||
configFile, err := os.Create(ConfigFile)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allConf := GetAll()
|
|
||||||
|
|
||||||
tomlEncoder := toml.NewEncoder(configFile)
|
|
||||||
err = tomlEncoder.Encode(&allConf)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadFromTomlFile() error {
|
|
||||||
dest := make(Config)
|
|
||||||
_, err := toml.DecodeFile(ConfigFile, &dest)
|
|
||||||
|
|
||||||
for k, val := range dest {
|
|
||||||
// send the conf to its own module
|
|
||||||
if _, ok := configs[k]; ok {
|
|
||||||
configs[k].MapFrom(val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Hooks registered here will be executed after the config package has finished
|
// Hooks registered here will be executed after the config package has finished
|
||||||
// loading the conf
|
// loading the conf
|
||||||
|
62
internal/config/config_file.go
Normal file
62
internal/config/config_file.go
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// Copyright (c) 2023 Chakib Ben Ziane <contact@blob42.xyz> and [`gosuki` contributors](https://github.com/blob42/gosuki/graphs/contributors).
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
//
|
||||||
|
// This file is part of GoSuki.
|
||||||
|
//
|
||||||
|
// GoSuki is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// GoSuki is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with gosuki. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Create a toml config file
|
||||||
|
func InitConfigFile() error {
|
||||||
|
configFile, err := os.Create(ConfigFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
allConf := GetAll()
|
||||||
|
|
||||||
|
tomlEncoder := toml.NewEncoder(configFile)
|
||||||
|
err = tomlEncoder.Encode(&allConf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadFromTomlFile() error {
|
||||||
|
dest := make(Config)
|
||||||
|
_, err := toml.DecodeFile(ConfigFile, &dest)
|
||||||
|
|
||||||
|
for k, val := range dest {
|
||||||
|
|
||||||
|
// send the conf to its own module
|
||||||
|
if _, ok := configs[k]; ok {
|
||||||
|
configs[k].MapFrom(val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("loaded firefox config %#v", configs["firefox"])
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
61
internal/config/flags.go
Normal file
61
internal/config/flags.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// Copyright (c) 2023 Chakib Ben Ziane <contact@blob42.xyz> and [`gosuki` contributors](https://github.com/blob42/gosuki/graphs/contributors).
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
//
|
||||||
|
// This file is part of GoSuki.
|
||||||
|
//
|
||||||
|
// GoSuki is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// GoSuki is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with gosuki. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
package config
|
||||||
|
|
||||||
|
import "github.com/urfave/cli/v2"
|
||||||
|
|
||||||
|
// Setup cli flag for global options
|
||||||
|
func SetupGlobalFlags() []cli.Flag {
|
||||||
|
log.Debugf("Setting up global flags")
|
||||||
|
flags := []cli.Flag{}
|
||||||
|
for k, v := range configs[GlobalConfigName].Dump() {
|
||||||
|
log.Debugf("Registering global flag %s = %v", k, v)
|
||||||
|
|
||||||
|
// Register the option as a cli flag
|
||||||
|
switch val := v.(type) {
|
||||||
|
case string:
|
||||||
|
flags = append(flags, &cli.StringFlag{
|
||||||
|
Category: "_",
|
||||||
|
Name: k,
|
||||||
|
Value: val,
|
||||||
|
})
|
||||||
|
|
||||||
|
case int:
|
||||||
|
flags = append(flags, &cli.IntFlag{
|
||||||
|
Category: "_",
|
||||||
|
Name: k,
|
||||||
|
Value: val,
|
||||||
|
})
|
||||||
|
|
||||||
|
case bool:
|
||||||
|
flags = append(flags, &cli.BoolFlag{
|
||||||
|
Category: "_",
|
||||||
|
Name: k,
|
||||||
|
Value: val,
|
||||||
|
})
|
||||||
|
|
||||||
|
default:
|
||||||
|
log.Fatalf("unsupported type for global option %s", k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
@ -27,6 +27,7 @@ var BadProfile = &profiles.INIProfileLoader{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetProfiles(t *testing.T) {
|
func TestGetProfiles(t *testing.T) {
|
||||||
|
// fake browser flavour
|
||||||
MozBrowsers["test"] = profiles.BrowserFlavour{"test", "testdata"}
|
MozBrowsers["test"] = profiles.BrowserFlavour{"test", "testdata"}
|
||||||
t.Run("OK", func(t *testing.T) {
|
t.Run("OK", func(t *testing.T) {
|
||||||
pm := &MozProfileManager{
|
pm := &MozProfileManager{
|
||||||
|
@ -67,7 +67,8 @@ type Browser interface {
|
|||||||
type ProfilePrefs struct {
|
type ProfilePrefs struct {
|
||||||
|
|
||||||
// Whether to watch all the profiles for multi-profile modules
|
// Whether to watch all the profiles for multi-profile modules
|
||||||
WatchAllProfiles bool `toml:"watch_all_profiles"`
|
WatchAllProfiles bool `toml:"watch_all_profiles" mapstructure:"watch_all_profiles"`
|
||||||
|
Profile string `toml:"profile" mapstructure:"profile"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BrowserConfig is the main browser configuration shared by all browser modules.
|
// BrowserConfig is the main browser configuration shared by all browser modules.
|
||||||
@ -81,9 +82,6 @@ type BrowserConfig struct {
|
|||||||
// Name of bookmarks file
|
// Name of bookmarks file
|
||||||
BkFile string
|
BkFile string
|
||||||
|
|
||||||
|
|
||||||
ProfilePrefs
|
|
||||||
|
|
||||||
// In memory sqlite db (named `memcache`).
|
// In memory sqlite db (named `memcache`).
|
||||||
// Used to keep a browser's state of bookmarks across jobs.
|
// Used to keep a browser's state of bookmarks across jobs.
|
||||||
BufferDB *database.DB
|
BufferDB *database.DB
|
||||||
@ -108,29 +106,11 @@ type BrowserConfig struct {
|
|||||||
hooks map[string]hooks.Hook
|
hooks map[string]hooks.Hook
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (b *BrowserConfig) GetWatcher() *watch.WatchDescriptor {
|
func (b *BrowserConfig) GetWatcher() *watch.WatchDescriptor {
|
||||||
return b.watcher
|
return b.watcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b BrowserConfig) BookmarkDir() (string, error) {
|
|
||||||
var err error
|
|
||||||
bDir, err := utils.ExpandPath(b.BkDir)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
exists, err := utils.CheckDirExists(bDir)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !exists {
|
|
||||||
return "", fmt.Errorf("not a bookmark dir: %s ", bDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
return bDir, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CallHooks calls all registered hooks for this browser for the given
|
// CallHooks calls all registered hooks for this browser for the given
|
||||||
// *tree.Node. The hooks are called in the order they were registered. This is
|
// *tree.Node. 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
|
// usually done within the parsing logic of a browser module, typically in the
|
||||||
|
@ -23,6 +23,12 @@ package profiles
|
|||||||
|
|
||||||
import "path/filepath"
|
import "path/filepath"
|
||||||
|
|
||||||
|
// PathResolver allows custom path resolution for profiles
|
||||||
|
type PathResolver interface {
|
||||||
|
GetPath() string
|
||||||
|
SetBaseDir(string)
|
||||||
|
}
|
||||||
|
|
||||||
type INIProfileLoader struct {
|
type INIProfileLoader struct {
|
||||||
// The absolute path to the directory where profiles.ini is located
|
// The absolute path to the directory where profiles.ini is located
|
||||||
BasePath string
|
BasePath string
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
package profiles
|
package profiles
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
"git.blob42.xyz/gosuki/gosuki/internal/logging"
|
"git.blob42.xyz/gosuki/gosuki/internal/logging"
|
||||||
"git.blob42.xyz/gosuki/gosuki/internal/utils"
|
"git.blob42.xyz/gosuki/gosuki/internal/utils"
|
||||||
)
|
)
|
||||||
@ -36,15 +37,6 @@ type ProfileManager interface {
|
|||||||
// Returns all profiles for a given flavour
|
// Returns all profiles for a given flavour
|
||||||
GetProfiles(flavour string) ([]*Profile, error)
|
GetProfiles(flavour string) ([]*Profile, error)
|
||||||
|
|
||||||
//TODO!: remove
|
|
||||||
// Returns the default profile if no profile is selected
|
|
||||||
// GetDefaultProfile() (*Profile, error)
|
|
||||||
|
|
||||||
//TODO!: remove
|
|
||||||
//TODO!: fix input to method, should take string ?
|
|
||||||
// Return that absolute path to a profile and follow symlinks
|
|
||||||
// GetProfilePath(Profile) (string)
|
|
||||||
|
|
||||||
// If should watch all profiles
|
// If should watch all profiles
|
||||||
WatchAllProfiles() bool
|
WatchAllProfiles() bool
|
||||||
|
|
||||||
@ -61,6 +53,7 @@ type Profile struct {
|
|||||||
Id string
|
Id string
|
||||||
|
|
||||||
// Name of the profile
|
// Name of the profile
|
||||||
|
// This is usually the name of the directory where the profile is stored
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
// relative path to profile from base dir
|
// relative path to profile from base dir
|
||||||
@ -74,12 +67,6 @@ func (f Profile) AbsolutePath() (string, error) {
|
|||||||
return utils.ExpandPath(f.BaseDir, f.Path)
|
return utils.ExpandPath(f.BaseDir, f.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathResolver allows custom path resolution for profiles
|
|
||||||
// See the INIProfileLoader for an example
|
|
||||||
type PathResolver interface {
|
|
||||||
GetPath() string
|
|
||||||
SetBaseDir(string)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The BrowserFlavour struct stores the name of the browser and the base
|
// The BrowserFlavour struct stores the name of the browser and the base
|
||||||
// directory where the profiles are stored.
|
// directory where the profiles are stored.
|
||||||
|
Loading…
Reference in New Issue
Block a user