SessionMenu: no initial selected entry

This commit is contained in:
Ly-sec
2025-12-25 14:27:48 +01:00
parent 6de63c88ff
commit 72aa5b0fe2
+25 -12
View File
@@ -61,7 +61,7 @@ SmartPanel {
property int timeRemaining: 0
// Navigation properties
property int selectedIndex: 0
property int selectedIndex: -1
// Action metadata mapping
readonly property var actionMetadata: {
@@ -148,12 +148,12 @@ SmartPanel {
// Lifecycle handlers
onOpened: {
selectedIndex = 0;
selectedIndex = -1;
}
onClosed: {
cancelTimer();
selectedIndex = 0;
selectedIndex = -1;
}
// Timer management
@@ -258,25 +258,37 @@ SmartPanel {
// Navigation functions
function selectNextWrapped() {
if (powerOptions.length > 0) {
selectedIndex = (selectedIndex + 1) % powerOptions.length;
if (selectedIndex < 0) {
selectedIndex = 0;
} else {
selectedIndex = (selectedIndex + 1) % powerOptions.length;
}
}
}
function selectPreviousWrapped() {
if (powerOptions.length > 0) {
selectedIndex = (((selectedIndex - 1) % powerOptions.length) + powerOptions.length) % powerOptions.length;
if (selectedIndex < 0) {
selectedIndex = powerOptions.length - 1;
} else {
selectedIndex = (((selectedIndex - 1) % powerOptions.length) + powerOptions.length) % powerOptions.length;
}
}
}
function selectFirst() {
selectedIndex = 0;
if (powerOptions.length > 0) {
selectedIndex = 0;
} else {
selectedIndex = -1;
}
}
function selectLast() {
if (powerOptions.length > 0) {
selectedIndex = powerOptions.length - 1;
} else {
selectedIndex = 0;
selectedIndex = -1;
}
}
@@ -286,8 +298,8 @@ SmartPanel {
return {
columns,
rows,
currentRow: Math.floor(selectedIndex / columns),
currentCol: selectedIndex % columns,
currentRow: selectedIndex >= 0 ? Math.floor(selectedIndex / columns) : -1,
currentCol: selectedIndex >= 0 ? selectedIndex % columns : -1,
itemsInRow: row => Math.min(columns, powerOptions.length - row * columns)
};
}
@@ -298,8 +310,9 @@ SmartPanel {
return;
const grid = getGridInfo();
let newRow = grid.currentRow;
let newCol = grid.currentCol;
// If no selection, start at first item
let newRow = grid.currentRow >= 0 ? grid.currentRow : 0;
let newCol = grid.currentCol >= 0 ? grid.currentCol : 0;
switch (direction) {
case "left":
@@ -329,7 +342,7 @@ SmartPanel {
}
function activate() {
if (powerOptions.length > 0 && powerOptions[selectedIndex]) {
if (powerOptions.length > 0 && selectedIndex >= 0 && powerOptions[selectedIndex]) {
const option = powerOptions[selectedIndex];
startTimer(option.action);
}