Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript definition #68

Merged
merged 7 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {BrowserWindow} from 'electron';

export interface Options {
/**
* Default: [Only in development](https://github.com/sindresorhus/electron-is-dev)
*/
readonly enabled?: boolean;

/**
* Show DevTools on each created `BrowserWindow`.
*
* @default true
*/
readonly showDevTools?: boolean;

/**
* The dock state to open DevTools in.
*
* @default 'undocked'
*/
readonly devToolsMode?: 'undocked' | 'right' | 'bottom' | 'previous' | 'detach';
}

/**
* Install keyboard shortcuts and optionally activate DevTools on each created `BrowserWindow`.
*
* @example
*
* import {app, BrowserWindow} from 'electron';
* import electronDebug from 'electron-debug';
*
* electronDebug();
*
* let win;
* (async () => {
* await app.whenReady();
* win = new BrowserWindow();
* });
*/
export default function electronDebug(options?: Options): void;

/**
* Reload the specified `BrowserWindow` instance or the focused one.
*/
export function refresh(window?: BrowserWindow = BrowserWindow.getFocusedWindow()): void;

/**
* Toggle DevTools for the specified `BrowserWindow` instance or the focused one.
*/
export function devTools(window?: BrowserWindow = BrowserWindow.getFocusedWindow()): void;

/**
* Open DevTools for the specified `BrowserWindow` instance or the focused one.
*/
export function openDevTools(window?: BrowserWindow = BrowserWindow.getFocusedWindow()): void;
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ module.exports = opts => {
});
};

module.exports.default = module.exports;

module.exports.refresh = refresh;
module.exports.devTools = devTools;
module.exports.openDevTools = openDevTools;
12 changes: 12 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {expectType} from 'tsd-check';
import {BrowserWindow} from 'electron';
import electronDebug, {refresh, devTools, openDevTools} from '.';

expectType<void>(electronDebug({
enabled: true,
showDevTools: true
}));

expectType<void>(refresh(new BrowserWindow()));
expectType<void>(devTools());
expectType<void>(openDevTools());
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
},
"scripts": {
"start": "electron test.js",
"test": "xo"
"test": "xo && tsd-check"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"electron",
Expand All @@ -33,6 +34,7 @@
"devtron": "^1.1.0",
"electron": "^2.0.2",
"electron-react-devtools": "^0.5.3",
"tsd-check": "^0.3.0",
"xo": "*"
},
"xo": {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Show DevTools on each created `BrowserWindow`.

Type: `string`<br>
Default: `undocked`<br>
Values: `undocked` `right` `bottom` `previous`
Values: `undocked` `right` `bottom` `previous` `detach`

The dock state to open DevTools in.

Expand Down