* Creates a new editor window.
(
rootDirectory: string | null = null,
fileList: string[] = [],
markdownList: string[] = [],
options: Partial<BrowserWindowConstructorOptions> = {},
bufferStoreInfo: BufferStoreInfo | null = null
)
| 67 | * Creates a new editor window. |
| 68 | */ |
| 69 | createWindow( |
| 70 | rootDirectory: string | null = null, |
| 71 | fileList: string[] = [], |
| 72 | markdownList: string[] = [], |
| 73 | options: Partial<BrowserWindowConstructorOptions> = {}, |
| 74 | bufferStoreInfo: BufferStoreInfo | null = null |
| 75 | ): BrowserWindow { |
| 76 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 77 | const accessor = this._accessor as any |
| 78 | const { menu: appMenu, env, preferences, editorBufferStore } = accessor |
| 79 | const addBlankTab = |
| 80 | !bufferStoreInfo && !rootDirectory && fileList.length === 0 && markdownList.length === 0 |
| 81 | |
| 82 | const mainWindowState = windowStateKeeper({ |
| 83 | defaultWidth: 1200, |
| 84 | defaultHeight: 800 |
| 85 | }) |
| 86 | |
| 87 | const { x, y, width, height } = ensureWindowPosition(mainWindowState) |
| 88 | const winOptions: BrowserWindowConstructorOptions = Object.assign( |
| 89 | { x, y, width, height }, |
| 90 | editorWinOptions, |
| 91 | options |
| 92 | ) |
| 93 | if (isLinux) { |
| 94 | winOptions.icon = path.join(process.cwd(), 'static', 'logo-96px.png') |
| 95 | } |
| 96 | |
| 97 | const { |
| 98 | titleBarStyle, |
| 99 | theme, |
| 100 | sideBarVisibility, |
| 101 | restoreLayoutState, |
| 102 | tabBarVisibility, |
| 103 | sourceCodeModeEnabled, |
| 104 | spellcheckerEnabled, |
| 105 | spellcheckerLanguage |
| 106 | } = preferences.getAll() |
| 107 | const resolvedSideBarVisibility = restoreLayoutState ? !!sideBarVisibility : false |
| 108 | |
| 109 | // Enable native or custom/frameless window and titlebar |
| 110 | if (!isOsx) { |
| 111 | winOptions.titleBarStyle = 'default' |
| 112 | if (titleBarStyle === 'native') { |
| 113 | winOptions.frame = true |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | winOptions.backgroundColor = this._getPreferredBackgroundColor(theme) |
| 118 | if (env.disableSpellcheck) { |
| 119 | // winOptions.webPreferences is set by editorWinOptions spread above |
| 120 | ;(winOptions.webPreferences as { spellcheck: boolean }).spellcheck = false |
| 121 | } |
| 122 | |
| 123 | let win: BrowserWindow | null = (this.browserWindow = new BrowserWindow(winOptions)) |
| 124 | |
| 125 | // Give every editor window a stable id for session buffer persistence. |
| 126 | // We cant use win.id as it might collide with same IDs from closed windows |
no test coverage detected