feat(shortcut): add custom shortcut CRUD persistence#98
Conversation
There was a problem hiding this comment.
Sorry @yixinshark, your pull request is larger than the review limit of 150000 diff characters
deepin pr auto review★ 总体评分:40分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 在 keybindingmanager.cpp 中增加白名单校验逻辑
#include <QFileInfo>
static const QStringList &allowedCommandPrefixes()
{
static const QStringList prefixes = {
QStringLiteral("/usr/bin/"),
QStringLiteral("/usr/local/bin/"),
QStringLiteral("/usr/sbin/")
};
return prefixes;
}
static bool isValidCustomShortcutCommand(const QString &command)
{
if (command.isEmpty()
|| command.size() > MaxCustomShortcutCommandLength
|| containsControlCharacter(command)) {
return false;
}
// 防止通过 shell 元字符进行命令注入
if (command.contains(QLatin1Char('|')) || command.contains(QLatin1Char('&'))
|| command.contains(QLatin1Char(';')) || command.contains(QLatin1Char('>'))
|| command.contains(QLatin1Char('<')) || command.contains(QLatin1Char('$'))
|| command.contains(QLatin1Char('`')) || command.contains(QLatin1Char('('))) {
qWarning() << "Invalid command: contains shell metacharacters";
return false;
}
// 提取第一段作为可执行文件路径进行白名单校验
const QString executablePath = command.split(QLatin1Char(' ')).first();
const QFileInfo fileInfo(executablePath);
if (!fileInfo.isAbsolute()) {
qWarning() << "Invalid command: must use absolute path";
return false;
}
bool allowed = false;
for (const QString &prefix : allowedCommandPrefixes()) {
if (executablePath.startsWith(prefix)) {
allowed = true;
break;
}
}
if (!allowed) {
qWarning() << "Invalid command: executable not in allowed paths" << executablePath;
}
return allowed;
} |
Add runtime custom shortcut CRUD (AddCustomShortcut/ModifyCustomShortcut/DeleteCustomShortcut) to KeybindingManager with input validation, conflict handling and commit-failure rollback. Add GetShortcutCommand so the control center can fetch a custom shortcut command separately. Persist runtime custom shortcuts through user-level DConfig plus a custom shortcut subpath registry. Keep Add on full save/create semantics, use updateCustomShortcut for Modify so existing entries update only changed fields, and roll back persisted state when registration or conflict persistence fails. Introduce display-only shortcut configs so modifiable shortcuts with no hotkey remain visible as "None" after their binding is taken. Keep these entries in the runtime map and expose them through ListAllShortcuts. Remove the unused checkConflictForConfig helper after conflict checks stayed on the actual LookupConflictShortcut/registerShortcut paths. 新增自定义快捷键运行时增删改(AddCustomShortcut/ModifyCustomShortcut/DeleteCustomShortcut),包含输入校验、冲突处理和提交失败回滚;新增 GetShortcutCommand,供控制中心单独获取自定义快捷键命令。 通过用户级 DConfig 和自定义快捷键 subpath 注册表持久化运行时自定义快捷键。Add 继续使用完整创建/保存语义,Modify 改用 updateCustomShortcut,仅更新已有条目的变化字段,并在注册或冲突持久化失败时回滚持久化状态。 引入 display-only 快捷键配置,使可修改但无热键的快捷键在绑定被其他快捷键占用后仍能以“无”显示。此类条目保留在运行时映射中,并通过 ListAllShortcuts 暴露。 删除未使用的 checkConflictForConfig 辅助函数,因为真实冲突检测仍走 LookupConflictShortcut/registerShortcut 路径。 Log: feat(shortcut): add custom shortcut CRUD and display-only support Change-Id: Ie59dd3cb4e2575eea15974b9454eefc0ff484bfa
d713203 to
2de4961
Compare
#96 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, yixinshark 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 |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Summary
Test
Related: #96