Files
Alexandr Stelnykovych 989175aab4 feat(UI): implement "Open Data Directory" in the Tauri app
Related ticket: #1834

The Tauri integration never implemented the action: the install dir
lookup rejected with "not yet supported", the rejection was unhandled,
and the shell plugin would not open local paths from JS anyway. The app
also cannot know the data directory from its arguments, as --data is not
passed on Windows and points to the v1 location on Linux.

Add a read-only core/paths endpoint to the core API (bin, data and log
directories) and an open_dir command in the Tauri app that takes a
directory kind (bin, data, logs), queries the endpoint and opens the
directory natively: ShellExecuteW with the default verb on Windows,
which honors a third-party file manager registered for folders, and
the open crate elsewhere. No path is accepted from the webview, and
further "open directory" actions only need UI changes.
2026-10-01 13:06:55 +03:00

126 lines
2.5 KiB
Go

package core
import (
"errors"
"fmt"
"sync/atomic"
"github.com/safing/portmaster/base/config"
"github.com/safing/portmaster/base/database"
"github.com/safing/portmaster/base/log"
"github.com/safing/portmaster/base/metrics"
"github.com/safing/portmaster/base/utils/debug"
"github.com/safing/portmaster/service/mgr"
_ "github.com/safing/portmaster/service/netenv"
_ "github.com/safing/portmaster/service/netquery"
_ "github.com/safing/portmaster/service/status"
_ "github.com/safing/portmaster/service/sync"
_ "github.com/safing/portmaster/service/ui"
"github.com/safing/portmaster/service/updates"
)
var db = database.NewInterface(&database.Options{
Local: true,
Internal: true,
})
// Core is the core service module.
type Core struct {
m *mgr.Manager
instance instance
EventShutdown *mgr.EventMgr[struct{}]
EventRestart *mgr.EventMgr[struct{}]
}
// Manager returns the manager.
func (c *Core) Manager() *mgr.Manager {
return c.m
}
// Start starts the module.
func (c *Core) Start() error {
return start()
}
// Stop stops the module.
func (c *Core) Stop() error {
return nil
}
func prep() error {
// init config
if err := registerConfig(); err != nil {
return err
}
if err := registerUpdateConfig(); err != nil {
return err
}
if err := registerAPIEndpoints(); err != nil {
return err
}
if err := initModulesIntegration(); err != nil {
return err
}
return nil
}
func start() error {
if err := startPlatformSpecific(); err != nil {
return fmt.Errorf("failed to start plattform-specific components: %w", err)
}
// Setup update system.
initUpdateConfig()
initVersionExport()
// Enable persistent metrics.
if err := metrics.EnableMetricPersistence("core:metrics/storage"); err != nil {
log.Warningf("core: failed to enable persisted metrics: %s", err)
}
return nil
}
var (
module *Core
shimLoaded atomic.Bool
)
// New returns a new NetEnv module.
func New(instance instance) (*Core, error) {
if !shimLoaded.CompareAndSwap(false, true) {
return nil, errors.New("only one instance allowed")
}
m := mgr.New("Core")
module = &Core{
m: m,
instance: instance,
EventShutdown: mgr.NewEventMgr[struct{}]("shutdown", m),
EventRestart: mgr.NewEventMgr[struct{}]("restart", m),
}
if err := prep(); err != nil {
return nil, err
}
return module, nil
}
type instance interface {
Shutdown()
Restart()
AddWorkerInfoToDebugInfo(di *debug.Info)
Config() *config.Config
BinaryUpdates() *updates.Updater
IntelUpdates() *updates.Updater
BinDir() string
DataDir() string
LogDir() string
}