Repository: electron/electron (language: cpp)

Issue:
[Bug]: the example in the document of represented file creates BrowserWindow twice
doc link: https://www.electronjs.org/docs/latest/tutorial/represented-file
code: https://github.com/electron/electron/blob/d8e7457ab0fa13b16d7c8e10395dd315e6fe2077/docs/fiddles/features/represented-file/main.js#L4-L18

The code in the example creates BrowserWindow both in the `createWindow` function and after `app.whenReady()`, which not loads `index.html` properly.



Discussion / hints:
This issue has been automatically marked as stale. **If this issue is still affecting you, please leave any comment** (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the [latest version of Electron](https://www.electronjs.org/releases/stable) or in the [beta](https://www.electronjs.org/releases/beta)—please include it with your comment!
May I send a pr to fix this?

Fix patch:
diff --git a/docs/fiddles/features/represented-file/main.js b/docs/fiddles/features/represented-file/main.js
index 183b3fc3d169c..6898a110f97b8 100644
--- a/docs/fiddles/features/represented-file/main.js
+++ b/docs/fiddles/features/represented-file/main.js
@@ -7,14 +7,20 @@ function createWindow () {
     height: 600
   })
 
+  win.setRepresentedFilename(os.homedir())
+  win.setDocumentEdited(true)
+
   win.loadFile('index.html')
 }
 
 app.whenReady().then(() => {
-  const win = new BrowserWindow()
+  createWindow()
 
-  win.setRepresentedFilename(os.homedir())
-  win.setDocumentEdited(true)
+  app.on('activate', () => {
+    if (BrowserWindow.getAllWindows().length === 0) {
+      createWindow()
+    }
+  })
 })
 
 app.on('window-all-closed', () => {
@@ -22,9 +28,3 @@ app.on('window-all-closed', () => {
     app.quit()
   }
 })
-
-app.on('activate', () => {
-  if (BrowserWindow.getAllWindows().length === 0) {
-    createWindow()
-  }
-})


Test patch: