feat: app launcher
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Hyprland
|
||||
import Quickshell.Io
|
||||
|
||||
QtObject {
|
||||
id: manager
|
||||
|
||||
property bool shellOpen: false
|
||||
property bool quickSettingsOpen: false
|
||||
property bool appLauncherOpen: false
|
||||
property var appUsageCounts: ({})
|
||||
property string appUsagePath: {
|
||||
var homeDir = Quickshell.env("HOME");
|
||||
return homeDir ? homeDir + "/.local/share/deltarunequickshell/apps.json" : "";
|
||||
}
|
||||
property bool appUsageLoaded: false
|
||||
property var windowRequests: ({})
|
||||
property var quickSettingsPayload: ({})
|
||||
property var globals: ({})
|
||||
@@ -15,6 +24,8 @@ QtObject {
|
||||
signal shellClosed
|
||||
signal quickSettingsOpened
|
||||
signal quickSettingsClosed
|
||||
signal appLauncherOpened
|
||||
signal appLauncherClosed
|
||||
signal windowRequested(string name, var payload)
|
||||
|
||||
function openShell() {
|
||||
@@ -33,6 +44,9 @@ QtObject {
|
||||
if (quickSettingsOpen) {
|
||||
closeQuickSettings();
|
||||
}
|
||||
if (appLauncherOpen) {
|
||||
closeAppLauncher();
|
||||
}
|
||||
shellOpen = false;
|
||||
shellClosed();
|
||||
}
|
||||
@@ -55,6 +69,9 @@ QtObject {
|
||||
var normalizedPayload = payload || ({});
|
||||
quickSettingsPayload = normalizedPayload;
|
||||
console.log("ShellStateManager: openQuickSettings", normalizedPayload);
|
||||
if (appLauncherOpen) {
|
||||
closeAppLauncher();
|
||||
}
|
||||
if (!quickSettingsOpen) {
|
||||
quickSettingsOpen = true;
|
||||
quickSettingsOpened();
|
||||
@@ -74,6 +91,72 @@ QtObject {
|
||||
quickSettingsOpen ? closeQuickSettings() : openQuickSettings(payload);
|
||||
}
|
||||
|
||||
function openAppLauncher(payload) {
|
||||
var normalizedPayload = payload || ({});
|
||||
console.log("ShellStateManager: openAppLauncher", normalizedPayload);
|
||||
if (quickSettingsOpen) {
|
||||
closeQuickSettings();
|
||||
}
|
||||
if (!appLauncherOpen) {
|
||||
appLauncherOpen = true;
|
||||
appLauncherOpened();
|
||||
}
|
||||
requestWindow("appLauncher", normalizedPayload);
|
||||
}
|
||||
|
||||
function closeAppLauncher() {
|
||||
if (appLauncherOpen) {
|
||||
console.log("ShellStateManager: closeAppLauncher");
|
||||
appLauncherOpen = false;
|
||||
appLauncherClosed();
|
||||
}
|
||||
}
|
||||
|
||||
function toggleAppLauncher(payload) {
|
||||
appLauncherOpen ? closeAppLauncher() : openAppLauncher(payload);
|
||||
}
|
||||
|
||||
function bumpAppUsage(id) {
|
||||
if (!id)
|
||||
return;
|
||||
var updated = Object.assign({}, appUsageCounts);
|
||||
updated[id] = (updated[id] || 0) + 1;
|
||||
appUsageCounts = updated;
|
||||
}
|
||||
|
||||
function persistAppUsage() {
|
||||
if (!appUsageLoaded)
|
||||
return;
|
||||
if (!appUsageFile || !appUsageAdapter)
|
||||
return;
|
||||
appUsageAdapter.counts = appUsageCounts || ({});
|
||||
appUsageFile.writeAdapter();
|
||||
}
|
||||
|
||||
onAppUsageCountsChanged: persistAppUsage()
|
||||
|
||||
property FileView appUsageFile: FileView {
|
||||
id: appUsageFile
|
||||
path: manager.appUsagePath
|
||||
watchChanges: true
|
||||
onFileChanged: reload()
|
||||
onLoaded: {
|
||||
if (appUsageAdapter) {
|
||||
manager.appUsageCounts = appUsageAdapter.counts || ({});
|
||||
}
|
||||
manager.appUsageLoaded = true;
|
||||
}
|
||||
onLoadFailed: {
|
||||
manager.appUsageLoaded = true;
|
||||
manager.persistAppUsage();
|
||||
}
|
||||
|
||||
JsonAdapter {
|
||||
id: appUsageAdapter
|
||||
property var counts: ({})
|
||||
}
|
||||
}
|
||||
|
||||
function setGlobal(key, value) {
|
||||
globals[key] = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user