Electron Desktop Application Task Management Method Based on IndexedDB Storage
By leveraging IndexedDB storage technology, a task management module is provided for Electron desktop applications, solving the problem of inadequate task management and achieving efficient processing of large-scale tasks while ensuring data security.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA TELECOM DIGITAL INTELLIGENCE TECH CO LTD
- Filing Date
- 2022-12-14
- Publication Date
- 2026-06-30
AI Technical Summary
Electron desktop applications lack task management functionality, and existing storage components suffer from issues such as poor handling of concurrent tasks, limited data storage capacity, slow queries, and limited APIs.
It adopts IndexedDB storage technology and provides a task management module. By listening to user tasks and using IndexedDB to store task information, it can realize the creation, deletion, modification and query of tasks, and perform queue management based on task status and parallelism, including the conversion of pending, running, paused, failed and completed queues.
It enables efficient management of large-scale data tasks, provides a complete task management solution, improves the efficiency and security of task processing, and ensures the security of data under the same-origin policy.
Smart Images

Figure CN116010002B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer task management technology, and in particular to a task management method for Electron desktop applications based on IndexedDB storage. Background Technology
[0002] Electron is a cross-platform desktop application built with HTML, CSS, and JavaScript. It achieves this by merging Chromium and Node.js into a single runtime environment and packaging it as an application for Mac, Windows, and Linux systems. Electron was developed in 2013 as a framework for building Atom. Both projects were open-sourced in the spring of 2014. Electron's core philosophy is to keep it small and allow for sustainable development. For example, Electron only uses Chromium's rendering library, not all of its components. This makes upgrading Chromium easier, but it also means that Electron lacks some browser-related features found in Google Chrome. New features added to Electron should primarily be native APIs. If possible, a feature should ideally be a Node.js module.
[0003] Both Electron and NW.js can be used to develop desktop applications using front-end knowledge. NW.js and Electron were initially developed by the same author. Later, for various reasons, they split into two products: one named NW.js (with technical support from Intel) and the other named Electron (with technical support from GitHub). NW.js and Electron can use almost all modules in Node.js. They can not only package HTML web pages into cross-platform software that can be installed on computers, but also access the operating system's native UI and APIs (controlling windows, adding menu items, applying tray menus, reading and writing files, and accessing the clipboard) through JavaScript.
[0004] Electron is currently widely used, including GitHub's Atom editor, Microsoft's VS Code editor, and even some internal software from Alibaba.
[0005] In existing technologies, Electron lacks a suitable task management module when creating desktop applications. Furthermore, the Electron-store storage component provided by Electron, which stores data in local hard drive files using Node.js's fs module and performs read operations, suffers from issues such as poor concurrency handling, limited data storage capacity, slow querying of large datasets, and a limited API. Summary of the Invention
[0006] In view of the aforementioned shortcomings of existing technologies, this invention proposes an Electron desktop application task management method based on IndexedDB storage. This method is used to view and manage desktop application tasks, solving the problem that Electron lacks task management capabilities, and can store over ten thousand tasks. Using IndexedDB storage makes adding, deleting, modifying, and querying tasks more convenient and faster. A complete task management solution for Electron desktop applications is provided.
[0007] This invention provides a method for managing Electron desktop applications based on IndexedDB storage, comprising:
[0008] The task management module listens for tasks issued by users and stores tasks with the queue type of pending queue in the task information into IndexedDB.
[0009] The task management trigger judgment method is as follows: if the number of tasks with the queue type of running queue in IndexedDB is less than a predetermined value, the tasks with the queue type of pending queue in IndexedDB are sorted according to the task change time, the first predetermined number of data are taken, the queue type of the predetermined number of tasks is changed to running queue, and they are put into the waiting task queue of the running queue.
[0010] When the waiting task queue changes, the method is triggered by first determining the number of parallel tasks. If the number of parallel tasks is greater than the number of currently running tasks, the waiting task queue will enter the running task queue in a first-in-first-out manner until they are equal.
[0011] When the running task queue changes, the method is triggered to determine if the running status of the task in the running task queue is an unexecuted task or a paused task, and to execute the background interface or Electron's nodejs service corresponding to the task type of the unexecuted task or the paused task.
[0012] If a task in the running task queue fails, the task queue type is changed to a failure queue; the queue type of the tasks in the failure queue is changed to a pending queue for retry.
[0013] Once a task in the running task queue is completed, the task queue type changes to a completion queue.
[0014] Preferably, the task is paused by changing the queue type to a pause queue in the pending queue or running queue.
[0015] Preferably, the task information includes task name, queue type, task type, number of task retries, latest task change time, task start time, task sequence number, and task running status.
[0016] Preferably, the task types include: uploading, downloading, deleting, and copying.
[0017] Preferably, the queue types include pending queues, running queues, paused queues, failed queues, and completed queues.
[0018] Preferably, the tasks in the pending queue and the running queue include single selection, multiple selection, deletion, and pause functions.
[0019] Preferably, the task running status includes unexecuted task, task in progress, and task paused.
[0020] Preferably, the running queue includes a waiting task queue and a running task queue.
[0021] The present invention also provides an electronic device, the electronic device comprising:
[0022] At least one processor; and,
[0023] A memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the above-described method.
[0024] The present invention also provides a non-transitory computer-readable storage medium that stores computer instructions for causing the computer to perform the above-described method.
[0025] The beneficial effects of this invention are:
[0026] It provides a complete solution for desktop application task management, which can handle large data volume tasks with ease compared to other storage solutions;
[0027] IndexedDB employs a same-origin policy, where each source is associated with a different collection of databases. Different sources are not allowed to access databases from other sources, thus ensuring data security. Attached Figure Description
[0028] Figure 1This is a flowchart of a preferred embodiment of the desktop application task management method of the present invention;
[0029] Figure 2 This is a flowchart of the pending queue task management in a preferred embodiment of the present invention;
[0030] Figure 3 This is a flowchart of the task management process in a preferred embodiment of the present invention;
[0031] Figure 4 This is a flowchart of the pause queue task management in a preferred embodiment of the present invention;
[0032] Figure 5 This is a flowchart illustrating the queue task management process in a preferred embodiment of the present invention;
[0033] Figure 6 This is a flowchart of the failure queue task management in a preferred embodiment of the present invention. Detailed Implementation
[0034] The following description, with reference to the accompanying drawings, illustrates several preferred embodiments of the present invention to make its technical content clearer and easier to understand. The present invention can be embodied in many different forms, and the scope of protection of the present invention is not limited to the embodiments mentioned herein.
[0035] First, the technical terms involved in the embodiments of the present invention will be explained.
[0036] EventBus, also known as the event bus, can be used in Vue as a communication bridge. It's like all components share the same event center, which can register to send or receive events, so components can notify other components in parallel. ElementUI: A desktop component library for designers and developers.
[0037] Vue is a library for building interactive web interfaces. It is a progressive framework for building data-driven web interfaces. The framework follows the CMD specification and provides the MVVM design pattern (Model->View->View-Model) and a composable component system. It has a simple and flexible API. The framework inherits React's virtual DOM technology and Angular's two-way data binding technology. It is a relatively new functional framework.
[0038] IndexedDB is a method for storing data on the browser side. It's called a "DB" because it enriches client-side query methods and, due to local storage, effectively reduces the impact of network traffic on page data. With IndexedDB, browsers can store more data, thus enriching the types of applications available on the browser. Unlike traditional relational databases, IndexedDB is a key-value database. The value can be a complex struct object, and the key can be certain property values of an object or other objects (including binary objects). You can use any property of an object as an index to speed up lookups. IndexedDB has built-in transactions; all database operations are bound to specific transactions, and these transactions are automatically committed. IndexedDB does not support manual transaction commits. Most of the IndexedDB API is asynchronous. When using asynchronous methods, the API does not immediately return the queried data but instead returns a callback. The essence of the asynchronous API is to send an operation request to the database. When the operation is completed, a DOM event is received. Through this event, we know whether the operation was successful and obtain the result. IndexedDB is a NoSQL database. Unlike relational databases, IndexedDB is object-oriented, storing JavaScript objects. Another crucial feature of IndexedDB is its same-origin policy: each origin is associated with a different collection of databases, and different origins are not allowed to access databases from other origins, thus ensuring IndexedDB's security.
[0039] One embodiment of the present invention provides a method for managing Electron desktop application tasks based on IndexedDB storage, comprising:
[0040] The task management module listens for tasks issued by users and stores tasks with the queue type of pending queue in the task information into IndexedDB.
[0041] The task management trigger judgment method is as follows: if the number of tasks with the queue type of running queue in IndexedDB is less than a predetermined value, the tasks with the queue type of pending queue in IndexedDB are sorted according to the task change time, the first predetermined number of data are taken, the queue type of the predetermined number of tasks is changed to running queue, and they are put into the waiting task queue of the running queue.
[0042] When the waiting task queue changes, the method is triggered by first determining the number of parallel tasks. If the number of parallel tasks is greater than the number of currently running tasks, the waiting task queue will enter the running task queue in a first-in-first-out manner until they are equal.
[0043] When the running task queue changes, the method is triggered to determine if the running status of the task in the running task queue is an unexecuted task or a paused task, and to execute the background interface or Electron's nodejs service corresponding to the task type of the unexecuted task or the paused task.
[0044] If a task in the running task queue fails, the task queue type is changed to a failure queue; the queue type of the tasks in the failure queue is changed to a pending queue for retry.
[0045] Once a task in the running task queue is completed, the task queue type changes to a completion queue.
[0046] This invention provides a complete solution for desktop application task management. Compared with other storage solutions such as localStorage and Electron-store, it handles large data volume tasks with ease. IndexedDB uses a same-origin policy, where each source is associated with a different set of databases. Different sources are not allowed to access databases from other sources, thus ensuring data security.
[0047] In this embodiment of the invention, after a user issues a task using EventBus, the task management system uses EventBus to listen for the task and stores it in IndexedDB as a pending queue. The task information includes the following main fields: queueType (task queue type), which in this embodiment is represented as follows: 1: pending queue, 9: running queue, 0: paused queue, 2: failed queue, 3: completed queue; type (task type), which in this embodiment includes "upload", "download", "delete", and "copy"; retry (number of retry attempts); changeTime (last change time of the task); start (task start time); id (auto-incrementing task sequence number); step (steps of task execution); name (task name); and other parameters required for task execution. Users can view pending queue tasks in the task management system by page and by type. The pending queue can be used for operations including but not limited to single selection, multiple selection, deletion, and pause.
[0048] Reference Figure 1 The pending queue specifically includes the following operations:
[0049] The `tasking` method receives tasks from EventBus and stores them in IndexedDB. The default task queue type is Pending Queue 1, and the task ID is auto-incremented to obtain a unique identifier.
[0050] The `pauseFn` method is triggered when the pause button is clicked on the pending queue 1 page. It modifies the `queueType` of the task to 0 based on the task ID, and the task enters the pause queue 0.
[0051] The `gotasking` method is triggered when the number of tasks in the pending queue 1 changes. It checks the number of tasks in the running queue 9 and checks if the number of tasks in the running queue with task queue type 9 in IndexedDB is less than or equal to a predetermined number. In this embodiment, 50 tasks are preferred. If the number is less than or equal to 50, the tasks in the pending queue with a `queueType` field value of 1 will be sorted according to the latest change time (`changeTime`). The first predetermined number of data will be taken. For example, the first 50 data will be taken, and their `queueType` field value will be changed to 9: running queue. These 50 data will then enter the waiting task queue in running queue 9 to wait for execution.
[0052] Reference Figure 2 The running queue includes a waiting task queue and a running task queue, and specifically includes the following operations:
[0053] Listen: Observe the changes in the evaluation result of an expression or function on a Vue instance.
[0054] Monitor the waiting task queue (waitingQueue): When the data in the waiting task queue changes, trigger the goinTheQueue method: First, determine the number of parallel tasks. If the number of parallel tasks is greater than the number of currently running tasks in the queue, the waiting task queue will enter the running task queue (inTheQueue) in a first-in-first-out manner until they are equal.
[0055] Listen to the running task queue:
[0056] When the data in the running task queue changes, the method `changinTheQueue` is triggered: it determines the running status step of all tasks in the running task queue. The running status includes 0: no task is being executed, 1: task is being executed, and 5: task is paused. If the running status of a task is 0 or 5, the `IssuedTask` method is triggered.
[0057] When the number of running task queues is less than or equal to 50, the gotasking method is triggered: the tasks in the pending queue will be changed to the 9th running queue based on the task change time descending order of the first 50 tasks, and these 50 tasks will be assigned to the waiting task queue.
[0058] When the running task queue is not empty, the showSearchSch method is triggered: periodically query the task progress, setInterval(js timer) periodically queries the completion progress of the running task queue, and when the running queue is empty, the timer in the showSearchSch method is cleared.
[0059] The `IssuedTask` method: Based on the task type, it accesses the backend API service, passing the task information as a parameter. If the API returns a success status, it changes the `queueType` field value of the task with that ID to 3, and the task enters the completion queue. If the API returns a failure status, it changes the `queueType` field value of the task with that ID to 2, increments the `retry` field value by 1, and the task enters the failure queue. For example, a file deletion task would call the file deletion backend service API. The backend service would receive the passed parameters, delete the corresponding file, and return a success status upon success. The task management system, upon receiving the successful request status, would then transfer the task to the completion queue.
[0060] The `pauseFn` method: When the pause button is clicked on the run queue page, this method is triggered. It modifies the `queueType` of the task to 0 based on the task ID, and the task enters the pause queue.
[0061] The deleteTask method: When the delete button is clicked on the page, this method is triggered and deletes the data stored in IndexedDB based on the selected task ID.
[0062] In this embodiment of the invention, the running queue is divided into two layers: one layer is the IndexedDB storage layer, which stores the running queue tasks, and the other layer is the running task queue and the waiting task queue displayed in the user list.
[0063] After the running queue receives 50 tasks from the pending queue, the tasks are moved to the waiting task queue. Changes in the waiting task queue trigger a method that first checks the number of parallel tasks. If the number of parallel tasks is greater than the number of currently running tasks, tasks from the waiting queue are moved to the running task queue in a first-in, first-out manner until they are equal. When the running task queue changes, a method is triggered to check the running status (step) of all tasks in the running task queue. For tasks with a running status of 0 or 5, the corresponding backend interface or Electron's Node.js service is executed. For example, for a file deletion task, the file deletion backend service interface is called. The backend service receives the passed parameters, deletes the corresponding file, and returns a success status. The task management system, upon receiving the successful request status, moves the task to the completion queue.
[0064] When the number of tasks in the run queue is less than or equal to 50, the following method is triggered: the tasks in the pending queue will be changed to the run queue 9 based on the task change time in descending order, and these 50 tasks will be assigned to the waiting task queue.
[0065] When the run queue is not empty, trigger the method to periodically check the task progress. setInterval(js timer) periodically checks the completion progress of the run task queue. When the run queue is empty, clear the timer.
[0066] The run queue includes single-selection, multi-selection deletion, and pause functions.
[0067] Reference Figure 3 The pause queue specifically includes the following operations.
[0068] The `playPauseFn` method: When the start button is clicked on the pause page, this method is triggered. It modifies the `queueType` of the task to 1 based on the task ID, and the task enters the pending queue.
[0069] The deleteTask method: When the delete button is clicked on the page, this method is triggered and deletes the data stored in IndexedDB based on the selected task ID.
[0070] Clicking the pause button in the pending or running queue will change the queueType of the selected task data to 0, thus placing it in the paused queue. Users can view pending queue tasks by page and by type in the task management pending queue.
[0071] The pause queue includes single selection, multiple selection, delete all, and start functions. Selecting a task and clicking the start button changes the task's queueType to 1, and it enters the pending queue.
[0072] Reference Figure 4 The completion queue specifically includes the following operations:
[0073] The deleteTask method: When the delete button is clicked on the page, this method is triggered and deletes the data stored in IndexedDB based on the selected task ID.
[0074] Once a task in the task queue is completed, the task data's `queueType` changes to 3, and it enters the completion queue. Users can view completed tasks in the task management completion queue by page and type. The completion queue includes single-selection, multi-selection, and delete-all functions.
[0075] Reference Figure 5 The failure queue specifically includes the following operations:
[0076] The `retryFn` method: When the retry button is clicked on the page, this method is triggered. Based on the selected task ID, the task's `retry` field is modified to 2 and `queueType` to 1, and the task is then placed in the pending queue.
[0077] The `changeloseQueue` method is triggered when the failure queue changes. It searches for tasks in the failure queue whose `retry` field is less than 3, modifies their `queueType` field to 1, and then moves the task to the pending queue.
[0078] The deleteTask method: When the delete button is clicked on the page, this method is triggered and deletes the data stored in IndexedDB based on the selected task ID.
[0079] When a task fails to run in the queue, the task data's `queueType` changes to 2, and it is moved to the failure queue. Users can view failed tasks in the task management failure queue by page and type. The failure queue includes single selection, multiple selection, delete all, and retry functions. Selecting a task and clicking the retry button changes the task data's `queueType` to 1, and it is moved to the pending queue.
[0080] This invention achieves a perfect integration of Electron, IndexedDB, VUE, and ElementUI. The component-based design is highly reusable, easy to use, and the entire task management process is driven by JavaScript.
[0081] The preferred embodiments of the present invention have been described in detail above. It should be understood that those skilled in the art can make numerous modifications and variations based on the concept of the present invention without creative effort. Therefore, all technical solutions that can be obtained by those skilled in the art based on the concept of the present invention through logical analysis, reasoning, or limited experimentation on the basis of existing technology should be within the scope of protection defined by the claims.
Claims
1. A task management method for Electron desktop applications based on IndexedDB storage, characterized in that, include: The task management module listens for tasks issued by users and stores tasks with the queue type of pending queue in the task information into IndexedDB. The task management trigger judgment method is as follows: if the number of tasks with the queue type of running queue in IndexedDB is less than a predetermined value, the tasks with the queue type of pending queue in IndexedDB are sorted according to the task change time, the first predetermined number of data are taken, the queue type of the predetermined number of tasks is changed to running queue, and they are put into the waiting task queue of the running queue. When the waiting task queue changes, the method is triggered by first determining the number of parallel tasks. If the number of parallel tasks is greater than the number of currently running tasks, the waiting task queue will enter the running task queue in a first-in-first-out manner until they are equal. When the running task queue changes, the method is triggered to determine if the running status of the task in the running task queue is an unexecuted task or a paused task, and to execute the background interface or Electron's nodejs service corresponding to the task type of the unexecuted task or the paused task. If a task in the running task queue fails, the task queue type is changed to a failure queue; the queue type of the tasks in the failure queue is changed to a pending queue for retry. Once a task in the running task queue is completed, the task queue type changes to a completion queue. The run queue is divided into two layers: the first layer is the IndexedDB storage layer, which stores the run queue tasks, and the second layer is the run task queue and waiting task queue displayed in the user list. When the running queue receives 50 tasks from the pending queue, the tasks enter the waiting task queue. When the waiting task queue changes, a method is triggered. First, the number of parallel tasks is checked. If the number of parallel tasks is greater than the number of currently running tasks, tasks from the waiting task queue will enter the running task queue in a first-in-first-out manner until they are equal. When the running task queue changes, a method is triggered to check the running status step of all tasks in the running task queue. If the running status of a task is 0 or 5, the background interface corresponding to the task type or the Electron Node.js service is executed. When the number of tasks in the run queue is less than or equal to 50, the following method is triggered: the tasks in the pending queue will be changed to the run queue in descending order of the task change time, and these 50 tasks will be assigned to the waiting task queue. The task is paused by changing the queue type to a pause queue in the pending queue or running queue.
2. The desktop application task management method as described in claim 1, characterized in that, The task information includes task name, queue type, task type, number of task retries, latest change time of the task, task start time, task sequence number, and task running status.
3. The desktop application task management method as described in claim 2, characterized in that, The task types include: uploading, downloading, deleting, and copying.
4. The desktop application task management method as described in claim 1, characterized in that, The queue types include pending queue, running queue, paused queue, failed queue, and completed queue.
5. The desktop application task management method as described in claim 1, characterized in that, The tasks in the pending queue and the running queue include single selection, multiple selection, deletion, and pause functions.
6. The desktop application task management method as described in claim 1, characterized in that, The task running status includes tasks that are not being executed, tasks that are being executed, and tasks that are paused.
7. The desktop application task management method as described in claim 1, characterized in that, The running queue includes a waiting task queue and a running task queue.
8. An electronic device, characterized in that, The electronic device includes: At least one processor; and, A memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1-7.
9. A non-transitory computer-readable storage medium, characterized in that, The non-transitory computer-readable storage medium stores computer instructions for causing the computer to perform the method described in any one of claims 1-7.