electron: add missing APIs added in 1.4.5

This commit is contained in:
rhysd
2016-11-23 23:28:13 +09:00
parent e8d8a70438
commit 08fa9d6083
3 changed files with 60 additions and 15 deletions

View File

@@ -313,6 +313,8 @@ var window = new BrowserWindow();
window.setProgressBar(0.5);
window.setRepresentedFilename('/etc/passwd');
window.setDocumentEdited(true);
window.previewFile('/path/to/file');
window.previewFile('/path/to/file', 'Displayed Name');
// Online/Offline Event Detection
// https://github.com/atom/electron/blob/master/docs/tutorial/online-offline-events.md
@@ -869,20 +871,25 @@ app.on('ready', () => {
// clipboard
// https://github.com/atom/electron/blob/master/docs/api/clipboard.md
clipboard.writeText('Example String');
clipboard.writeText('Example String', 'selection');
clipboard.writeBookmark('foo', 'http://example.com');
clipboard.writeBookmark('foo', 'http://example.com', 'selection');
console.log(clipboard.readText('selection'));
console.log(clipboard.availableFormats());
console.log(clipboard.readBookmark().title);
clipboard.clear();
{
let str: string;
clipboard.writeText('Example String');
clipboard.writeText('Example String', 'selection');
clipboard.writeBookmark('foo', 'http://example.com');
clipboard.writeBookmark('foo', 'http://example.com', 'selection');
clipboard.writeFindText('foo');
str = clipboard.readText('selection');
str = clipboard.readFindText();
console.log(clipboard.availableFormats());
console.log(clipboard.readBookmark().title);
clipboard.clear();
clipboard.write({
html: '<html></html>',
text: 'Hello World!',
image: clipboard.readImage()
});
clipboard.write({
html: '<html></html>',
text: 'Hello World!',
image: clipboard.readImage()
});
}
// crash-reporter
// https://github.com/atom/electron/blob/master/docs/api/crash-reporter.md

View File

@@ -68,6 +68,10 @@ webFrame.setSpellCheckProvider('en-US', true, {
webFrame.registerURLSchemeAsSecure('app');
webFrame.registerURLSchemeAsBypassingCSP('app');
webFrame.registerURLSchemeAsPrivileged('app');
webFrame.registerURLSchemeAsPrivileged('app', {
secure: true,
supportFetchAPI: true,
});
webFrame.insertText('text');

38
electron/index.d.ts vendored
View File

@@ -1023,6 +1023,14 @@ declare namespace Electron {
* Note: This API is available only on macOS.
*/
setAspectRatio(aspectRatio: number, extraSize?: Size): void;
/**
* Uses Quick Look to preview a file at a given path.
*
* @param path The absolute path to the file to preview with QuickLook.
* @param displayName The name of the file to display on the Quick Look modal view.
* Note: This API is available only on macOS.
*/
previewFile(path: string, displayName?: string): void;
/**
* Resizes and moves the window to width, height, x, y.
*/
@@ -1861,6 +1869,20 @@ declare namespace Electron {
* Note: This API is available on macOS and Windows.
*/
writeBookmark(title: string, url: string, type?: ClipboardType): void;
/**
* The text on the find pasteboard. This method uses synchronous IPC when called from the renderer process.
* The cached value is reread from the find pasteboard whenever the application is activated.
*
* Note: This API is available on macOS.
*/
readFindText(): string;
/**
* Writes the text into the find pasteboard as plain text.
* This method uses synchronous IPC when called from the renderer process.
*
* Note: This API is available on macOS.
*/
writeFindText(text: string): void;
}
type ClipboardType = '' | 'selection';
@@ -5144,7 +5166,7 @@ declare namespace Electron {
* Registers the scheme as secure, bypasses content security policy for resources,
* allows registering ServiceWorker and supports fetch API.
*/
registerURLSchemeAsPrivileged(scheme: string): void;
registerURLSchemeAsPrivileged(scheme: string, options?: RegisterURLSchemeOptions): void;
/**
* Inserts text to the focused element.
*/
@@ -5184,6 +5206,14 @@ declare namespace Electron {
size: number;
}
interface RegisterURLSchemeOptions {
secure?: boolean;
bypassCSP?: boolean;
allowServiceWorkers?: boolean;
supportFetchAPI?: boolean;
corsEnabled?: boolean;
}
// https://github.com/electron/electron/blob/master/docs/api/web-view-tag.md
/**
@@ -5257,6 +5287,10 @@ declare namespace Electron {
* If "on", the guest page will be allowed to open new windows.
*/
allowpopups: string;
/**
* A list of strings which specifies the web preferences to be set on the webview, separated by ,.
*/
webpreferences: string;
/**
* A list of strings which specifies the blink features to be enabled separated by ,.
*/
@@ -5377,7 +5411,7 @@ declare namespace Electron {
closeDevTools(): void;
/**
* @returns Whether guest page has a DevTools window attached.
*/
isDevToolsOpened(): boolean;
/**
* @returns Whether DevTools window of guest page is focused.