mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
launcher: settings provider
This commit is contained in:
@@ -437,6 +437,7 @@
|
||||
"search": "Search",
|
||||
"security": "Security",
|
||||
"select": "Select",
|
||||
"settings": "Settings",
|
||||
"shortcuts": "Shortcuts",
|
||||
"shutdown": "Shutdown",
|
||||
"signal": "Signal",
|
||||
|
||||
@@ -714,6 +714,14 @@ SmartPanel {
|
||||
}
|
||||
}
|
||||
|
||||
SettingsProvider {
|
||||
id: settingsProvider
|
||||
Component.onCompleted: {
|
||||
registerProvider(this);
|
||||
Logger.d("Launcher", "Registered: SettingsProvider");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
panelContent: Rectangle {
|
||||
id: ui
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import qs.Commons
|
||||
import qs.Services.UI
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
// Provider metadata
|
||||
property string name: I18n.tr("common.settings")
|
||||
property var launcher: null
|
||||
property bool handleSearch: true
|
||||
property string supportedLayouts: "list"
|
||||
|
||||
property var searchIndex: []
|
||||
|
||||
FileView {
|
||||
id: searchIndexFile
|
||||
path: Quickshell.shellDir + "/Assets/settings-search-index.json"
|
||||
watchChanges: false
|
||||
printErrors: false
|
||||
|
||||
onLoaded: {
|
||||
try {
|
||||
root.searchIndex = JSON.parse(text());
|
||||
} catch (e) {
|
||||
root.searchIndex = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
Logger.d("SettingsProvider", "Initialized");
|
||||
}
|
||||
|
||||
function getResults(query) {
|
||||
if (!query || searchIndex.length === 0)
|
||||
return [];
|
||||
|
||||
const trimmed = query.trim();
|
||||
if (!trimmed || trimmed.length < 2)
|
||||
return [];
|
||||
|
||||
// Build searchable items with resolved translations
|
||||
let items = [];
|
||||
for (let j = 0; j < searchIndex.length; j++) {
|
||||
const entry = searchIndex[j];
|
||||
items.push({
|
||||
"labelKey": entry.labelKey,
|
||||
"descriptionKey": entry.descriptionKey,
|
||||
"widget": entry.widget,
|
||||
"tab": entry.tab,
|
||||
"tabLabel": entry.tabLabel,
|
||||
"subTab": entry.subTab,
|
||||
"subTabLabel": entry.subTabLabel || null,
|
||||
"label": I18n.tr(entry.labelKey),
|
||||
"description": entry.descriptionKey ? I18n.tr(entry.descriptionKey) : "",
|
||||
"subTabName": entry.subTabLabel ? I18n.tr(entry.subTabLabel) : ""
|
||||
});
|
||||
}
|
||||
|
||||
const results = FuzzySort.go(trimmed, items, {
|
||||
"keys": ["label", "subTabName", "description"],
|
||||
"threshold": 0.35,
|
||||
"limit": 3,
|
||||
"scoreFn": function (r) {
|
||||
const labelScore = r[0].score;
|
||||
const subTabScore = r[1].score * 1.5;
|
||||
const descScore = r[2].score;
|
||||
return Math.max(labelScore, subTabScore, descScore);
|
||||
}
|
||||
});
|
||||
|
||||
let launcherItems = [];
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
const entry = results[i].obj;
|
||||
const tabName = I18n.tr(entry.tabLabel);
|
||||
const subTabName = entry.subTabName || "";
|
||||
const breadcrumb = subTabName ? (tabName + " › " + subTabName) : tabName;
|
||||
|
||||
launcherItems.push({
|
||||
"name": entry.label,
|
||||
"description": breadcrumb,
|
||||
"icon": "settings",
|
||||
"isTablerIcon": true,
|
||||
"isImage": false,
|
||||
"provider": root,
|
||||
"onActivate": createActivateHandler(entry)
|
||||
});
|
||||
}
|
||||
|
||||
return launcherItems;
|
||||
}
|
||||
|
||||
function createActivateHandler(entry) {
|
||||
return function () {
|
||||
if (launcher)
|
||||
launcher.close();
|
||||
|
||||
Qt.callLater(() => {
|
||||
var settingsPanel = PanelService.getPanel("settingsPanel", launcher.screen);
|
||||
if (settingsPanel) {
|
||||
settingsPanel.requestedEntry = entry;
|
||||
settingsPanel.open();
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,7 @@ SmartPanel {
|
||||
}
|
||||
|
||||
property int requestedTab: SettingsPanel.Tab.General
|
||||
property var requestedEntry: null
|
||||
|
||||
// Content state - these are synced with SettingsContent when panel opens
|
||||
property int currentTabIndex: 0
|
||||
@@ -148,8 +149,16 @@ SmartPanel {
|
||||
// When the panel opens, initialize content
|
||||
onOpened: {
|
||||
if (_settingsContent) {
|
||||
_settingsContent.requestedTab = requestedTab;
|
||||
_settingsContent.initialize();
|
||||
if (requestedEntry) {
|
||||
_settingsContent.requestedTab = requestedEntry.tab;
|
||||
_settingsContent.initialize();
|
||||
const entry = requestedEntry;
|
||||
requestedEntry = null;
|
||||
Qt.callLater(() => _settingsContent.navigateToResult(entry));
|
||||
} else {
|
||||
_settingsContent.requestedTab = requestedTab;
|
||||
_settingsContent.initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user