feat: Implement application launcher with pinned apps functionality
- Added `AppItem` struct to represent application details. - Implemented `collect_lnk_one_level` function to gather .lnk files from specified directories. - Created `get_apps` command to retrieve applications from the Taskbar and Start Menu. - Developed `launch_app` command to open applications. - Introduced `get_app_icon` command to fetch application icons in base64 format. - Added functionality to manage pinned applications with `get_pinned_apps` and `set_pinned_apps` commands. - Implemented system tray with toggle window functionality. - Created UI components for displaying application icons and tiles. - Developed hooks for managing application state, drag-and-drop reordering, and search functionality. - Styled components for a cohesive user interface.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { createSignal, Accessor } from "solid-js";
|
||||
|
||||
export function useDragReorder(
|
||||
pinnedPaths: Accessor<string[]>,
|
||||
persistPins: (paths: string[]) => void,
|
||||
isSearchActive: Accessor<boolean>
|
||||
) {
|
||||
const [dragIndex, setDragIndex] = createSignal<number | null>(null);
|
||||
const [dragOverIndex, setDragOverIndex] = createSignal<number | null>(null);
|
||||
|
||||
const canDrag = () => !isSearchActive();
|
||||
|
||||
const handleDragStart = (e: DragEvent, index: number) => {
|
||||
if (!canDrag()) return;
|
||||
setDragIndex(index);
|
||||
if (e.dataTransfer) {
|
||||
e.dataTransfer.effectAllowed = "move";
|
||||
e.dataTransfer.setData("text/plain", String(index));
|
||||
}
|
||||
};
|
||||
|
||||
const handleDragOver = (e: DragEvent, index: number) => {
|
||||
if (!canDrag()) return;
|
||||
e.preventDefault();
|
||||
if (e.dataTransfer) {
|
||||
e.dataTransfer.dropEffect = "move";
|
||||
}
|
||||
setDragOverIndex(index);
|
||||
};
|
||||
|
||||
const handleDrop = (e: DragEvent, dropIndex: number) => {
|
||||
if (!canDrag()) return;
|
||||
e.preventDefault();
|
||||
|
||||
let from = dragIndex();
|
||||
if (from === null && e.dataTransfer) {
|
||||
const data = e.dataTransfer.getData("text/plain");
|
||||
if (data !== "") {
|
||||
const parsed = Number(data);
|
||||
if (!Number.isNaN(parsed)) from = parsed;
|
||||
}
|
||||
}
|
||||
|
||||
setDragIndex(null);
|
||||
setDragOverIndex(null);
|
||||
|
||||
if (from === null || from === dropIndex) return;
|
||||
|
||||
const list = [...pinnedPaths()];
|
||||
if (
|
||||
from < 0 ||
|
||||
from >= list.length ||
|
||||
dropIndex < 0 ||
|
||||
dropIndex >= list.length
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [moved] = list.splice(from, 1);
|
||||
list.splice(dropIndex, 0, moved);
|
||||
persistPins(list);
|
||||
};
|
||||
|
||||
const handleDragEnd = () => {
|
||||
setDragIndex(null);
|
||||
setDragOverIndex(null);
|
||||
};
|
||||
|
||||
return {
|
||||
dragIndex,
|
||||
dragOverIndex,
|
||||
canDrag,
|
||||
handleDragStart,
|
||||
handleDragOver,
|
||||
handleDrop,
|
||||
handleDragEnd,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user