Недавние документы | Electron
https://www.electronjs.org/ru/docs/latest/tutorial/recent-documents • 75 KB fetched Open original page
Недавние документы | Electron
Перейти к основному содержанию
Electron Документация API Блог Инструменты
* Electron Forge
* Electron Fiddle
Сообщество
* Управление
* Примеры
* Ресурсы
Релизы Русский
* English
* Deutsch
* Español
* Français
* 日本語
* Português
* Русский
* 中文
Поиск
* Начать
* Процессы в Electron
* Рекомендации
* Примеры
* Темный режим
* Device Access
* In-App Purchases
*
* Горячие клавиши
* Deep Links
* Desktop Launcher Actions
*
* Menus
* Многопоточность
* Нативное перемещение файла
* История навигации
* Notification (Оповещения)
* Закадровый рендеринг
* Обнаружение Online/Offline событий
* Progress Bars
* Недавние документы
*
*
* Representing Files in a BrowserWindow
*
* SpellChecker
* Web Embeds
* Taskbar Customization
*
* Window Customization
* Разработка
* Native Node Modules
* Распространение
* Тестирование и отладка
* Ссылки
* Вклад
*
* Примеры
* Недавние документы На этой странице
Недавние документы
Обзор
Windows и macOS предоставляют легкий доступ к списку последних документов открытых приложением через JumpList или dock меню, соответственно.
JumpList:
Dock меню приложения:
Пример
Managing recent documents
docs/fiddles/features/recent-documents ( 43.4.0 ) Open in Fiddle
* main.js
* index.html const { app , BrowserWindow } = require ( 'electron/main' )
const fs = require ( 'node:fs' )
const path = require ( 'node:path' )
function createWindow ( ) {
const win = new BrowserWindow ( {
width : 800 ,
height : 600
} )
win . loadFile ( 'index.html' )
}
const fileName = 'recently-used.md'
fs . writeFile ( fileName , 'Lorem Ipsum' , ( ) => {
app . addRecentDocument ( path . join ( __dirname , fileName ) )
} )
app . whenReady ( ) . then ( createWindow )
app . on ( 'window-all-closed' , ( ) => {
app . clearRecentDocuments ( )
if ( process . platform !== 'darwin' ) {
app . quit ( )
}
} )
app . on ( 'activate' , ( ) => {
if ( BrowserWindow . getAllWindows ( ) . length === 0 ) {
createWindow ( )
}
} )
<! DOCTYPE html >
< html >
< head >
< meta charset = " UTF-8 " >
< title > Recent Documents </ title >
< meta http-equiv = " Content-Security-Policy " content = " script-src 'self' 'unsafe-inline'; " />
</ head >
< body >
< h1 > Recent Documents </ h1 >
< p >
Right click on the app icon to see recent documents.
You should see `recently-used.md` added to the list of recent files
</ p >
</ body >
</ html >
Adding a recent document
To add a file to recent documents, use the app.addRecentDocument API.
After launching the Electron application, right click the application icon. In this guide, the item is a Markdown file located in the root of the project. You should see recently-used.md added to the list of recent files:
Clearing the list of recent documents
To clear the list of recent documents, use the app.clearRecentDocuments API. In this guide, the list of documents is cleared once all windows have been closed.
Accessing the list of recent documents
To access the list of recent documents, use the app.getRecentDocuments API.
Additional information
Windows примечания
To use this feature on Windows, your application has to be registered as a handler of the file type of the document, otherwise the file won't appear in JumpList even after you have added it. You can find everything on registering your application in Application Registration .
Когда пользователь щелкает файл из JumpList, новый экземпляр приложения будет запущен с добавленного пути файла, как аргумент командной строки.
macOS примечания
Add the Recent Documents list to the application menu
You can add menu items to access and clear recent documents by adding the following code snippet to your menu template:
{
"submenu" : [
{
"label" : "Open Recent" ,
"role" : "recentdocuments" ,
"submenu" : [
{
"label" : "Clear Recent" ,
"role" : "clearrecentdocuments"
}
]
}
]
}
Make sure the application menu is added after the 'ready' event and not before, or the menu item will be disabled:
const { app , Menu } = require ( 'electron' )
const template = [
// Menu template here
]
const menu = Menu . buildFromTemplate ( template )
app . whenReady ( ) . then ( ( ) => {
Menu . setApplicationMenu ( menu )
} )
When a file is requested from the recent documents menu, the open-file event of app module will be emitted for it.
Редактировать эту страницу
Назад
Progress Bars
Далее
Representing Files in a BrowserWindow
* Обзор
* Пример
* Managing recent documents
* Adding a recent document
* Clearing the list of recent documents
* Accessing the list of recent documents
* Additional information
* Windows примечания
* macOS примечания
* Add the Recent Documents list to the application menu
Документация
* Начало работы
* Справка по API
Контрольные списки
* Характеристика
* Безопасность
Инструменты
* Electron Forge
* Electron Fiddle
Сообщество
* Управление
* Ресурсы
* Discord
* Bluesky
* X
* Mastodon
* Stack Overflow
Подробнее
* GitHub
* Open Collective
* Панель управления инфраструктурой
Авторское право OpenJS Foundation и участники проекта Electron. Все права защищены. OpenJS Foundation обладает зарегистрированными товарными знаками и использует их. Список товарных знаков OpenJS Foundation приведён в нашей Политике в отношении товарных знаков и в Списке товарных знаков . Товарные знаки™ и логотипы®, не указанные в списке товарных знаков OpenJS Foundation , являются товарными знаками™ или зарегистрированными® товарными знаками их владельцев. Их использование не подразумевает какой-либо принадлежности к ним или поддержки с их стороны. The OpenJS Foundation | Условия использования | Политика конфиденциальности | Устав | Кодекс поведения | Политика в отношении товарных знаков | Список товарных знаков | Политика использования файлов cookie
Hosting and infrastructure graciously provided by
Links found on this page
- Перейти к основному содержанию [direct]
- Electron [direct]
- Документация [direct]
- API [direct]
- Блог [direct]
- Electron Forge [direct]
- Electron Fiddle [direct]
- Управление [direct]
- Примеры [direct]
- Ресурсы [direct]
- Релизы [direct]
- English [direct]
- Deutsch [direct]
- Español [direct]
- Français [direct]
- 日本語 [direct]
- Português [direct]
- 中文 [direct]
- Процессы в Electron [direct]
- Рекомендации [direct]
- Примеры [direct]
- Темный режим [direct]
- Device Access [direct]
- In-App Purchases [direct]
- Горячие клавиши [direct]
- Deep Links [direct]
- Desktop Launcher Actions [direct]
- Menus [direct]
- Многопоточность [direct]
- Нативное перемещение файла [direct]
- История навигации [direct]
- Notification (Оповещения) [direct]
- Закадровый рендеринг [direct]
- Обнаружение Online/Offline событий [direct]
- Progress Bars [direct]
- Representing Files in a BrowserWindow [direct]
- SpellChecker [direct]
- Web Embeds [direct]
- Taskbar Customization [direct]
- Window Customization [direct]
- Разработка [direct]
- Native Node Modules [direct]
- Распространение [direct]
- Тестирование и отладка [direct]
- Ссылки [direct]
- Вклад [direct]
- docs/fiddles/features/recent-documents ( 43.4.0 ) [direct]
- Open in Fiddle [direct]
- Application Registration [direct]
- Редактировать эту страницу [direct]
- Безопасность [direct]
- Discord [direct]
- Bluesky [direct]
- X [direct]
- Mastodon [direct]
- Stack Overflow [direct]
- GitHub [direct]
- Open Collective [direct]
- Панель управления инфраструктурой [direct]
- OpenJS Foundation [direct]
- Политике в отношении товарных знаков [direct]
- Списке товарных знаков [direct]
- Условия использования [direct]
- Политика конфиденциальности [direct]
- Устав [direct]
- Кодекс поведения [direct]
- Политика использования файлов cookie [direct]
|
|