keep file manager running in background

This commit is contained in:
nakst 2021-09-20 19:12:42 +01:00
parent 5e62a5ab14
commit 9b03402df8
4 changed files with 31 additions and 8 deletions

View File

@ -3,8 +3,10 @@ name=File Manager
icon=icon_system_file_manager
permission_all_files=1
permission_view_file_types=1
permission_start_application=1
use_single_process=1
is_file_manager=1
background_service=1
[build]
source=apps/file_manager/main.cpp

View File

@ -495,8 +495,15 @@ void _start() {
if (message->type == ES_MSG_INSTANCE_CREATE) {
Instance *instance = EsInstanceCreate(message, INTERFACE_STRING(FileManagerTitle));
instances.Add(instance);
InstanceCreateUI(instance);
EsApplicationStartupRequest request = EsInstanceGetStartupRequest(instance);
if (request.flags & ES_APPLICATION_STARTUP_BACKGROUND_SERVICE) {
// Keep the instance alive so that we always receive PATH_MOVED messages and such.
} else {
instances.Add(instance);
InstanceCreateUI(instance);
}
} else if (message->type == ES_MSG_INSTANCE_DESTROY) {
// TODO Cleanup/cancel any unfinished non-blocking tasks before we get here!
Instance *instance = message->instanceDestroy.instance;

View File

@ -35,6 +35,7 @@
#define APPLICATION_PERMISSION_SHUTDOWN (1 << 4)
#define APPLICATION_PERMISSION_VIEW_FILE_TYPES (1 << 5)
#define APPLICATION_PERMISSION_ALL_DEVICES (1 << 6)
#define APPLICATION_PERMISSION_START_APPLICATION (1 << 7)
#define APPLICATION_ID_DESKTOP_BLANK_TAB (-0x70000000)
#define APPLICATION_ID_DESKTOP_SETTINGS (-0x70000001)
@ -2196,6 +2197,7 @@ void ConfigurationLoadApplications() {
READ_PERMISSION("permission_run_temporary_application", APPLICATION_PERMISSION_RUN_TEMPORARY_APPLICATION);
READ_PERMISSION("permission_shutdown", APPLICATION_PERMISSION_SHUTDOWN);
READ_PERMISSION("permission_view_file_types", APPLICATION_PERMISSION_VIEW_FILE_TYPES);
READ_PERMISSION("permission_start_application", APPLICATION_PERMISSION_START_APPLICATION);
desktop.installedApplications.Add(application);
@ -2204,6 +2206,12 @@ void ConfigurationLoadApplications() {
} else if (EsSystemConfigurationGroupReadInteger(group, EsLiteral("is_installer"))) {
desktop.installer = application;
}
if (EsSystemConfigurationGroupReadInteger(group, EsLiteral("background_service"))) {
_EsApplicationStartupInformation startupInformation = {};
startupInformation.flags = ES_APPLICATION_STARTUP_BACKGROUND_SERVICE;
ApplicationInstanceCreate(application->id, &startupInformation, nullptr, true /* hidden */);
}
}
EsMutexRelease(&api.systemConfigurationMutex);
@ -2481,11 +2489,16 @@ void DesktopSyscall(EsMessage *message, uint8_t *buffer, EsBuffer *pipe) {
ApplicationInstance *instance = ApplicationInstanceFindByWindowID(message->desktop.windowID);
if (buffer[0] == DESKTOP_MSG_START_APPLICATION) {
EsBuffer b = { .in = buffer + 1, .bytes = message->desktop.bytes - 1 };
EsApplicationStartupRequest request = {};
EsBufferReadInto(&b, &request, sizeof(EsApplicationStartupRequest));
request.filePath = (const char *) EsBufferRead(&b, request.filePathBytes);
if (!b.error) OpenDocumentWithApplication(&request);
InstalledApplication *application = ApplicationFindByPID(message->desktop.processID);
if (application && (application->permissions & APPLICATION_PERMISSION_START_APPLICATION)) {
// TODO Restricting what flags can be requested?
EsBuffer b = { .in = buffer + 1, .bytes = message->desktop.bytes - 1 };
EsApplicationStartupRequest request = {};
EsBufferReadInto(&b, &request, sizeof(EsApplicationStartupRequest));
request.filePath = (const char *) EsBufferRead(&b, request.filePathBytes);
if (!b.error) OpenDocumentWithApplication(&request);
}
} else if (buffer[0] == DESKTOP_MSG_CREATE_CLIPBOARD_FILE && pipe) {
EsHandle processHandle = EsProcessOpen(message->desktop.processID);

View File

@ -698,7 +698,8 @@ define ES_DRIVE_TYPE_USB_MASS_STORAGE (4)
define ES_ELEMENT_FOCUS_ENSURE_VISIBLE (1 << 0)
define ES_ELEMENT_FOCUS_FROM_KEYBOARD (1 << 1)
define ES_APPLICATION_STARTUP_MANUAL_PATH (1 << 0)
define ES_APPLICATION_STARTUP_MANUAL_PATH (1 << 0)
define ES_APPLICATION_STARTUP_BACKGROUND_SERVICE (1 << 1)
define ES_LIST_VIEW_INLINE_TEXTBOX_COPY_EXISTING_TEXT (1 << 0)
define ES_LIST_VIEW_INLINE_TEXTBOX_REJECT_EDIT_IF_FOCUS_LOST (1 << 1)