{"id":13798044,"url":"https://github.com/jprichardson/electron-window","last_synced_at":"2025-04-04T10:02:45.897Z","repository":{"id":32498079,"uuid":"36078769","full_name":"jprichardson/electron-window","owner":"jprichardson","description":"Convenience methods for Electron windows.","archived":false,"fork":false,"pushed_at":"2018-09-21T09:55:30.000Z","size":37,"stargazers_count":290,"open_issues_count":7,"forks_count":28,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-01-31T22:54:39.029Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"hyperledger-archives/fabric","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jprichardson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-22T15:11:48.000Z","updated_at":"2024-07-21T18:12:30.000Z","dependencies_parsed_at":"2022-08-02T12:07:07.877Z","dependency_job_id":null,"html_url":"https://github.com/jprichardson/electron-window","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Felectron-window","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Felectron-window/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Felectron-window/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Felectron-window/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jprichardson","download_url":"https://codeload.github.com/jprichardson/electron-window/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237575791,"owners_count":19332524,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:00:38.222Z","updated_at":"2025-02-08T04:07:00.975Z","avatar_url":"https://github.com/jprichardson.png","language":"JavaScript","readme":"electron-window\n===============\n\nConvenience methods for Electron windows.\n\n\nInstallation\n------------\n\n    npm i --save electron-window\n\n\nUsage\n-----\n\n### TL;DR:\n\n`electron-window` converts this:\n\n```js\nconst { \n  app, \n  BrowserWindow \n} = require('electron')\n\nconst path = require('path')\nconst url = require('url')\n\n// Keep a global reference of the window object, if you don't, the window will\n// be closed automatically when the javascript object is GCed.\nlet mainWindow = null\n\napp.on('ready', () =\u003e {\n  mainWindow = new BrowserWindow({ width: 1000, height: 400, show: false })\n\n  const someArgs = { data: 'hi' }\n  const indexPath = path.resolve(__dirname, '..', 'weird-location', 'index.html')\n  const indexUrl = url.format({\n    protocol: 'file',\n    pathname: indexPath,\n    slashes: true,\n    hash: encodeURIComponent(JSON.stringify(someArgs))\n  })\n\n  mainWindow.on('closed', () =\u003e {\n    mainWindow = null\n  })\n\n  mainWindow.webContents.on('did-finish-load', () =\u003e {\n    mainWindow.show()\n    console.log('window is now visible!')\n  })\n\n  mainWindow.loadUrl(indexUrl)\n})\n```\n\nto this:\n\n```js\nconst { app } = require('electron')\nconst path = require('path')\nconst window = require('electron-window')\n\napp.on('ready', () =\u003e {\n  const mainWindow = window.createWindow({ width: 1000, height: 400 })\n  const someArgs = { data: 'hi' }\n  const indexPath = path.resolve(__dirname, '..', 'weird-location', 'index.html')\n  \n  mainWindow.showUrl(indexPath, someArgs, () =\u003e {\n    console.log('window is now visible!')\n  })\n})\n```\n\n\n### API Methods\n\n#### createWindow(options)\n\nClass method that creates a new [BrowserWindow](https://github.com/atom/electron/blob/master/docs/api/browser-window.md) with\nthe following default `options`: `{ show: false }`. No need to worry about keeping a global reference\nto prevent garbage collection, this is handled for you.\n\n\n#### parseArgs()\n\nInstance method to parse arguments in window. You would only need to call from your renderer preload script if you pass in\n[`preload`](https://github.com/atom/electron/blob/master/docs/api/browser-window.md#new-browserwindowoptions).\n\n\n#### showUrl(httpOrFileUrl, [argsForRenderer], [callback])\n\nInstance method that shows the url. When the url is finished loading, the callback is returned. If the optional `argsForRenderer` is set\nthen `__args__` will be a global object for the page in the renderer process. This is a convenient way to pass\narguments from the main process to the renderer process.\n\n\n#### unref()\n\nInstance method to call if you ever want to remove the global reference. Should only need to be called if\n[`destroy()`](https://github.com/atom/electron/blob/master/docs/api/browser-window.md#browserwindowdestroy) is ever called.\nMost likely, you won't need to use this.\n\n\n### API Properties\n\n#### windows\n\nClass property to get a reference to all windows created and their ids. This is in the form of an object where the keys are window ids, and the values are instances of `BrowserWindow`.\n\n\n\n### Example\n\n**main process**\n\n```js\nconst window = require('electron-window')\n\nconst windowOptions = {\n  width: 1000,\n  height: 400\n}\n\nconst mainWindow = window.createWindow(windowOptions)\n\n// can access at window.__args__ from scripts\n// ran from index.html\nconst args = {\n  data: 'some secret data'\n}\n\nmainWindow.showUrl('index.html', args, () =\u003e {\n  console.log('the window should be showing with the contents of the URL now')\n})\n```\n\n**renderer process**\n\n```js\n// only call if `preload` is set in `windowOptions`\nrequire('electron-window').parseArgs()\n\nconsole.log(window.__args__)\n// =\u003e Object {data: \"some secret data\"}\n```\n\n\nLicense\n-------\n\nMIT\n\n\n","funding_links":[],"categories":["Library","Components"],"sub_categories":["Window","Using Electron"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjprichardson%2Felectron-window","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjprichardson%2Felectron-window","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjprichardson%2Felectron-window/lists"}