1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

clipboard: single disable + read-only history option

This commit is contained in:
bbedward
2025-12-31 09:14:35 -05:00
parent 621710bd86
commit 2dbadfe1b5
8 changed files with 29 additions and 70 deletions

View File

@@ -205,9 +205,6 @@ func handleSetConfig(conn net.Conn, req models.Request, m *Manager) {
if v, ok := req.Params["disabled"].(bool); ok {
cfg.Disabled = v
}
if v, ok := req.Params["disableHistory"].(bool); ok {
cfg.DisableHistory = v
}
if err := m.SetConfig(cfg); err != nil {
models.RespondError(conn, req.ID, err.Error())

View File

@@ -36,10 +36,6 @@ var sensitiveMimeTypes = []string{
}
func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error) {
if config.Disabled {
return nil, fmt.Errorf("clipboard disabled in config")
}
display := wlCtx.Display()
dbPath, err := getDBPath()
if err != nil {
@@ -61,8 +57,10 @@ func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error)
dbPath: dbPath,
}
if err := m.setupRegistry(); err != nil {
return nil, err
if !config.Disabled {
if err := m.setupRegistry(); err != nil {
return nil, err
}
}
m.notifierWg.Add(1)
@@ -70,17 +68,17 @@ func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error)
go m.watchConfig()
if !config.DisableHistory {
db, err := openDB(dbPath)
if err != nil {
return nil, fmt.Errorf("failed to open db: %w", err)
}
m.db = db
db, err := openDB(dbPath)
if err != nil {
return nil, fmt.Errorf("failed to open db: %w", err)
}
m.db = db
if err := m.migrateHashes(); err != nil {
log.Errorf("Failed to migrate hashes: %v", err)
}
if err := m.migrateHashes(); err != nil {
log.Errorf("Failed to migrate hashes: %v", err)
}
if !config.Disabled {
if config.ClearAtStartup {
if err := m.clearHistoryInternal(); err != nil {
log.Errorf("Failed to clear history at startup: %v", err)
@@ -97,7 +95,7 @@ func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error)
m.alive = true
m.updateState()
if m.dataControlMgr != nil && m.seat != nil {
if !config.Disabled && m.dataControlMgr != nil && m.seat != nil {
m.setupDataDeviceSync()
}
@@ -326,7 +324,7 @@ func (m *Manager) readAndStore(r *os.File, mimeType string) {
return
}
if !cfg.DisableHistory && m.db != nil {
if !cfg.Disabled && m.db != nil {
m.storeClipboardEntry(data, mimeType)
}
@@ -1211,23 +1209,13 @@ func (m *Manager) applyConfigChange(newCfg Config) {
m.config = newCfg
m.configMutex.Unlock()
if newCfg.DisableHistory && !oldCfg.DisableHistory && m.db != nil {
log.Info("Clipboard history disabled, closing database")
m.db.Close()
m.db = nil
switch {
case newCfg.Disabled && !oldCfg.Disabled:
log.Info("Clipboard tracking disabled")
case !newCfg.Disabled && oldCfg.Disabled:
log.Info("Clipboard tracking enabled")
}
if !newCfg.DisableHistory && oldCfg.DisableHistory && m.db == nil {
log.Info("Clipboard history enabled, opening database")
if db, err := openDB(m.dbPath); err == nil {
m.db = db
} else {
log.Errorf("Failed to reopen database: %v", err)
}
}
log.Infof("Clipboard config reloaded: disableHistory=%v", newCfg.DisableHistory)
m.updateState()
m.notifySubscribers()
}
@@ -1235,8 +1223,8 @@ func (m *Manager) applyConfigChange(newCfg Config) {
func (m *Manager) StoreData(data []byte, mimeType string) error {
cfg := m.getConfig()
if cfg.DisableHistory {
return fmt.Errorf("clipboard history disabled")
if cfg.Disabled {
return fmt.Errorf("clipboard tracking disabled")
}
if m.db == nil {

View File

@@ -457,7 +457,6 @@ func TestDefaultConfig(t *testing.T) {
assert.Equal(t, 0, cfg.AutoClearDays)
assert.False(t, cfg.ClearAtStartup)
assert.False(t, cfg.Disabled)
assert.False(t, cfg.DisableHistory)
}
func TestManager_PostDelegatesToWlContext(t *testing.T) {

View File

@@ -18,9 +18,7 @@ type Config struct {
MaxEntrySize int64 `json:"maxEntrySize"`
AutoClearDays int `json:"autoClearDays"`
ClearAtStartup bool `json:"clearAtStartup"`
Disabled bool `json:"disabled"`
DisableHistory bool `json:"disableHistory"`
Disabled bool `json:"disabled"`
}
func DefaultConfig() Config {

View File

@@ -207,9 +207,6 @@ func handleClipboardSetConfig(conn net.Conn, req models.Request) {
if v, ok := req.Params["disabled"].(bool); ok {
cfg.Disabled = v
}
if v, ok := req.Params["disableHistory"].(bool); ok {
cfg.DisableHistory = v
}
if err := clipboard.SaveConfig(cfg); err != nil {
models.RespondError(conn, req.ID, err.Error())