|
17 | 17 | [download-image]: https://img.shields.io/npm/dm/electron-windows.svg |
18 | 18 | [download-url]: https://npmjs.org/package/electron-windows |
19 | 19 |
|
20 | | -> Manage multiple windows of Electron gracefully and provides powerful features. |
| 20 | +> Manage multiple windows of Electron gracefully and provide powerful features. |
21 | 21 |
|
22 | | -<!-- GITCONTRIBUTOR_START --> |
23 | | - |
24 | | -## Contributors |
25 | | - |
26 | | -|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/17586742?v=4" width="100px;"/><br/><sub><b>sriting</b></sub>](https://github.com/sriting)<br/>|[<img src="https://avatars.githubusercontent.com/u/52845048?v=4" width="100px;"/><br/><sub><b>snapre</b></sub>](https://github.com/snapre)<br/>|[<img src="https://avatars.githubusercontent.com/u/12660278?v=4" width="100px;"/><br/><sub><b>ColaDaddyz</b></sub>](https://github.com/ColaDaddyz)<br/>|[<img src="https://avatars.githubusercontent.com/u/30524126?v=4" width="100px;"/><br/><sub><b>z0gSh1u</b></sub>](https://github.com/z0gSh1u)<br/>|[<img src="https://avatars.githubusercontent.com/u/4081746?v=4" width="100px;"/><br/><sub><b>zlyi</b></sub>](https://github.com/zlyi)<br/>| |
27 | | -| :---: | :---: | :---: | :---: | :---: | :---: | |
28 | | -[<img src="https://avatars.githubusercontent.com/u/50158871?v=4" width="100px;"/><br/><sub><b>moshangqi</b></sub>](https://github.com/moshangqi)<br/> |
29 | | - |
30 | | -This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Fri Apr 25 2025 11:40:35 GMT+0800`. |
31 | | - |
32 | | -<!-- GITCONTRIBUTOR_END --> |
33 | | - |
34 | | -## Installment |
| 22 | +## Installation |
35 | 23 |
|
36 | 24 | ```bash |
37 | 25 | $ npm i electron-windows --save |
38 | 26 | ``` |
39 | 27 |
|
40 | 28 | ## Demo |
41 | 29 |
|
42 | | - |
| 30 | + |
43 | 31 |
|
44 | | -## APIs |
45 | | - |
46 | | -### init |
| 32 | +## Quick Start |
47 | 33 |
|
48 | 34 | ```javascript |
49 | | -const WindowManager = require('electron-windows'); |
50 | | -const windowManager = new WindowManager(); |
51 | | -``` |
| 35 | +const WindowManager = require('electron-windows') |
52 | 36 |
|
53 | | -### create |
| 37 | +const windowManager = new WindowManager() |
54 | 38 |
|
55 | | -```javascript |
56 | | -const { app } = require('electron'); |
57 | | -const winRef = windowManager.create({ |
58 | | - name: 'window1', |
59 | | - loadingView: { |
60 | | - url: '', |
61 | | - }, |
| 39 | +// Create a window |
| 40 | +const mainWindow = windowManager.create({ |
| 41 | + name: 'main', |
62 | 42 | browserWindow: { |
63 | 43 | width: 800, |
64 | 44 | height: 600, |
65 | | - titleBarStyle: 'hidden', |
66 | | - title: 'demo', |
67 | | - show: false, |
68 | | - webPreferences: { |
69 | | - nodeIntegration: app.isDev, |
70 | | - webSecurity: true, |
71 | | - webviewTag: true, |
72 | | - }, |
73 | 45 | }, |
74 | | - openDevTools: true, |
75 | | - storageKey: 'storage-filename', // optional. The name of file. Support storage of window state |
76 | | - storagePath: app.getPath('userData'), // optional. The path of file, only used when storageKey is not empty |
77 | | -}); |
| 46 | +}) |
| 47 | + |
| 48 | +// Get window by name |
| 49 | +const theWindow = windowManager.get('main') |
| 50 | + |
| 51 | +// Get window by id |
| 52 | +const theWindowToo = windowManager.getById(mainWindow.id) |
| 53 | + |
| 54 | +// Get all windows |
| 55 | +const all = windowManager.getAll() |
78 | 56 | ``` |
79 | 57 |
|
80 | | -## TODO |
| 58 | +## API Reference |
| 59 | + |
| 60 | +### `new WindowManager()` |
| 61 | + |
| 62 | +Creates a new WindowManager instance. |
| 63 | + |
| 64 | +### `windowManager.create(options)` |
| 65 | + |
| 66 | +Creates and manages a new BrowserWindow. |
| 67 | + |
| 68 | +- **options** `Object` - Configuration for the window: |
| 69 | + - **name** `string` - Window identifier, used by `get()`. Default: `'anonymous'` |
| 70 | + - **browserWindow** `Object` - [Electron BrowserWindow options](https://www.electronjs.org/docs/latest/api/browser-window) |
| 71 | + - **loadingView** `Object` - Loading view configuration: |
| 72 | + - **url** `string` - URL to show while main content loads |
| 73 | + - **openDevTools** `boolean` - Auto open DevTools when window is ready. Default: `false` |
| 74 | + - **preventOriginClose** `boolean` - Prevent window from closing, need manually close. Default: `false` |
| 75 | + - **preventOriginNavigate** `boolean` - Prevent webContents navigation. Default: `false` |
| 76 | + - **storageKey** `string` - Save/restore window position and size using `electron-window-state` |
| 77 | + - **storagePath** `string` - Custom storage path for window state file |
| 78 | + - **globalUserAgent** `string` - Custom User-Agent for all `loadURL` calls in this window |
| 79 | + |
| 80 | +Returns: `BrowserWindow` |
| 81 | + |
| 82 | +### `windowManager.get(name)` |
| 83 | + |
| 84 | +Get a managed window by name. |
| 85 | + |
| 86 | +- **name** `string` - Window name |
| 87 | + |
| 88 | +Returns: `BrowserWindow | undefined` |
| 89 | + |
| 90 | +### `windowManager.getById(id)` |
| 91 | + |
| 92 | +Get a managed window by Electron window id. |
| 93 | + |
| 94 | +- **id** `number` - Window id |
| 95 | + |
| 96 | +Returns: `BrowserWindow | undefined` |
| 97 | + |
| 98 | +### `windowManager.getAll()` |
| 99 | + |
| 100 | +Get all managed windows. |
| 101 | + |
| 102 | +Returns: `Object` - Object with window IDs as keys |
| 103 | + |
| 104 | +### `WindowManager.setGlobalUserAgent(ua)` |
| 105 | + |
| 106 | +Static method. Set global user agent for all windows. |
| 107 | + |
| 108 | +- **ua** `string` - User agent string |
| 109 | + |
| 110 | +## Roadmap |
81 | 111 |
|
82 | 112 | - [ ] support storage of window configuration |
83 | | -- [ ] clone pointed window |
| 113 | +- [ ] support window cloning |
| 114 | + |
| 115 | +<!-- GITCONTRIBUTOR_START --> |
| 116 | + |
| 117 | +## Contributors |
| 118 | + |
| 119 | +|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="80px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/17586742?v=4" width="80px;"/><br/><sub><b>sriting</b></sub>](https://github.com/sriting)<br/>|[<img src="https://avatars.githubusercontent.com/u/30524126?v=4" width="80px;"/><br/><sub><b>z0gSh1u</b></sub>](https://github.com/z0gSh1u)<br/>|[<img src="https://avatars.githubusercontent.com/u/52845048?v=4" width="80px;"/><br/><sub><b>snapre</b></sub>](https://github.com/snapre)<br/>|[<img src="https://avatars.githubusercontent.com/u/12660278?v=4" width="80px;"/><br/><sub><b>ColaDaddyz</b></sub>](https://github.com/ColaDaddyz)<br/>|[<img src="https://avatars.githubusercontent.com/in/1143301?v=4" width="80px;"/><br/><sub><b>Copilot</b></sub>](https://github.com/apps/copilot-swe-agent)<br/>| |
| 120 | +| :---: | :---: | :---: | :---: | :---: | :---: | |
| 121 | +[<img src="https://avatars.githubusercontent.com/u/11213298?v=4" width="80px;"/><br/><sub><b>WynterDing</b></sub>](https://github.com/WynterDing)<br/>|[<img src="https://avatars.githubusercontent.com/u/4081746?v=4" width="80px;"/><br/><sub><b>zlyi</b></sub>](https://github.com/zlyi)<br/>|[<img src="https://avatars.githubusercontent.com/u/50158871?v=4" width="80px;"/><br/><sub><b>moshangqi</b></sub>](https://github.com/moshangqi)<br/> |
| 122 | + |
| 123 | +This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Mon Feb 23 2026 15:23:51 GMT+0800`. |
| 124 | + |
| 125 | +<!-- GITCONTRIBUTOR_END --> |
84 | 126 |
|
85 | 127 | ## License |
86 | 128 |
|
|
0 commit comments