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:
@@ -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")
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user