├── .github ├── demo.gif └── workflows │ ├── node.js.yml │ └── npm-publish.yml ├── .gitignore ├── LICENSE.md ├── README.md ├── index.js ├── package-lock.json └── package.json /.github/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zachflower/hyper-confirm/6cba4dbd770b4a86b2b6ed162b6c2488030afeef/.github/demo.gif -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [10.x, 12.x, 14.x] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v1 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | - run: npm ci 28 | - run: npm run build --if-present 29 | - run: npm test 30 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages 3 | 4 | name: Node.js Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: actions/setup-node@v1 16 | with: 17 | node-version: 12 18 | - run: npm ci 19 | - run: npm run build --if-present 20 | - run: npm test 21 | 22 | publish-npm: 23 | needs: build 24 | runs-on: ubuntu-latest 25 | steps: 26 | - uses: actions/checkout@v2 27 | - uses: actions/setup-node@v1 28 | with: 29 | node-version: 12 30 | registry-url: https://registry.npmjs.org/ 31 | - run: npm ci 32 | - run: npm run build --if-present 33 | - run: npm publish 34 | env: 35 | NODE_AUTH_TOKEN: ${{secrets.npm_token}} 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright © 2017 Zachary Flower 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > [!IMPORTANT] 2 | > hyper-confirm is no longer in active maintenance, so it is not recommended to be used and unlikely to work with the latest versions of Hyper. I am not aware of a replacement plugin, but will happily add a link here if someone wants to send one my way. 3 | 4 | ![build](https://github.com/zachflower/hyper-confirm/workflows/Node.js%20CI/badge.svg) [![npm](https://img.shields.io/npm/v/hyper-confirm.svg)](https://www.npmjs.com/package/hyper-confirm) [![npm](https://img.shields.io/npm/dt/hyper-confirm.svg)](https://www.npmjs.com/package/hyper-confirm) [![npm](https://img.shields.io/npm/l/hyper-confirm.svg)](https://www.npmjs.com/package/hyper-confirm) 5 | 6 | # hyper-confirm 7 | 8 | `hyper-confirm` is a plugin for [Hyper](https://hyper.is/) (formerly HyperTerm) that shows a confirmation dialog before quitting Hyper. This functionality, which is found in other terminal emulators like [iTerm2](https://www.iterm2.com/), provides a safety net against accidentally quitting Hyper (a common problem outlined in [Hyper Issue #399](https://github.com/zeit/hyper/issues/399)). 9 | 10 | ![](.github/demo.gif) 11 | 12 | ## Installation 13 | 14 | ### Via [hpm](https://github.com/zeit/hpm) 15 | 16 | To install `hyper-confirm` via `hpm` (recommended), run the following command in your terminal: 17 | 18 | ``` 19 | hpm install hyper-confirm 20 | ``` 21 | 22 | ### Manually 23 | 24 | If you don't use `hpm`, add `hyper-confirm` to the `plugins` array in your Hyper config file (typically found at `~/.hyper.js`): 25 | 26 | ```javascript 27 | plugins: [ 28 | ... 29 | 'hyper-confirm' 30 | ] 31 | ``` 32 | 33 | ## Configuration 34 | 35 | As of [v1.0.0](https://github.com/zachflower/hyper-confirm/releases/tag/v1.0.0), the quit confirmation dialog is enabled by default. To disable it, add `confirmQuit: false` to the `config` object in your Hyper config file (typically found at `~/.hyper.js`): 36 | 37 | ```javascript 38 | module.exports = { 39 | config: { 40 | ... 41 | confirmQuit: false 42 | }, 43 | ... 44 | }; 45 | ``` 46 | 47 | ## Credits 48 | 49 | - [@albinekb](https://github.com/albinekb), who opened [this unmerged pull request](https://github.com/zeit/hyper/pull/403) that acted as the foundation for `hyper-confirm` 50 | 51 | 52 | ## License 53 | 54 | `hyper-confirm` is released under the [MIT License](LICENSE.md). 55 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const {dialog} = require('electron'); 2 | 3 | let confirmQuit = true; 4 | let beforeQuitHandler; 5 | 6 | const createBeforeQuitHandler = app => { 7 | let quitConfirmed = false; 8 | return event => { 9 | if (confirmQuit && !quitConfirmed && app.getWindows().size) { 10 | event.preventDefault(); 11 | dialog.showMessageBox({ 12 | type: 'question', 13 | buttons: ['OK', 'Cancel'], 14 | defaultId: 0, 15 | title: 'Quit Hyper?', 16 | message: 'Quit Hyper?', 17 | detail: 'All sessions will be closed.' 18 | }, index => { 19 | if (index === 0) { 20 | quitConfirmed = true; 21 | app.quit(); 22 | } 23 | }); 24 | } 25 | }; 26 | }; 27 | 28 | exports.decorateConfig = config => { 29 | if (typeof config.confirmQuit !== undefined) { 30 | confirmQuit = Boolean(config.confirmQuit); 31 | } 32 | 33 | return config; 34 | }; 35 | 36 | exports.onApp = app => { 37 | switch (process.platform) { 38 | case 'win32': 39 | // Windows confirmations happen in the middleware 40 | break; 41 | default: 42 | if (beforeQuitHandler) { 43 | app.off('before-quit', beforeQuitHandler); 44 | } 45 | 46 | beforeQuitHandler = createBeforeQuitHandler(app); 47 | app.on('before-quit', beforeQuitHandler); 48 | 49 | break; 50 | } 51 | }; 52 | 53 | exports.middleware = _ => next => action => { 54 | const {dialog, app} = require('electron').remote; 55 | 56 | let confirmQuit = true; 57 | 58 | if (typeof app.config.getConfig().confirmQuit !== undefined) { 59 | confirmQuit = Boolean(app.config.getConfig().confirmQuit); 60 | } 61 | 62 | switch (process.platform) { 63 | case 'win32': 64 | if (confirmQuit && action.type === 'UI_WINDOW_CLOSE') { 65 | dialog.showMessageBox({ 66 | type: 'question', 67 | buttons: ['OK', 'Cancel'], 68 | defaultId: 0, 69 | title: 'Quit Hyper?', 70 | message: 'Quit Hyper?', 71 | detail: 'All sessions will be closed.' 72 | }, index => { 73 | if (index === 0) { 74 | next(action); 75 | } 76 | }); 77 | 78 | return; 79 | } 80 | 81 | break; 82 | default: 83 | // No special middleware for non-windows operating systems 84 | break; 85 | } 86 | 87 | next(action); 88 | }; 89 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hyper-confirm", 3 | "version": "1.0.0", 4 | "description": "Show a confirmation dialog before quitting Hyper", 5 | "author": "Zachary Flower ", 6 | "contributors": [ 7 | { 8 | "name": "Zachary Flower", 9 | "email": "zach@flower.codes" 10 | } 11 | ], 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/zachflower/hyper-confirm.git" 15 | }, 16 | "bugs": { 17 | "url": "https://github.com/zachflower/hyper-confirm/issues" 18 | }, 19 | "homepage": "https://github.com/zachflower/hyper-confirm#readme", 20 | "keywords": [ 21 | "hyper.app", 22 | "hyper", 23 | "hyperterm", 24 | "plugin", 25 | "system", 26 | "confirm" 27 | ], 28 | "main": "index.js", 29 | "scripts": { 30 | "test": "xo" 31 | }, 32 | "license": "MIT", 33 | "devDependencies": { 34 | "xo": "^0.32.1" 35 | }, 36 | "xo": { 37 | "space": 2 38 | } 39 | } 40 | --------------------------------------------------------------------------------