mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Add Electron definitions
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
[*.ts]
|
||||
indent_style = tab
|
||||
@@ -0,0 +1,437 @@
|
||||
/// <reference path="./github-electron-main.d.ts" />
|
||||
import app = require('app');
|
||||
import AutoUpdater = require('auto-updater');
|
||||
import BrowserWindow = require('browser-window');
|
||||
import ContentTracing = require('content-tracing');
|
||||
import Dialog = require('dialog');
|
||||
import GlobalShortcut = require('global-shortcut');
|
||||
import ipc = require('ipc');
|
||||
import Menu = require('menu');
|
||||
import MenuItem = require('menu-item');
|
||||
import PowerMonitor = require('power-monitor');
|
||||
import Protocol = require('protocol');
|
||||
import Tray = require('tray');
|
||||
import Clipboard = require('clipboard');
|
||||
import CrashReporter = require('crash-reporter');
|
||||
import NativeImage = require('native-image');
|
||||
import Screen = require('screen');
|
||||
import Shell = require('shell');
|
||||
|
||||
import path = require('path');
|
||||
|
||||
// Quick start
|
||||
// https://github.com/atom/electron/blob/master/docs/tutorial/quick-start.md
|
||||
|
||||
// Report crashes to our server.
|
||||
require('crash-reporter').start();
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the javascript object is GCed.
|
||||
var mainWindow: GitHubElectron.BrowserWindow = null;
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin')
|
||||
app.quit();
|
||||
});
|
||||
|
||||
// This method will be called when Electron has done everything
|
||||
// initialization and ready for creating browser windows.
|
||||
app.on('ready', () => {
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({ width: 800, height: 600 });
|
||||
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadUrl(`file://${__dirname}/index.html`);
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', () => {
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null;
|
||||
});
|
||||
});
|
||||
|
||||
// Desktop environment integration
|
||||
// https://github.com/atom/electron/blob/master/docs/tutorial/desktop-environment-integration.md
|
||||
|
||||
app.addRecentDocument('/Users/USERNAME/Desktop/work.type');
|
||||
app.clearRecentDocuments();
|
||||
var dockMenu = Menu.buildFromTemplate([
|
||||
<GitHubElectron.MenuItemOptions>{
|
||||
label: 'New Window',
|
||||
click: () => {
|
||||
console.log('New Window');
|
||||
}
|
||||
},
|
||||
<GitHubElectron.MenuItemOptions>{
|
||||
label: 'New Window with Settings',
|
||||
submenu: [
|
||||
<GitHubElectron.MenuItemOptions>{ label: 'Basic' },
|
||||
<GitHubElectron.MenuItemOptions>{ label: 'Pro' }
|
||||
]
|
||||
},
|
||||
<GitHubElectron.MenuItemOptions>{ label: 'New Command...' }
|
||||
]);
|
||||
app.dock.setMenu(dockMenu);
|
||||
|
||||
app.setUserTasks([
|
||||
<GitHubElectron.Task>{
|
||||
program: process.execPath,
|
||||
arguments: '--new-window',
|
||||
iconPath: process.execPath,
|
||||
iconIndex: 0,
|
||||
title: 'New Window',
|
||||
description: 'Create a new window'
|
||||
}
|
||||
]);
|
||||
app.setUserTasks([]);
|
||||
|
||||
var window = new BrowserWindow();
|
||||
window.setProgressBar(0.5);
|
||||
window.setRepresentedFilename('/etc/passwd');
|
||||
window.setDocumentEdited(true);
|
||||
|
||||
// Online/Offline Event Detection
|
||||
// https://github.com/atom/electron/blob/master/docs/tutorial/online-offline-events.md
|
||||
|
||||
var onlineStatusWindow: GitHubElectron.BrowserWindow;
|
||||
|
||||
app.on('ready', () => {
|
||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false });
|
||||
onlineStatusWindow.loadUrl(`file://${__dirname}/online-status.html`);
|
||||
});
|
||||
|
||||
ipc.on('online-status-changed', (event: any, status: any) => {
|
||||
console.log(status);
|
||||
});
|
||||
|
||||
// Synopsis
|
||||
// https://github.com/atom/electron/blob/master/docs/api/synopsis.md
|
||||
|
||||
app.on('ready', () => {
|
||||
window = new BrowserWindow({ width: 800, height: 600 });
|
||||
window.loadUrl('https://github.com');
|
||||
});
|
||||
|
||||
// Supported Chrome command line switches
|
||||
// https://github.com/atom/electron/blob/master/docs/api/chrome-command-line-switches.md
|
||||
|
||||
app.commandLine.appendSwitch('remote-debugging-port', '8315');
|
||||
app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1');
|
||||
app.commandLine.appendSwitch('v', -1);
|
||||
app.commandLine.appendSwitch('vmodule', 'console=0');
|
||||
|
||||
// auto-updater
|
||||
// https://github.com/atom/electron/blob/master/docs/api/auto-updater.md
|
||||
|
||||
AutoUpdater.setFeedUrl('http://mycompany.com/myapp/latest?version=' + app.getVersion());
|
||||
|
||||
// browser-window
|
||||
// https://github.com/atom/electron/blob/master/docs/api/browser-window.md
|
||||
|
||||
var win = new BrowserWindow({ width: 800, height: 600, show: false });
|
||||
win.on('closed', () => {
|
||||
win = null;
|
||||
});
|
||||
|
||||
win.loadUrl('https://github.com');
|
||||
win.show();
|
||||
|
||||
// content-tracing
|
||||
// https://github.com/atom/electron/blob/master/docs/api/content-tracing.md
|
||||
|
||||
ContentTracing.startRecording('*', ContentTracing.DEFAULT_OPTIONS, () => {
|
||||
console.log('Tracing started');
|
||||
|
||||
setTimeout(() => {
|
||||
ContentTracing.stopRecording('', path => {
|
||||
console.log('Tracing data recorded to ' + path);
|
||||
});
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
// dialog
|
||||
// https://github.com/atom/electron/blob/master/docs/api/dialog.md
|
||||
|
||||
console.log(Dialog.showOpenDialog({
|
||||
properties: ['openFile', 'openDirectory', 'multiSelections']
|
||||
}));
|
||||
|
||||
// global-shortcut
|
||||
// https://github.com/atom/electron/blob/master/docs/api/global-shortcut.md
|
||||
|
||||
// Register a 'ctrl+x' shortcut listener.
|
||||
var ret = GlobalShortcut.register('ctrl+x', () => {
|
||||
console.log('ctrl+x is pressed');
|
||||
});
|
||||
if (!ret)
|
||||
console.log('registerion fails');
|
||||
|
||||
// Check whether a shortcut is registered.
|
||||
console.log(GlobalShortcut.isRegistered('ctrl+x'));
|
||||
|
||||
// Unregister a shortcut.
|
||||
GlobalShortcut.unregister('ctrl+x');
|
||||
|
||||
// Unregister all shortcuts.
|
||||
GlobalShortcut.unregisterAll();
|
||||
|
||||
// ipc
|
||||
// https://github.com/atom/electron/blob/master/docs/api/ipc-main-process.md
|
||||
|
||||
ipc.on('asynchronous-message', (event: any, arg: any) => {
|
||||
console.log(arg); // prints "ping"
|
||||
event.sender.send('asynchronous-reply', 'pong');
|
||||
});
|
||||
|
||||
ipc.on('synchronous-message', (event: any, arg: any) => {
|
||||
console.log(arg); // prints "ping"
|
||||
event.returnValue = 'pong';
|
||||
});
|
||||
|
||||
// menu
|
||||
// https://github.com/atom/electron/blob/master/docs/api/menu.md
|
||||
|
||||
var menu = new Menu();
|
||||
menu.append(new MenuItem({ label: 'MenuItem1', click: () => { console.log('item 1 clicked'); } }));
|
||||
menu.append(new MenuItem({ type: 'separator' }));
|
||||
menu.append(new MenuItem({ label: 'MenuItem2', type: 'checkbox', checked: true }));
|
||||
|
||||
// main.js
|
||||
var template = [
|
||||
{
|
||||
label: 'Electron',
|
||||
submenu: [
|
||||
{
|
||||
label: 'About Electron',
|
||||
selector: 'orderFrontStandardAboutPanel:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Services',
|
||||
submenu: <any[]>[]
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Hide Electron',
|
||||
accelerator: 'Command+H',
|
||||
selector: 'hide:'
|
||||
},
|
||||
{
|
||||
label: 'Hide Others',
|
||||
accelerator: 'Command+Shift+H',
|
||||
selector: 'hideOtherApplications:'
|
||||
},
|
||||
{
|
||||
label: 'Show All',
|
||||
selector: 'unhideAllApplications:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Quit',
|
||||
accelerator: 'Command+Q',
|
||||
click: () => { app.quit(); }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Undo',
|
||||
accelerator: 'Command+Z',
|
||||
selector: 'undo:'
|
||||
},
|
||||
{
|
||||
label: 'Redo',
|
||||
accelerator: 'Shift+Command+Z',
|
||||
selector: 'redo:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Cut',
|
||||
accelerator: 'Command+X',
|
||||
selector: 'cut:'
|
||||
},
|
||||
{
|
||||
label: 'Copy',
|
||||
accelerator: 'Command+C',
|
||||
selector: 'copy:'
|
||||
},
|
||||
{
|
||||
label: 'Paste',
|
||||
accelerator: 'Command+V',
|
||||
selector: 'paste:'
|
||||
},
|
||||
{
|
||||
label: 'Select All',
|
||||
accelerator: 'Command+A',
|
||||
selector: 'selectAll:'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'View',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Reload',
|
||||
accelerator: 'Command+R',
|
||||
click: () => { BrowserWindow.getFocusedWindow().reloadIgnoringCache(); }
|
||||
},
|
||||
{
|
||||
label: 'Toggle DevTools',
|
||||
accelerator: 'Alt+Command+I',
|
||||
click: () => { BrowserWindow.getFocusedWindow().toggleDevTools(); }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Window',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Minimize',
|
||||
accelerator: 'Command+M',
|
||||
selector: 'performMiniaturize:'
|
||||
},
|
||||
{
|
||||
label: 'Close',
|
||||
accelerator: 'Command+W',
|
||||
selector: 'performClose:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Bring All to Front',
|
||||
selector: 'arrangeInFront:'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Help',
|
||||
submenu: []
|
||||
}
|
||||
];
|
||||
|
||||
menu = Menu.buildFromTemplate(template);
|
||||
|
||||
Menu.setApplicationMenu(menu); // Must be called within app.on('ready', function(){ ... });
|
||||
|
||||
Menu.buildFromTemplate([
|
||||
{ label: '4', id: '4' },
|
||||
{ label: '5', id: '5' },
|
||||
{ label: '1', id: '1', position: 'before=4' },
|
||||
{ label: '2', id: '2' },
|
||||
{ label: '3', id: '3' }
|
||||
]);
|
||||
|
||||
Menu.buildFromTemplate([
|
||||
{ label: 'a', position: 'endof=letters' },
|
||||
{ label: '1', position: 'endof=numbers' },
|
||||
{ label: 'b', position: 'endof=letters' },
|
||||
{ label: '2', position: 'endof=numbers' },
|
||||
{ label: 'c', position: 'endof=letters' },
|
||||
{ label: '3', position: 'endof=numbers' }
|
||||
]);
|
||||
|
||||
// power-monitor
|
||||
// https://github.com/atom/electron/blob/master/docs/api/power-monitor.md
|
||||
|
||||
app.on('ready', () => {
|
||||
PowerMonitor.on('suspend', () => {
|
||||
console.log('The system is going to sleep');
|
||||
});
|
||||
});
|
||||
|
||||
// protocol
|
||||
// https://github.com/atom/electron/blob/master/docs/api/protocol.md
|
||||
|
||||
app.on('ready', () => {
|
||||
Protocol.registerProtocol('atom', (request: any) => {
|
||||
var url = request.url.substr(7);
|
||||
return new Protocol.RequestFileJob(path.normalize(`${__dirname}/${url}`));
|
||||
});
|
||||
});
|
||||
|
||||
// tray
|
||||
// https://github.com/atom/electron/blob/master/docs/api/tray.md
|
||||
|
||||
var appIcon: GitHubElectron.Tray = null;
|
||||
app.on('ready', () => {
|
||||
appIcon = new Tray('/path/to/my/icon');
|
||||
var contextMenu = Menu.buildFromTemplate([
|
||||
{ label: 'Item1', type: 'radio' },
|
||||
{ label: 'Item2', type: 'radio' },
|
||||
{ label: 'Item3', type: 'radio', checked: true },
|
||||
{ label: 'Item4', type: 'radio' },
|
||||
]);
|
||||
appIcon.setToolTip('This is my application.');
|
||||
appIcon.setContextMenu(contextMenu);
|
||||
});
|
||||
|
||||
// clipboard
|
||||
// https://github.com/atom/electron/blob/master/docs/api/clipboard.md
|
||||
|
||||
Clipboard.writeText('Example String');
|
||||
Clipboard.writeText('Example String', 'selection');
|
||||
console.log(Clipboard.readText('selection'));
|
||||
|
||||
// crash-reporter
|
||||
// https://github.com/atom/electron/blob/master/docs/api/crash-reporter.md
|
||||
|
||||
CrashReporter.start({
|
||||
productName: 'YourName',
|
||||
companyName: 'YourCompany',
|
||||
submitUrl: 'https://your-domain.com/url-to-submit',
|
||||
autoSubmit: true
|
||||
});
|
||||
|
||||
// NativeImage
|
||||
// https://github.com/atom/electron/blob/master/docs/api/native-image.md
|
||||
|
||||
var appIcon2 = new Tray('/Users/somebody/images/icon.png');
|
||||
var window2 = new BrowserWindow({ icon: '/Users/somebody/images/window.png' });
|
||||
var image = Clipboard.readImage();
|
||||
var appIcon3 = new Tray(image);
|
||||
var appIcon4 = new Tray('/Users/somebody/images/icon.png');
|
||||
|
||||
// screen
|
||||
// https://github.com/atom/electron/blob/master/docs/api/screen.md
|
||||
|
||||
app.on('ready', () => {
|
||||
var size = Screen.getPrimaryDisplay().workAreaSize;
|
||||
mainWindow = new BrowserWindow({ width: size.width, height: size.height });
|
||||
});
|
||||
|
||||
app.on('ready', () => {
|
||||
var displays = Screen.getAllDisplays();
|
||||
var externalDisplay: any = null;
|
||||
for (var i in displays) {
|
||||
if (displays[i].bounds.x > 0 || displays[i].bounds.y > 0) {
|
||||
externalDisplay = displays[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (externalDisplay) {
|
||||
mainWindow = new BrowserWindow({
|
||||
x: externalDisplay.bounds.x + 50,
|
||||
y: externalDisplay.bounds.y + 50,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// shell
|
||||
// https://github.com/atom/electron/blob/master/docs/api/shell.md
|
||||
|
||||
Shell.openExternal('https://github.com');
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
// Type definitions for the Electron 0.25.2 main process
|
||||
// Project: http://electron.atom.io/
|
||||
// Definitions by: jedmao <https://github.com/jedmao/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="./github-electron.d.ts" />
|
||||
|
||||
declare module 'app' {
|
||||
var _app: GitHubElectron.App;
|
||||
export = _app;
|
||||
}
|
||||
|
||||
declare module 'auto-updater' {
|
||||
var _autoUpdater: GitHubElectron.AutoUpdater;
|
||||
export = _autoUpdater;
|
||||
}
|
||||
|
||||
declare module 'browser-window' {
|
||||
var BrowserWindow: typeof GitHubElectron.BrowserWindow;
|
||||
export = BrowserWindow;
|
||||
}
|
||||
|
||||
declare module 'content-tracing' {
|
||||
/**
|
||||
* Get a set of category groups. The category groups can change as new code paths are reached.
|
||||
* @param callback Called once all child processes have acked to the getCategories request.
|
||||
*/
|
||||
export function getCategories(callback: (categoryGroups: any[]) => void): void;
|
||||
/**
|
||||
* Start recording on all processes. Recording begins immediately locally, and asynchronously
|
||||
* on child processes as soon as they receive the EnableRecording request.
|
||||
* @param categoryFilter A filter to control what category groups should be traced.
|
||||
* A filter can have an optional "-" prefix to exclude category groups that contain
|
||||
* a matching category. Having both included and excluded category patterns in the
|
||||
* same list would not be supported.
|
||||
* @param options controls what kind of tracing is enabled, it could be a OR-ed
|
||||
* combination of tracing.DEFAULT_OPTIONS, tracing.ENABLE_SYSTRACE, tracing.ENABLE_SAMPLING
|
||||
* and tracing.RECORD_CONTINUOUSLY.
|
||||
* @param callback Called once all child processes have acked to the startRecording request.
|
||||
*/
|
||||
export function startRecording(categoryFilter: string, options: number, callback: Function): void;
|
||||
/**
|
||||
* Stop recording on all processes. Child processes typically are caching trace data and
|
||||
* only rarely flush and send trace data back to the main process. That is because it may
|
||||
* be an expensive operation to send the trace data over IPC, and we would like to avoid
|
||||
* much runtime overhead of tracing. So, to end tracing, we must asynchronously ask all
|
||||
* child processes to flush any pending trace data.
|
||||
* @param resultFilePath Trace data will be written into this file if it is not empty,
|
||||
* or into a temporary file.
|
||||
* @param callback Called once all child processes have acked to the stopRecording request.
|
||||
*/
|
||||
export function stopRecording(resultFilePath: string, callback:
|
||||
/**
|
||||
* @param filePath A file that contains the traced data.
|
||||
*/
|
||||
(filePath: string) => void
|
||||
): void;
|
||||
/**
|
||||
* Start monitoring on all processes. Monitoring begins immediately locally, and asynchronously
|
||||
* on child processes as soon as they receive the startMonitoring request.
|
||||
* @param callback Called once all child processes have acked to the startMonitoring request.
|
||||
*/
|
||||
export function startMonitoring(categoryFilter: string, options: number, callback: Function): void;
|
||||
/**
|
||||
* Stop monitoring on all processes.
|
||||
* @param callback Called once all child processes have acked to the stopMonitoring request.
|
||||
*/
|
||||
export function stopMonitoring(callback: Function): void;
|
||||
/**
|
||||
* Get the current monitoring traced data. Child processes typically are caching trace data
|
||||
* and only rarely flush and send trace data back to the main process. That is because it may
|
||||
* be an expensive operation to send the trace data over IPC, and we would like to avoid much
|
||||
* runtime overhead of tracing. So, to end tracing, we must asynchronously ask all child
|
||||
* processes to flush any pending trace data.
|
||||
* @param callback Called once all child processes have acked to the captureMonitoringSnapshot request.
|
||||
*/
|
||||
export function captureMonitoringSnapshot(resultFilePath: string, callback:
|
||||
/**
|
||||
* @param filePath A file that contains the traced data
|
||||
* @returns {}
|
||||
*/
|
||||
(filePath: string) => void
|
||||
): void;
|
||||
/**
|
||||
* Get the maximum across processes of trace buffer percent full state.
|
||||
* @param callback Called when the TraceBufferUsage value is determined.
|
||||
*/
|
||||
export function getTraceBufferUsage(callback: Function): void;
|
||||
/**
|
||||
* @param callback Called every time the given event occurs on any process.
|
||||
*/
|
||||
export function setWatchEvent(categoryName: string, eventName: string, callback: Function): void;
|
||||
/**
|
||||
* Cancel the watch event. If tracing is enabled, this may race with the watch event callback.
|
||||
*/
|
||||
export function cancelWatchEvent(): void;
|
||||
export var DEFAULT_OPTIONS: number;
|
||||
export var ENABLE_SYSTRACE: number;
|
||||
export var ENABLE_SAMPLING: number;
|
||||
export var RECORD_CONTINUOUSLY: number;
|
||||
}
|
||||
|
||||
declare module 'dialog' {
|
||||
/**
|
||||
* @param callback If supplied, the API call will be asynchronous.
|
||||
* @returns On success, returns an array of file paths chosen by the user,
|
||||
* otherwise returns undefined.
|
||||
*/
|
||||
export var showOpenDialog: typeof GitHubElectron.Dialog.showOpenDialog;
|
||||
/**
|
||||
* @param callback If supplied, the API call will be asynchronous.
|
||||
* @returns On success, returns the path of file chosen by the user, otherwise
|
||||
* returns undefined.
|
||||
*/
|
||||
export var showSaveDialog: typeof GitHubElectron.Dialog.showSaveDialog;
|
||||
/**
|
||||
* Shows a message box. It will block until the message box is closed. It returns .
|
||||
* @param callback If supplied, the API call will be asynchronous.
|
||||
* @returns The index of the clicked button.
|
||||
*/
|
||||
export var showMessageBox: typeof GitHubElectron.Dialog.showMessageBox;
|
||||
|
||||
/**
|
||||
* Runs a modal dialog that shows an error message. This API can be called safely
|
||||
* before the ready event of app module emits, it is usually used to report errors
|
||||
* in early stage of startup.
|
||||
*/
|
||||
export function showErrorBox(title: string, content: string): void;
|
||||
}
|
||||
|
||||
declare module 'global-shortcut' {
|
||||
/**
|
||||
* Registers a global shortcut of accelerator.
|
||||
* @param accelerator Represents a keyboard shortcut. It can contain modifiers
|
||||
* and key codes, combined by the "+" character.
|
||||
* @param callback Called when the registered shortcut is pressed by the user.
|
||||
* @returns {}
|
||||
*/
|
||||
export function register(accelerator: string, callback: Function): void;
|
||||
/**
|
||||
* @param accelerator Represents a keyboard shortcut. It can contain modifiers
|
||||
* and key codes, combined by the "+" character.
|
||||
* @returns Whether the accelerator is registered.
|
||||
*/
|
||||
export function isRegistered(accelerator: string): boolean;
|
||||
/**
|
||||
* Unregisters the global shortcut of keycode.
|
||||
* @param accelerator Represents a keyboard shortcut. It can contain modifiers
|
||||
* and key codes, combined by the "+" character.
|
||||
*/
|
||||
export function unregister(accelerator: string): void;
|
||||
/**
|
||||
* Unregisters all the global shortcuts.
|
||||
*/
|
||||
export function unregisterAll(): void;
|
||||
}
|
||||
|
||||
declare module 'ipc' {
|
||||
var ipc: NodeJS.EventEmitter;
|
||||
export = ipc;
|
||||
}
|
||||
|
||||
declare module 'menu' {
|
||||
var Menu: typeof GitHubElectron.Menu;
|
||||
export = Menu;
|
||||
}
|
||||
|
||||
declare module 'menu-item' {
|
||||
var MenuItem: typeof GitHubElectron.MenuItem;
|
||||
export = MenuItem;
|
||||
}
|
||||
|
||||
declare module 'power-monitor' {
|
||||
var powerMonitor: NodeJS.EventEmitter;
|
||||
export = powerMonitor;
|
||||
}
|
||||
|
||||
declare module 'protocol' {
|
||||
export function registerProtocol(scheme: string, handler: (request: any) => void): void;
|
||||
export function unregisterProtocol(scheme: string): void;
|
||||
export function isHandledProtocol(scheme: string): boolean;
|
||||
export function interceptProtocol(scheme: string, handler: (request: any) => void): void;
|
||||
export function uninterceptProtocol(scheme: string): void;
|
||||
export class RequestFileJob {
|
||||
/**
|
||||
* Create a request job which would query a file of path and set corresponding mime types.
|
||||
*/
|
||||
constructor(path: string);
|
||||
}
|
||||
export class RequestStringJob {
|
||||
/**
|
||||
* Create a request job which sends a string as response.
|
||||
*/
|
||||
constructor(options?: {
|
||||
/**
|
||||
* Default is "text/plain".
|
||||
*/
|
||||
mimeType?: string;
|
||||
/**
|
||||
* Default is "UTF-8".
|
||||
*/
|
||||
charset?: string;
|
||||
data?: string;
|
||||
});
|
||||
}
|
||||
export class RequestBufferJob {
|
||||
/**
|
||||
* Create a request job which accepts a buffer and sends a string as response.
|
||||
*/
|
||||
constructor(options?: {
|
||||
/**
|
||||
* Default is "application/octet-stream".
|
||||
*/
|
||||
mimeType?: string;
|
||||
/**
|
||||
* Default is "UTF-8".
|
||||
*/
|
||||
encoding?: string;
|
||||
data?: Buffer;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'tray' {
|
||||
var Tray: typeof GitHubElectron.Tray;
|
||||
export = Tray;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/// <reference path="./github-electron-renderer.d.ts" />
|
||||
import ipc = require('ipc');
|
||||
import remote = require('remote');
|
||||
import WebFrame = require('web-frame');
|
||||
import Clipboard = require('clipboard');
|
||||
import CrashReporter = require('crash-reporter');
|
||||
import NativeImage = require('native-image');
|
||||
import Screen = require('screen');
|
||||
import Shell = require('shell');
|
||||
|
||||
import fs = require('fs');
|
||||
|
||||
// In renderer process (web page).
|
||||
// https://github.com/atom/electron/blob/master/docs/api/ipc-renderer.md
|
||||
console.log(ipc.sendSync('synchronous-message', 'ping')); // prints "pong"
|
||||
|
||||
ipc.on('asynchronous-reply', (arg: any) => {
|
||||
console.log(arg); // prints "pong"
|
||||
});
|
||||
ipc.send('asynchronous-message', 'ping');
|
||||
|
||||
// remote
|
||||
// https://github.com/atom/electron/blob/master/docs/api/remote.md
|
||||
|
||||
var BrowserWindow: typeof GitHubElectron.BrowserWindow = remote.require('browser-window');
|
||||
var win = new BrowserWindow({ width: 800, height: 600 });
|
||||
win.loadUrl('https://github.com');
|
||||
|
||||
remote.getCurrentWindow().on('close', () => {
|
||||
// blabla...
|
||||
});
|
||||
|
||||
remote.getCurrentWindow().capturePage(buf => {
|
||||
fs.writeFile('/tmp/screenshot.png', buf, err => {
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
|
||||
remote.getCurrentWindow().capturePage(buf => {
|
||||
remote.require('fs').writeFile('/tmp/screenshot.png', buf, (err: Error) => {
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
|
||||
// web-frame
|
||||
// https://github.com/atom/electron/blob/master/docs/api/web-frame.md
|
||||
|
||||
WebFrame.setZoomFactor(2);
|
||||
|
||||
WebFrame.setSpellCheckProvider('en-US', true, {
|
||||
spellCheck: text => {
|
||||
return !(require('spellchecker').isMisspelled(text));
|
||||
}
|
||||
});
|
||||
|
||||
// clipboard
|
||||
// https://github.com/atom/electron/blob/master/docs/api/clipboard.md
|
||||
|
||||
Clipboard.writeText('Example String');
|
||||
Clipboard.writeText('Example String', 'selection');
|
||||
console.log(Clipboard.readText('selection'));
|
||||
|
||||
// crash-reporter
|
||||
// https://github.com/atom/electron/blob/master/docs/api/crash-reporter.md
|
||||
|
||||
CrashReporter.start({
|
||||
productName: 'YourName',
|
||||
companyName: 'YourCompany',
|
||||
submitUrl: 'https://your-domain.com/url-to-submit',
|
||||
autoSubmit: true
|
||||
});
|
||||
|
||||
// NativeImage
|
||||
// https://github.com/atom/electron/blob/master/docs/api/native-image.md
|
||||
|
||||
var Tray: typeof GitHubElectron.Tray = remote.require('Tray');
|
||||
var appIcon2 = new Tray('/Users/somebody/images/icon.png');
|
||||
var window2 = new BrowserWindow({ icon: '/Users/somebody/images/window.png' });
|
||||
var image = Clipboard.readImage();
|
||||
var appIcon3 = new Tray(image);
|
||||
var appIcon4 = new Tray('/Users/somebody/images/icon.png');
|
||||
|
||||
// screen
|
||||
// https://github.com/atom/electron/blob/master/docs/api/screen.md
|
||||
|
||||
var app: GitHubElectron.App = remote.require('app');
|
||||
|
||||
var mainWindow: GitHubElectron.BrowserWindow = null;
|
||||
|
||||
app.on('ready', () => {
|
||||
var size = Screen.getPrimaryDisplay().workAreaSize;
|
||||
mainWindow = new BrowserWindow({ width: size.width, height: size.height });
|
||||
});
|
||||
|
||||
app.on('ready', () => {
|
||||
var displays = Screen.getAllDisplays();
|
||||
var externalDisplay: any = null;
|
||||
for (var i in displays) {
|
||||
if (displays[i].bounds.x > 0 || displays[i].bounds.y > 0) {
|
||||
externalDisplay = displays[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (externalDisplay) {
|
||||
mainWindow = new BrowserWindow({
|
||||
x: externalDisplay.bounds.x + 50,
|
||||
y: externalDisplay.bounds.y + 50,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// shell
|
||||
// https://github.com/atom/electron/blob/master/docs/api/shell.md
|
||||
|
||||
Shell.openExternal('https://github.com');
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
// Type definitions for the Electron 0.25.2 renderer process (web page)
|
||||
// Project: http://electron.atom.io/
|
||||
// Definitions by: jedmao <https://github.com/jedmao/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="./github-electron.d.ts" />
|
||||
|
||||
declare module GitHubElectron {
|
||||
|
||||
class InProcess implements NodeJS.EventEmitter {
|
||||
addListener(event: string, listener: Function): InProcess;
|
||||
on(event: string, listener: Function): InProcess;
|
||||
once(event: string, listener: Function): InProcess;
|
||||
removeListener(event: string, listener: Function): InProcess;
|
||||
removeAllListeners(event?: string): InProcess;
|
||||
setMaxListeners(n: number): void;
|
||||
listeners(event: string): Function[];
|
||||
emit(event: string, ...args: any[]): boolean;
|
||||
/**
|
||||
* Send ...args to the renderer via channel in asynchronous message, the main
|
||||
* process can handle it by listening to the channel event of ipc module.
|
||||
*/
|
||||
send(channel: string, ...args: any[]): void;
|
||||
/**
|
||||
* Send ...args to the renderer via channel in synchronous message, and returns
|
||||
* the result sent from main process. The main process can handle it by listening
|
||||
* to the channel event of ipc module, and returns by setting event.returnValue.
|
||||
* Note: Usually developers should never use this API, since sending synchronous
|
||||
* message would block the whole renderer process.
|
||||
* @returns The result sent from the main process.
|
||||
*/
|
||||
sendSync(channel: string, ...args: any[]): string;
|
||||
/**
|
||||
* Like ipc.send but the message will be sent to the host page instead of the main process.
|
||||
* This is mainly used by the page in <webview> to communicate with host page.
|
||||
*/
|
||||
sendToHost(channel: string, ...args: any[]): void;
|
||||
}
|
||||
|
||||
module Remote {
|
||||
export function getCurrentWindow(): BrowserWindow;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'ipc' {
|
||||
var InProcess: GitHubElectron.InProcess;
|
||||
export = InProcess;
|
||||
}
|
||||
|
||||
declare module 'remote' {
|
||||
/**
|
||||
* @returns The object returned by require(module) in the main process.
|
||||
*/
|
||||
export function require(module: string): any;
|
||||
/**
|
||||
* @returns The BrowserWindow object which this web page belongs to.
|
||||
*/
|
||||
export var getCurrentWindow: typeof GitHubElectron.Remote.getCurrentWindow;
|
||||
/**
|
||||
* @returns The global variable of name (e.g. global[name]) in the main process.
|
||||
*/
|
||||
export function getGlobal(name: string): any;
|
||||
/**
|
||||
* Returns the process object in the main process. This is the same as
|
||||
* remote.getGlobal('process'), but gets cached.
|
||||
*/
|
||||
export var process: any;
|
||||
}
|
||||
|
||||
declare module 'web-frame' {
|
||||
/**
|
||||
* Changes the zoom factor to the specified factor, zoom factor is
|
||||
* zoom percent / 100, so 300% = 3.0.
|
||||
*/
|
||||
export function setZoomFactor(factor: number): void;
|
||||
/**
|
||||
* @returns The current zoom factor.
|
||||
*/
|
||||
export function getZoomFactor(): number;
|
||||
/**
|
||||
* Changes the zoom level to the specified level, 0 is "original size", and each
|
||||
* increment above or below represents zooming 20% larger or smaller to default
|
||||
* limits of 300% and 50% of original size, respectively.
|
||||
*/
|
||||
export function setZoomLevel(level: number): void;
|
||||
/**
|
||||
* @returns The current zoom level.
|
||||
*/
|
||||
export function getZoomLevel(): number;
|
||||
/**
|
||||
* Sets a provider for spell checking in input fields and text areas.
|
||||
*/
|
||||
export function setSpellCheckProvider(language: string, autoCorrectWord: boolean, provider: {
|
||||
/**
|
||||
* @returns Whether the word passed is correctly spelled.
|
||||
*/
|
||||
spellCheck: (text: string) => boolean;
|
||||
}): void;
|
||||
/**
|
||||
* Sets the scheme as secure scheme. Secure schemes do not trigger mixed content
|
||||
* warnings. For example, https and data are secure schemes because they cannot be
|
||||
* corrupted by active network attackers.
|
||||
*/
|
||||
export function registerUrlSchemeAsSecure(scheme: string): void;
|
||||
}
|
||||
Vendored
+1295
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user