-
Notifications
You must be signed in to change notification settings - Fork 51
feat: migrate from gsettings to dconfig for sound settings #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1. Replaced gio.Settings with dconfig (ConfigManager) for reading sound settings 2. Added dconfig manager creation function with proper error handling 3. Updated schema IDs and key names to match dconfig structure 4. Added logging support for better debugging 5. Maintained backward compatibility with default values when dconfig is unavailable feat: 从 gsettings 迁移到 dconfig 用于声音设置 1. 使用 dconfig (ConfigManager) 替代 gio.Settings 读取声音设置 2. 添加了 dconfig 管理器创建函数并包含错误处理 3. 更新了 schema ID 和键名以匹配 dconfig 结构 4. 添加了日志支持以便更好地调试 5. 在 dconfig 不可用时保持向后兼容性并提供默认值 pms: TASK-381277
Reviewer's GuideThis PR replaces gio.Settings-based sound settings retrieval with dconfig (ConfigManager), introducing a new factory function with error handling, updating schema IDs and keys, adding logging, and maintaining backward compatibility with default values. Sequence diagram for sound settings retrieval using dconfigsequenceDiagram
participant SP as soundplayer
participant Log as logger
participant DBus as dbus.SystemBus
participant CM as configManager
participant DCM as dconfig.Manager
SP->>DBus: Get system bus
DBus-->>SP: bus
SP->>CM: NewConfigManager(bus)
CM-->>SP: dsMgr
SP->>CM: AcquireManager(appID, id)
CM-->>SP: dsPath
SP->>CM: NewManager(bus, dsPath)
CM-->>SP: dconfigMgr
SP->>DCM: Value(0, key)
DCM-->>SP: value
alt error
SP->>Log: logger.Warning(err)
SP-->>SP: Use default value
end
Class diagram for migration from gio.Settings to dconfig (ConfigManager)classDiagram
class soundplayer {
+PlaySystemSound(event string, device string) error
+PlayThemeSound(theme string, event string, device string) error
+CanPlayEvent(event string) bool
+GetSoundTheme() string
+GetThemeSoundFile(theme string, event string) string
+makeDConfigManager(appID string, id string) (configManager.Manager, error)
-logger
}
class gio {
+NewSettings(schema string) Settings
}
class configManager {
+NewConfigManager(bus Bus) ConfigManager
+NewManager(bus Bus, path string) Manager
+Manager
}
class log {
+NewLogger(name string) Logger
+Logger
}
soundplayer ..> configManager : uses
soundplayer ..> log : uses
soundplayer ..> gio : replaced by dconfig
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review我来对这段代码进行审查,从语法逻辑、代码质量、性能和安全性几个方面提出改进建议: 语法逻辑方面
代码质量方面
性能方面
安全性方面
具体改进建议
// makeDConfigManager 创建并返回一个DConfig管理器实例
// 参数:
// - appID: 应用程序ID
// - id: 配置管理器ID
// 返回值:
// - configManager.Manager: 配置管理器实例
// - error: 错误信息,如果创建失败
func safeGetBoolValue(value dbus.Variant) (bool, error) {
b, ok := value.Value().(bool)
if !ok {
return false, errors.New("value is not a boolean")
}
return b, nil
}
var (
soundThemeCache string
soundThemeMutex sync.RWMutex
)
func GetSoundTheme() string {
soundThemeMutex.RLock()
if soundThemeCache != "" {
soundThemeMutex.RUnlock()
return soundThemeCache
}
soundThemeMutex.RUnlock()
// ... 原有逻辑获取soundTheme ...
soundThemeMutex.Lock()
soundThemeCache = theme
soundThemeMutex.Unlock()
return theme
}
const (
// DBus相关常量
dconfigDaemonAppId = "org.deepin.dde.daemon"
dconfigSoundEffectId = "org.deepin.dde.daemon.soundeffect"
dconfigAppearanceAppId = "org.deepin.dde.appearance"
dconfigAppearanceId = dconfigAppearanceAppId
// 配置键常量
keySoundTheme = "Sound_Theme"
keyEnabled = "enabled"
keyPlayer = "player"
// 默认值常量
defaultSoundTheme = "deepin"
)
var (
busConn *dbus.Conn
connMutex sync.Mutex
)
func getDBusConnection() (*dbus.Conn, error) {
connMutex.Lock()
defer connMutex.Unlock()
if busConn != nil {
return busConn, nil
}
var err error
busConn, err = dbus.SystemBus()
return busConn, err
}这些改进将提高代码的健壮性、性能和可维护性,同时减少潜在的安全风险。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy, robertkill The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
feat: 从 gsettings 迁移到 dconfig 用于声音设置
pms: TASK-381277
Summary by Sourcery
Migrate sound settings backend from GSettings to dconfig and improve error handling and debugging
New Features:
Enhancements: