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

@@ -142,8 +142,6 @@ var (
clipConfigNoClearStartup bool
clipConfigDisabled bool
clipConfigEnabled bool
clipConfigDisableHistory bool
clipConfigEnableHistory bool
)
func init() {
@@ -167,10 +165,8 @@ func init() {
clipConfigSetCmd.Flags().IntVar(&clipConfigAutoClearDays, "auto-clear-days", -1, "Auto-clear entries older than N days (0 to disable)")
clipConfigSetCmd.Flags().BoolVar(&clipConfigClearAtStartup, "clear-at-startup", false, "Clear history on startup")
clipConfigSetCmd.Flags().BoolVar(&clipConfigNoClearStartup, "no-clear-at-startup", false, "Don't clear history on startup")
clipConfigSetCmd.Flags().BoolVar(&clipConfigDisabled, "disable", false, "Disable clipboard manager entirely")
clipConfigSetCmd.Flags().BoolVar(&clipConfigEnabled, "enable", false, "Enable clipboard manager")
clipConfigSetCmd.Flags().BoolVar(&clipConfigDisableHistory, "disable-history", false, "Disable clipboard history persistence")
clipConfigSetCmd.Flags().BoolVar(&clipConfigEnableHistory, "enable-history", false, "Enable clipboard history persistence")
clipConfigSetCmd.Flags().BoolVar(&clipConfigDisabled, "disable", false, "Disable clipboard tracking")
clipConfigSetCmd.Flags().BoolVar(&clipConfigEnabled, "enable", false, "Enable clipboard tracking")
clipWatchCmd.Flags().BoolVarP(&clipWatchStore, "store", "s", false, "Store clipboard changes to history (no server required)")
@@ -587,12 +583,6 @@ func runClipConfigSet(cmd *cobra.Command, args []string) {
if clipConfigEnabled {
params["disabled"] = false
}
if clipConfigDisableHistory {
params["disableHistory"] = true
}
if clipConfigEnableHistory {
params["disableHistory"] = false
}
if len(params) == 0 {
fmt.Println("No config options specified")

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,16 +57,17 @@ func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error)
dbPath: dbPath,
}
if !config.Disabled {
if err := m.setupRegistry(); err != nil {
return nil, err
}
}
m.notifierWg.Add(1)
go m.notifier()
go m.watchConfig()
if !config.DisableHistory {
db, err := openDB(dbPath)
if err != nil {
return nil, fmt.Errorf("failed to open db: %w", err)
@@ -81,6 +78,7 @@ func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error)
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"`
}
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())

View File

@@ -26,7 +26,7 @@ DankModal {
property Component clipboardContent
property int activeImageLoads: 0
readonly property int maxConcurrentLoads: 3
readonly property bool clipboardAvailable: DMSService.isConnected && DMSService.capabilities.includes("clipboard")
readonly property bool clipboardAvailable: DMSService.isConnected && (DMSService.capabilities.length === 0 || DMSService.capabilities.includes("clipboard"))
property bool wtypeAvailable: false
Process {

View File

@@ -324,24 +324,14 @@ Item {
expanded: false
visible: configLoaded
SettingsToggleRow {
tab: "clipboard"
tags: ["clipboard", "disable", "manager"]
settingKey: "disabled"
text: I18n.tr("Disable Clipboard Manager")
description: I18n.tr("Disable clipboard manager entirely (requires restart)")
checked: root.config.disabled ?? false
onToggled: checked => root.saveConfig("disabled", checked)
}
SettingsToggleRow {
tab: "clipboard"
tags: ["clipboard", "disable", "history"]
settingKey: "disableHistory"
settingKey: "disabled"
text: I18n.tr("Disable History Persistence")
description: I18n.tr("Clipboard works but nothing saved to disk")
checked: root.config.disableHistory ?? false
onToggled: checked => root.saveConfig("disableHistory", checked)
checked: root.config.disabled ?? false
onToggled: checked => root.saveConfig("disabled", checked)
}
}
}