mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
github-electron: Add 'electron' module for main process
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
/// <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 {
|
||||
app,
|
||||
autoUpdater,
|
||||
BrowserWindow,
|
||||
contentTracing,
|
||||
dialog,
|
||||
globalShortcut,
|
||||
ipcMain,
|
||||
Menu,
|
||||
MenuItem,
|
||||
powerMonitor,
|
||||
protocol,
|
||||
Tray,
|
||||
clipboard,
|
||||
crashReporter,
|
||||
nativeImage,
|
||||
screen,
|
||||
shell
|
||||
} from 'electron';
|
||||
|
||||
import path = require('path');
|
||||
|
||||
@@ -39,8 +41,8 @@ app.on('window-all-closed', () => {
|
||||
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
|
||||
// Someone tried to run a second instance, we should focus our window
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.focus();
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.focus();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
@@ -156,7 +158,7 @@ app.on('ready', () => {
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`);
|
||||
});
|
||||
|
||||
ipc.on('online-status-changed', (event: any, status: any) => {
|
||||
ipcMain.on('online-status-changed', (event: any, status: any) => {
|
||||
console.log(status);
|
||||
});
|
||||
|
||||
@@ -183,7 +185,7 @@ 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());
|
||||
autoUpdater.setFeedURL('http://mycompany.com/myapp/latest?version=' + app.getVersion());
|
||||
|
||||
// browser-window
|
||||
// https://github.com/atom/electron/blob/master/docs/api/browser-window.md
|
||||
@@ -199,11 +201,11 @@ win.show();
|
||||
// content-tracing
|
||||
// https://github.com/atom/electron/blob/master/docs/api/content-tracing.md
|
||||
|
||||
ContentTracing.startRecording('*', ContentTracing.DEFAULT_OPTIONS, () => {
|
||||
contentTracing.startRecording('*', contentTracing.DEFAULT_OPTIONS, () => {
|
||||
console.log('Tracing started');
|
||||
|
||||
setTimeout(() => {
|
||||
ContentTracing.stopRecording('', path => {
|
||||
contentTracing.stopRecording('', path => {
|
||||
console.log('Tracing data recorded to ' + path);
|
||||
});
|
||||
}, 5000);
|
||||
@@ -212,7 +214,7 @@ ContentTracing.startRecording('*', ContentTracing.DEFAULT_OPTIONS, () => {
|
||||
// dialog
|
||||
// https://github.com/atom/electron/blob/master/docs/api/dialog.md
|
||||
|
||||
console.log(Dialog.showOpenDialog({
|
||||
console.log(dialog.showOpenDialog({
|
||||
properties: ['openFile', 'openDirectory', 'multiSelections']
|
||||
}));
|
||||
|
||||
@@ -220,30 +222,30 @@ console.log(Dialog.showOpenDialog({
|
||||
// https://github.com/atom/electron/blob/master/docs/api/global-shortcut.md
|
||||
|
||||
// Register a 'ctrl+x' shortcut listener.
|
||||
var ret = GlobalShortcut.register('ctrl+x', () => {
|
||||
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'));
|
||||
console.log(globalShortcut.isRegistered('ctrl+x'));
|
||||
|
||||
// Unregister a shortcut.
|
||||
GlobalShortcut.unregister('ctrl+x');
|
||||
globalShortcut.unregister('ctrl+x');
|
||||
|
||||
// Unregister all shortcuts.
|
||||
GlobalShortcut.unregisterAll();
|
||||
globalShortcut.unregisterAll();
|
||||
|
||||
// ipc
|
||||
// ipcMain
|
||||
// https://github.com/atom/electron/blob/master/docs/api/ipc-main-process.md
|
||||
|
||||
ipc.on('asynchronous-message', (event: any, arg: any) => {
|
||||
ipcMain.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) => {
|
||||
ipcMain.on('synchronous-message', (event: any, arg: any) => {
|
||||
console.log(arg); // prints "ping"
|
||||
event.returnValue = 'pong';
|
||||
});
|
||||
@@ -405,7 +407,7 @@ Menu.buildFromTemplate([
|
||||
// https://github.com/atom/electron/blob/master/docs/api/power-monitor.md
|
||||
|
||||
app.on('ready', () => {
|
||||
PowerMonitor.on('suspend', () => {
|
||||
powerMonitor.on('suspend', () => {
|
||||
console.log('The system is going to sleep');
|
||||
});
|
||||
});
|
||||
@@ -414,9 +416,9 @@ app.on('ready', () => {
|
||||
// https://github.com/atom/electron/blob/master/docs/api/protocol.md
|
||||
|
||||
app.on('ready', () => {
|
||||
Protocol.registerProtocol('atom', (request: any) => {
|
||||
protocol.registerProtocol('atom', (request: any) => {
|
||||
var url = request.url.substr(7);
|
||||
return new Protocol.RequestFileJob(path.normalize(`${__dirname}/${url}`));
|
||||
return new protocol.RequestFileJob(path.normalize(`${__dirname}/${url}`));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -440,26 +442,26 @@ app.on('ready', () => {
|
||||
// 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'));
|
||||
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({
|
||||
crashReporter.start({
|
||||
productName: 'YourName',
|
||||
companyName: 'YourCompany',
|
||||
submitURL: 'https://your-domain.com/url-to-submit',
|
||||
autoSubmit: true
|
||||
});
|
||||
|
||||
// NativeImage
|
||||
// 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 image = clipboard.readImage();
|
||||
var appIcon3 = new Tray(image);
|
||||
var appIcon4 = new Tray('/Users/somebody/images/icon.png');
|
||||
|
||||
@@ -467,12 +469,12 @@ var appIcon4 = new Tray('/Users/somebody/images/icon.png');
|
||||
// https://github.com/atom/electron/blob/master/docs/api/screen.md
|
||||
|
||||
app.on('ready', () => {
|
||||
var size = Screen.getPrimaryDisplay().workAreaSize;
|
||||
var size = screen.getPrimaryDisplay().workAreaSize;
|
||||
mainWindow = new BrowserWindow({ width: size.width, height: size.height });
|
||||
});
|
||||
|
||||
app.on('ready', () => {
|
||||
var displays = Screen.getAllDisplays();
|
||||
var displays = screen.getAllDisplays();
|
||||
var externalDisplay: any = null;
|
||||
for (var i in displays) {
|
||||
if (displays[i].bounds.x > 0 || displays[i].bounds.y > 0) {
|
||||
@@ -492,4 +494,4 @@ app.on('ready', () => {
|
||||
// shell
|
||||
// https://github.com/atom/electron/blob/master/docs/api/shell.md
|
||||
|
||||
Shell.openExternal('https://github.com');
|
||||
shell.openExternal('https://github.com');
|
||||
|
||||
15
github-electron/github-electron-main.d.ts
vendored
15
github-electron/github-electron-main.d.ts
vendored
@@ -254,6 +254,21 @@ declare module 'tray' {
|
||||
export = Tray;
|
||||
}
|
||||
|
||||
declare module 'electron' {
|
||||
export var app: GitHubElectron.App;
|
||||
export var autoUpdater: GitHubElectron.AutoUpdater;
|
||||
export var BrowserWindow: typeof GitHubElectron.BrowserWindow;
|
||||
export var contentTracing: GitHubElectron.ContentTracing;
|
||||
export var dialog: GitHubElectron.Dialog;
|
||||
export var globalShortcut: GitHubElectron.GlobalShortcut;
|
||||
export var ipcMain: NodeJS.EventEmitter;
|
||||
export var Menu: typeof GitHubElectron.Menu;
|
||||
export var MenuItem: typeof GitHubElectron.MenuItem;
|
||||
export var powerMonitor: NodeJS.EventEmitter;
|
||||
export var protocol: GitHubElectron.Protocol;
|
||||
export var Tray: typeof GitHubElectron.Tray;
|
||||
}
|
||||
|
||||
interface NodeRequireFunction {
|
||||
(id: 'app'): GitHubElectron.App
|
||||
(id: 'auto-updater'): GitHubElectron.AutoUpdater
|
||||
|
||||
12
github-electron/github-electron.d.ts
vendored
12
github-electron/github-electron.d.ts
vendored
@@ -1407,12 +1407,12 @@ declare module GitHubElectron {
|
||||
}
|
||||
|
||||
declare module 'clipboard' {
|
||||
var clipboard: GitHubElectron.Clipboard
|
||||
var clipboard: GitHubElectron.Clipboard;
|
||||
export = clipboard;
|
||||
}
|
||||
|
||||
declare module 'crash-reporter' {
|
||||
var crashReporter: GitHubElectron.CrashReporter
|
||||
var crashReporter: GitHubElectron.CrashReporter;
|
||||
export = crashReporter;
|
||||
}
|
||||
|
||||
@@ -1431,6 +1431,14 @@ declare module 'shell' {
|
||||
export = shell;
|
||||
}
|
||||
|
||||
declare module 'electron' {
|
||||
export var clipboard: GitHubElectron.Clipboard;
|
||||
export var crashReporter: GitHubElectron.CrashReporter;
|
||||
export var nativeImage: GitHubElectron.NativeImage;
|
||||
export var screen: GitHubElectron.Screen;
|
||||
export var shell: GitHubElectron.Shell;
|
||||
}
|
||||
|
||||
interface Window {
|
||||
/**
|
||||
* Creates a new window.
|
||||
|
||||
Reference in New Issue
Block a user