@@ -13,39 +13,62 @@ __Application dock menu:__
1313
1414![ macOS Dock Menu] [ dock-menu-image ]
1515
16- To add a file to recent documents, you need to use the
17- [ app.addRecentDocument] [ addrecentdocument ] API.
18-
1916## Example
2017
21- ### Add an item to recent documents
22-
23- Starting with a working application from the
24- [ Quick Start Guide] ( quick-start.md ) , add the following lines to the
25- ` main.js ` file:
18+ ### Managing recent documents
2619
2720``` javascript fiddle='docs/fiddles/features/recent-documents'
28- const { app } = require (' electron' )
21+ const { app , BrowserWindow } = require (' electron' )
22+ const fs = require (' fs' )
23+ const path = require (' path' )
24+
25+ function createWindow () {
26+ const win = new BrowserWindow ({
27+ width: 800 ,
28+ height: 600
29+ })
30+
31+ win .loadFile (' index.html' )
32+ }
33+
34+ const fileName = ' recently-used.md'
35+ fs .writeFile (fileName, ' Lorem Ipsum' , () => {
36+ app .addRecentDocument (path .join (__dirname , fileName))
37+ })
2938
30- app .addRecentDocument (' /Users/USERNAME/Desktop/work.type' )
39+ app .whenReady ().then (createWindow)
40+
41+ app .on (' window-all-closed' , () => {
42+ app .clearRecentDocuments ()
43+ if (process .platform !== ' darwin' ) {
44+ app .quit ()
45+ }
46+ })
47+
48+ app .on (' activate' , () => {
49+ if (BrowserWindow .getAllWindows ().length === 0 ) {
50+ createWindow ()
51+ }
52+ })
3153```
3254
33- After launching the Electron application, right click the application icon.
34- You should see the item you just added. In this guide, the item is a Markdown
35- file located in the root of the project:
55+ #### Adding a recent document
3656
37- ![ Recent document] ( ../images/recent-documents.png )
57+ To add a file to recent documents, use the
58+ [ app.addRecentDocument] [ addrecentdocument ] API.
3859
39- ### Clear the list of recent documents
60+ After launching the Electron application, right click the application icon.
61+ In this guide, the item is a Markdown file located in the root of the project.
62+ You should see ` recently-used.md ` added to the list of recent files:
4063
41- To clear the list of recent documents, you need to use
42- [ app.clearRecentDocuments] [ clearrecentdocuments ] API in the ` main.js ` file:
64+ ![ Recent document] ( ../images/recent-documents.png )
4365
44- ``` javascript
45- const { app } = require (' electron' )
66+ #### Clearing the list of recent documents
4667
47- app .clearRecentDocuments ()
48- ```
68+ To clear the list of recent documents, use the
69+ [ app.clearRecentDocuments] [ clearrecentdocuments ] API.
70+ In this guide, the list of documents is cleared once all windows have been
71+ closed.
4972
5073## Additional information
5174
0 commit comments