-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
- Loading branch information
1 parent
a5983bb
commit 1c0eeab
Showing
3 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {BrowserWindow} from 'electron'; | ||
|
||
declare namespace electronServe { | ||
interface Options { | ||
/** | ||
The directory to serve, relative to the app root directory. | ||
*/ | ||
directory: string; | ||
|
||
/** | ||
Custom scheme. For example, `foo` results in your `directory` being available at `foo://-`. | ||
@default 'app' | ||
*/ | ||
scheme?: string; | ||
|
||
/** | ||
The partition the protocol should be installed to, if you're not using Electron's default partition. | ||
@default electron.session.defaultSession | ||
*/ | ||
partition?:string | ||
} | ||
|
||
interface loadURL { | ||
/** | ||
Load the index file in the window. | ||
*/ | ||
(window: BrowserWindow): Promise<void>; | ||
} | ||
} | ||
|
||
/** | ||
Static file serving for Electron apps. | ||
@example | ||
``` | ||
import {app, BrowserWindow} from 'electron'; | ||
import serve = require('electron-serve'); | ||
const loadURL = serve({directory: 'renderer'}); | ||
let mainWindow; | ||
(async () => { | ||
await app.whenReady(); | ||
mainWindow = new BrowserWindow(); | ||
await loadURL(mainWindow); | ||
// The above is equivalent to this: | ||
await mainWindow.loadURL('app://-'); | ||
// The `-` is just the required hostname. | ||
})(); | ||
``` | ||
*/ | ||
declare function electronServe(options: electronServe.Options): electronServe.loadURL; | ||
|
||
export = electronServe; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {expectType} from 'tsd-check'; | ||
import {BrowserWindow} from 'electron'; | ||
import serve = require('.'); | ||
|
||
expectType<serve.loadURL>(serve({directory: ''})); | ||
|
||
const loadURL = serve({directory: ''}); | ||
expectType<Promise<void>>(loadURL(new BrowserWindow())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters