{"_id":"@advanced-rest-client/arc-electron-preferences","_rev":"11-645e40d48454d54d301ee016605e0f30","name":"@advanced-rest-client/arc-electron-preferences","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0-rc1":{"name":"@advanced-rest-client/arc-electron-preferences","version":"1.0.0-rc1","author":{"name":"Pawel Psztyc"},"license":"Apache-2.0","_id":"@advanced-rest-client/arc-electron-preferences@1.0.0-rc1","maintainers":[{"name":"jarrodek","email":"jarrodek@gmail.com"}],"dist":{"shasum":"45d802628eb63b3aa241cd8a765acdf575e31a8b","tarball":"https://registry.npmjs.org/@advanced-rest-client/arc-electron-preferences/-/arc-electron-preferences-1.0.0-rc1.tgz","fileCount":19,"integrity":"sha512-9DeS3XkiWLaCOOgvqTeWFjNcsB+d23MvHJRN2URpNpoANibzQXOty53470Q/UINtxVBbXnrNpuq0A3EYm/rM7w==","signatures":[{"sig":"MEUCIC/eY24FL1dkL1GKqsjl0Z1aDz351hajSLFZwOyLeRfQAiEAv1m8AGwYIWaN1VogN0W23RVWGKmmurOTwuaf3465orE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":65829,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbbmHeCRA9TVsSAnZWagAAOQAP/1E4W7GI6geU64+/ynka\nvJAA7aOvWdv82x7SBo8cycLZ2IrUZCou05AWb7QXhkwEEY0KD9u2k9497MLf\nslVWm6ptiTa371vTI2P0W2d6GKHWCMLnQotJ8nk1g1mAl/TqQi4CNo/wzT9f\nzKA0CR5J4C+V78LuZ0Darl0ivccDCk3DlDS8iaBjgiyAvbU5qhEMSEQrhgUj\n/WrKhkAbNfs7bBU55CukHeC1dsSMDIDAngMTdXu1gXnB6G2f8xd7uKumNorb\nw2b18tCLA8KFYUcLS0xDN8s/A3Lj4Jp4K9zUVlst4E2vtbJ9uatgIRvy5evL\nNhbJkaU1uQ0HJrEwDypPfAkGtjL5itJKP51zpqNURxnCheEAX/hF+lpBrhZ0\nBzCItxnCXXMDkg+XVEc5veyzGt2OUiNGISOHe0frAdrkyuctCVa+89Jrzcjs\nF1MiYyKevsaRYCcdZ70pwP/WPLWnX7SfdjxGCxMB6B9QQUqIbuWAa3UTXcze\nnkEA/HxY6xk9E2O1pfkUhBrFJ9Kq65m/ojCpfqp36rxBoz/CHipZdVMGuGGg\nuFs8ddIE7xXnbyM3st230MnTFoy1OMHBtemUhfeTn6W5F1Hm0wzh9JUdmkSK\nw7q9rUaNOB4FXlFTbjx9pywQcPOjupLEe7W0KhGjbdI7TyQ9ClJbsc7UAEeb\nWEvV\r\n=jPDn\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"059a95c1e5d09ca7805237a421b3956185cbfca2","scripts":{"test":"electron-mocha test/*.main.test.js && electron-mocha --renderer test/*.renderer.test.js"},"_npmUser":{"name":"jarrodek","email":"jarrodek@gmail.com"},"_npmVersion":"6.3.0","description":"A package to handle ARC preferences state in both rendered and main process","directories":{},"_nodeVersion":"8.11.2","dependencies":{"uuid":"^3.2.1","fs-extra":"^7.0.0","electron-log":"^2.2.16","@advanced-rest-client/arc-electron-payload-processor":"^0.1.0"},"_hasShrinkwrap":false,"devDependencies":{"chai":"^4.1.2","mocha":"^4.1.0","electron":"^2.0.7","electron-mocha":"^6.0.4"},"_npmOperationalInternal":{"tmp":"tmp/arc-electron-preferences_1.0.0-rc1_1533960669724_0.09372096349402859","host":"s3://npm-registry-packages"}},"1.0.0-rc2":{"name":"@advanced-rest-client/arc-electron-preferences","version":"1.0.0-rc2","author":{"name":"Pawel Psztyc"},"license":"Apache-2.0","_id":"@advanced-rest-client/arc-electron-preferences@1.0.0-rc2","maintainers":[{"name":"jarrodek","email":"jarrodek@gmail.com"}],"dist":{"shasum":"c96bf159bf18863bbc4dd88b00f862b22ba9ff48","tarball":"https://registry.npmjs.org/@advanced-rest-client/arc-electron-preferences/-/arc-electron-preferences-1.0.0-rc2.tgz","fileCount":19,"integrity":"sha512-maJRVNJOSM+yYzXPzD5NNjipk3qjO8kTSsrR95Qt76UiCKi0KOGwZG5j8m6whEh1+EArFXOJ1xtII+up5JKBgg==","signatures":[{"sig":"MEUCIQDv+p6typdCD3PmwF7gzkrkPHU8UW9leSczg5l5nUoiWgIgfMG1QP2S3AJWiIoitFMa7P/c4DSaTCiAN/asokucWu4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":66333,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbqtl4CRA9TVsSAnZWagAAJ8EP+wV15T5izV4l6tIPgNid\n0gcJlXVmNNTYD9jheafO5ilCpzSAS09fjpSjHhf8GwQZVyVm5W/RMgiMLvln\n2PKt5OjvSG1qs6QTi/iLm4vP7xZmNwxCZiJmL0GJo8g0QTPQNXYEUz3myXy1\ntSKq2V/KrLQxm8leICzFs/urvzJr+eXrfLK2JxeshidcIKavrpoassndIr+x\nroyxB2b7LqqY3y4tBYkub7HC6TaoJtMGoIuaxz9MgOy5AqCcGGUwlRMZWVU2\nfm9jl3F/P8i5gMB1jbkQGfhglJznKBOAgYqEkcHE6FypMzofUlmx0wRmyImo\n7vci645ji0TsU7NFaWgIGCIsNJjzCn5iKbY0/l3lBWqEGFVSGP4fQQxVIV39\nmjGPM6dwXkUIIiTVX9MhGBcPdSqdreZoDI0tiZ6snPy98uX+GBrgXMrNBWi6\nH7W2w9gCKvnJmxo/ZpVbnlvw43owfCNe06pycmPhZj0JlEjQ+5P0R+pmX77z\nf1lRtbHTL0EHuqTfGGC84Ut+oaC4BrcmWIfzqKPbFZSJjarUCmEWAth7AzTw\nCaGBp2sMNWWbcI3I0ZIM9EJurnAcCnQ+PbtixI3aa5TYO0Qmh5YJ9tW5jXZ/\n/OdLHAeHcsvt/YEltdwoN6zDLGMtMvfj9e6JgViMxkPIFm1uKt/u35V6bWoN\nTciW\r\n=ShyT\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"66b1093c1f08481edaca5fbe7de7631e1766ea92","scripts":{"test":"electron-mocha test/*.main.test.js && electron-mocha --renderer test/*.renderer.test.js"},"_npmUser":{"name":"jarrodek","email":"jarrodek@gmail.com"},"_npmVersion":"6.4.1","description":"A package to handle ARC preferences state in both rendered and main process","directories":{},"_nodeVersion":"8.11.2","dependencies":{"uuid":"^3.2.1","fs-extra":"^7.0.0","electron-log":"^2.2.16","@advanced-rest-client/arc-electron-payload-processor":"^0.1.0"},"_hasShrinkwrap":false,"devDependencies":{"chai":"^4.1.2","mocha":"^4.1.0","electron":"^2.0.7","electron-mocha":"^6.0.4"},"_npmOperationalInternal":{"tmp":"tmp/arc-electron-preferences_1.0.0-rc2_1537923448114_0.7779715157021381","host":"s3://npm-registry-packages"}},"2.0.0":{"name":"@advanced-rest-client/arc-electron-preferences","version":"2.0.0","author":{"name":"Pawel Psztyc"},"license":"Apache-2.0","_id":"@advanced-rest-client/arc-electron-preferences@2.0.0","maintainers":[{"name":"jarrodek","email":"jarrodek@gmail.com"}],"dist":{"shasum":"a0be8f07a34fb52b644a1dc576342f8a0a1c06b9","tarball":"https://registry.npmjs.org/@advanced-rest-client/arc-electron-preferences/-/arc-electron-preferences-2.0.0.tgz","fileCount":23,"integrity":"sha512-HmEDLP1U/oYUi4MZkkoBBnpEQ6iqtx3KI5ceCv7X0YlLgJPnamU9Wvzg4Feha/Ic3mCyjOyNvCtbcMSy7onuhA==","signatures":[{"sig":"MEUCIQDyLWlOudCgiedRErOdHG5qqhQQpXU2I7AlORCp7qbr4gIgRbu2urQKv+Nya2n+GGnCOuopSB4RHSsRvg42AKKYJLk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":50528,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd3NOvCRA9TVsSAnZWagAApEkQAJgQVN5P6Wzbktr0zreF\n/Fzoh9j13fqmhQDx8HS7yTjRC35/hhPiUYo/hJNF592FRelFgFcUa19OU6H1\nc9SXdQrlAZuL6myeKqW5bjr8bgsc+XEHxU18aOwVkASByAcC8o64tD71f6fH\nc/qaIaON5TOCjhXkrbFeHFvTnqDX7zmtoTLMhucUxH5KDHlXN5Y0Y3An8o/F\n0/FkS8nNYrUZ9kyfBZen32maXBAbQ75etQY0bJF8XXLdv3G1/y6s6b6R9JuA\nm3Qn9x7FFknLmMuQ5MVATz7tSs+1rU29xLqJ2bghSe/mBxzF8ZoCl/zXdusq\nXFBBLEXgwbyk3OWQdpGlZi9rCCw7gGxBrBPmLgydvCW6Xb+j0GBtd3NWxxpy\nq8DrlY41MVNgWOynvKvjG3aUbcN+YFhcIecAiY5jZdFqgkzQlmoOabki+INr\n9k3vwoLriEijIlCr27pSfa3HswCzelDW97/p+IMWJYFPG3YbqBq+5ZBTTfSB\nmaOtOAympstPSQwvaAH+plt5RGPhpweRMcHpLcYMYRKknscjBbT6m4usfb8A\nG13oCmFJ40EcntHd0zLLf2Y5PByeONH86kvZai5HXvAmCkVrOGRMSuM3BcoR\nHWJoTvUtLXR33/DL3RA76jE/TSlY+3Ki5f5ld+7P6du+esrJIfQEnI2jmRNt\nYNzj\r\n=h7pN\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","type":"module","gitHead":"44f3da22696e312d0b94113f3d894ed4e68c02fe","scripts":{"test":"npm run test:main && npm run test:renderer && npm run test:proxy","test:main":"electron-mocha test/*.main.test.js","test:proxy":"electron-mocha --renderer test/preferences-proxy.test.js --require-main test/proxy-test-main-script.js","test:renderer":"electron-mocha --renderer test/*.renderer.test.js"},"_npmUser":{"name":"jarrodek","email":"jarrodek@gmail.com"},"_npmVersion":"6.13.1","description":"A package to handle preferences state in electron application","directories":{},"_nodeVersion":"12.13.0","dependencies":{"esm":"^3.2.25","uuid":"^3.3.3","fs-extra":"^8.1.0","electron-log":"^3.0.9"},"_hasShrinkwrap":false,"devDependencies":{"chai":"^4.2.0","mocha":"^6.2.2","eslint":"^6.7.1","electron":"^7.1.2","babel-eslint":"^10.0.3","electron-mocha":"^8.1.2","eslint-config-google":"^0.14.0","@advanced-rest-client/eslint-config":"^1.1.3"},"peerDependencies":{"electron":"^7.x"},"_npmOperationalInternal":{"tmp":"tmp/arc-electron-preferences_2.0.0_1574753199369_0.2117972381215385","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-08-11T04:11:09.546Z","modified":"2026-04-07T19:30:08.799Z","1.0.0-rc1":"2018-08-11T04:11:09.843Z","1.0.0-rc2":"2018-09-26T00:57:28.299Z","2.0.0":"2019-11-26T07:26:39.504Z"},"author":{"name":"Pawel Psztyc"},"license":"Apache-2.0","description":"A package to handle preferences state in electron application","maintainers":[{"email":"jarrodek@gmail.com","name":"jarrodek"},{"email":"alexperez@mulesoft.com","name":"alexperez_march_2024"},{"email":"elmellidiego@gmail.com","name":"dmacias"}],"readme":"# arc-electron-preferences\n\n\n**This library only works with Electron >= 7.0.0**. Electron is required as a peer dependency of this project.\n\nA module to be used in Electron application to add support for storing preferences.\n\nIt is mainly used for Advanced REST Client and API Console projects. However it is made in the most universal way.\n\nIt contains classes to work in both main and renderer processes.\n\n## ESM zone\n\nThe models are ES modules. If your application does not support ESM then always use `index.js` files located in main package,\n`lib/`, `main/`, and `renderer/` directories.\n\n## Main process\n\nApplication settings storing/restoring/updating is only handled in the main process. Even though it is possible to use `AppPreferences` class in the renderer process,\nto minimize the risk of desynchronizing settings always use `PreferencesManager` in the main process and `PreferencesProxy` in the renderer process.\nIf the application, however, has only single window and the main process do not store instance of the `AppPreferences` or `PreferencesManager` in the memory it is safe to read and update file directly from the renderer process.\n\n```javascript\nimport { PreferencesManager } from '@advanced-rest-client/arc-electron-preferences';\nconst mgr = new PreferencesManager();\nmgr.observe();\n```\n\n## Renderer process\n\n### Working with Preferences manager\n\nUse the proxy to communicate with the main process using channels (not regular IPC events!).\n\n```javascript\nimport { ArcPreferencesProxy } from '@advanced-rest-client/arc-electron-preferences/renderer';\n\nconst proxy = new ArcPreferencesProxy();\nproxy.observe();\n```\n\n#### Direct API\n\n```javascript\nconst settings = await proxy.load(); // load current settings\nawait proxy.store('name', 'someValue');\n```\n\n#### Web events\n\n##### Reading settings\n\n```javascript\nconst e = new CustomEvent('settings-read', {\n  bubbles: true,\n  composed: true, // assuming custom element\n  cancelable: true,\n  detail: {} // must be set!\n});\nthis.dispatchEvent(e); // assuming custom element\n\nif (e.defaultPrevented) {\n  e.detail.result.then((settings) => console.log(settings));\n}\n```\n\n##### Updating settings\n\n```javascript\nconst e = new CustomEvent('settings-changed', {\n  bubbles: true,\n  composed: true, // assuming custom element\n  cancelable: true,\n  detail: {\n    name: 'my-setting',\n    value: 'my-value'\n  }\n});\nthis.dispatchEvent(e); // assuming custom element\n\nif (e.defaultPrevented) {\n  e.detail.result.then((settings) => console.log('Settings saved'));\n}\n```\n\nWhen settings are updates every browser window receives `app-preference-updated`\nevent from the main page on the ipc main bus and the proxy dispatches non cancellable\n`settings-changed` custom event. Therefore once the proxy is initialized the\ncomponents / application should just listen to this event to know if a setting\nchanged.\n\n## Application meta data (main process)\n\nWhen first run the app creates a meta data file. The file contains `appId` which is an `uuid` version 4 string and `aid` which is `uuid` version 5.\n\nThe `appId` property can be used to identify specific instance of the application.\nThis can be used to synchronize data between the instance and the application server.\n\nThe `aid` is anonymised application id that should be used with analytics suite.\nThis property cannot be used anywhere else to ensure that any analytics data cannot be connected to specific instance.\n\n### Usage\n\n```javascript\nimport { AppMeta } from '@advanced-rest-client/arc-electron-preferences';\n\nconst meta = new AppMeta();\n// appId is persistent and can be used to identify the app instance\nconst appId = await meta.getAppId();\n// aid can be only used to record a user session.\nconst aid = await meta.getAninimizedId();\n```\n\n## Session control (window meta)\n\nThe `SessionControl` updates application's window state to the state file.\nIt includes window position and size.\n\n### Example usage\n\n```javascript\nimport { SessionControl } from '@advanced-rest-client/arc-electron-preferences';\n\n// The argument is the index of the window.\nconst session = new SessionControl(1);\nconst state = await session.load();\nconst win = new BrowserWindow({\n  width: state.size.width,\n  height: state.size.height,\n  x: state.position.x,\n  y: state.position.y,\n});\nsession.trackWindow(win);\nwin.metaSession = session;\nwin.addListener('closed', () => {\n  win.metaSession.untrackWindow();\n});\n```\n\nThe constructor takes window index as an argument. Each window has it's own\nstate file that keeps its size and position.\n\nThe second optional argument is a map of default values for window `width` and `height`\nand `debounce` to store the state after this amount of ms.\n\nThe application can call `updatePosition()` and `updateSize()` function by it's\nown. The class provides the `trackWindow()` function that tracks both `resize`\nand `move` events of the window object. **when using this function** clear\nevent listeners when the window is closed or it will newer get garbage collected.\n","readmeFilename":"README.md"}