本文整理汇总了TypeScript中electron.ipcRenderer.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ipcRenderer.on方法的具体用法?TypeScript ipcRenderer.on怎么用?TypeScript ipcRenderer.on使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.ipcRenderer
的用法示例。
在下文中一共展示了ipcRenderer.on方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: AutomatedSingleSignOn
const subscribeToMainProcessEvents = () => {
ipcRenderer.on(EVENT_TYPE.ACCOUNT.SSO_LOGIN, (event: IpcMessageEvent, code: string) =>
new AutomatedSingleSignOn().start(code)
);
ipcRenderer.on(EVENT_TYPE.UI.SYSTEM_MENU, (event: IpcMessageEvent, action: string) => {
const selectedWebview = getSelectedWebview();
if (selectedWebview) {
selectedWebview.send(action);
}
});
ipcRenderer.on(EVENT_TYPE.WEBAPP.CHANGE_LOCATION_HASH, (event: IpcMessageEvent, hash: string) => {
const selectedWebview = getSelectedWebview();
if (selectedWebview) {
selectedWebview.send(EVENT_TYPE.WEBAPP.CHANGE_LOCATION_HASH, hash);
}
});
ipcRenderer.on(
EVENT_TYPE.WRAPPER.RELOAD,
(): void => {
const webviews = document.querySelectorAll<WebviewTag>('webview');
webviews.forEach(webview => webview.reload());
}
);
};
示例2: startup
export function startup(data: ProcessExplorerData): void {
applyStyles(data.styles);
applyZoom(data.zoomLevel);
// Map window process pids to titles, annotate process names with this when rendering to distinguish between them
ipcRenderer.on('vscode:windowsInfoResponse', (_event: unknown, windows: any[]) => {
mapPidToWindowTitle = new Map<number, string>();
windows.forEach(window => mapPidToWindowTitle.set(window.pid, window.title));
});
ipcRenderer.on('vscode:listProcessesResponse', (_event: Event, processRoots: [{ name: string, rootProcess: ProcessItem | IRemoteDiagnosticError }]) => {
updateProcessInfo(processRoots);
requestProcessList(0);
});
lastRequestTime = Date.now();
ipcRenderer.send('windowsInfoRequest');
ipcRenderer.send('vscode:listProcesses');
document.onkeydown = (e: KeyboardEvent) => {
const cmdOrCtrlKey = platform.isMacintosh ? e.metaKey : e.ctrlKey;
// Cmd/Ctrl + zooms in
if (cmdOrCtrlKey && e.keyCode === 187) {
applyZoom(webFrame.getZoomLevel() + 1);
}
// Cmd/Ctrl - zooms out
if (cmdOrCtrlKey && e.keyCode === 189) {
applyZoom(webFrame.getZoomLevel() - 1);
}
};
}
示例3: runAutoUpdaterService
export const runServices = () => {
ipcRenderer.on(
FULLSCREEN,
(e: Electron.IpcMessageEvent, isFullscreen: boolean) => {
store.isFullscreen = isFullscreen;
},
);
ipcRenderer.on(
'get-tab-by-web-contents-id',
(e: any, webContentsId: number) => {
let sent = false;
for (const page of store.pagesStore.pages) {
if (
page.webview.getWebContents() &&
page.webview.getWebContents().id === webContentsId
) {
const tab = store.tabsStore.getTabById(page.id).getApiTab();
ipcRenderer.send('get-tab-by-web-contents-id', tab);
sent = true;
break;
}
}
if (!sent) {
ipcRenderer.send('get-tab-by-web-contents-id', {});
}
},
);
runAutoUpdaterService();
runExtensionsService();
};
示例4: createTweetMessage
window.onload = () => {
const tweetButtonElement = document.getElementById('tweet-button')
const trackNameElement = document.getElementById('track-name')
const artworkImageElement = document.getElementById('artwork')
ipcRenderer.on('twitter-auth-reply', (event, arg) => {
ipcRenderer.send('itunes-get-track')
})
ipcRenderer.on('itunes-get-track-reply', (event, arg) => {
nowPlayingTrack = arg as NowPlayingTrack
console.log('get track success')
console.log(nowPlayingTrack)
trackNameElement.innerHTML = createTweetMessage(nowPlayingTrack)
artworkImageElement.style.backgroundImage = `url(${fileUrl(nowPlayingTrack.artworkPath)})`
})
tweetButtonElement.addEventListener('click', () => {
if (!nowPlayingTrack) {
console.log('nowplaying track not found')
return
}
const tweet: NowPlayingTweet = {
message: createTweetMessage(nowPlayingTrack),
artworkPath: nowPlayingTrack.artworkPath,
}
ipcRenderer.send('twitter-post', tweet)
})
// first, twitter auth
ipcRenderer.send('twitter-auth')
}
示例5: setup
/**
* @brief Initialize image import events.
*/
private setup() : void {
const eventName: string = IPCEventType[IPCEventType.OpenDialogLoadImage] ;
const eventSuccess: string = eventName + EventSuffix.Success ;
const eventFail: string = eventName + EventSuffix.Fail ;
var self: ImageImportHandler = this ;
// On success, send data to controller before displaying it in view.
IPCRenderer.on(eventSuccess, function(
event,
parentNodeKey: string,
hashes: string[],
files: string[],
basenames: string[]
) {
hashes.forEach(
function(
hash: string,
index: number,
array: string[]
) {
self.sendImportImageEvent(
parentNodeKey,
basenames[index],
hash,
files[index]
) ;
}) ;
}) ;
// On fail, abort import.
IPCRenderer.on(eventFail, function() {}) ;
}
示例6: init
export function init() {
ipcRenderer.on('executeForegroundAction', (event, callId, action, params) => {
executeForegroundAction(action, params)
.then(result => {
ipcRenderer.send('onForegroundActionDone', callId, null, result)
},
error => {
const msg = (error instanceof Error) ? error.message : error
ipcRenderer.send('onForegroundActionDone', callId, msg, null)
})
})
ipcRenderer.on('start-import', () => store.dispatch(startImportAction()))
ipcRenderer.on('progress', (event, progress: ImportProgress) => store.dispatch(setImportProgressAction(progress)))
ipcRenderer.on('finish-import', () => {
fetchTotalPhotoCount()
fetchSections()
fetchDates()
fetchTags()
})
ipcRenderer.on('new-version', (event, version: any /* Type should be `Version`, but it doesn't work */) => updatePhotoVersion(version))
ipcRenderer.on('scanned-devices', (event, devices: Device[]) => store.dispatch(initDevicesAction(devices)))
ipcRenderer.on('add-device', (event, device: Device) => store.dispatch(addDeviceAction(device)))
ipcRenderer.on('remove-device', (event, device: Device) => store.dispatch(removeDeviceAction(device)))
ipcRenderer.on('photos-trashed', (event, photoIds: PhotoId[]) => store.dispatch(emptyTrashAction(photoIds)))
}
示例7: initIPC
function initIPC() {
ipcRenderer.on('openFile', (e, path) => {
readFile(path, 'utf-8', (err, context) => {
filePath = path;
session.setValue(context);
updateTitle();
});
});
ipcRenderer.on('saveFile', (e, path) => {
filePath = path;
saveFile();
});
}
示例8: dispatchContext
dispatchContext().then(ctx => {
const keymaps = receivedKeymaps.then(k => {
const handlers = new KeymapsHandler(k, ctx);
handlers.subscribeKeydown();
console.log('Tui: Now handling keymaps:', handlers);
return handlers;
});
Promise.all([pluginPaths, keymaps])
.then(([paths, handlers]) => PluginManager.create(paths, ctx, handlers))
.then(manager => {
console.log('Tui: Plugin manager created:', manager);
console.log('Tui: Application launched. Memory(KB):', process.getProcessMemoryInfo());
});
keymaps.then(k => {
ipc.on('tuitter:new-tweet', () => {
console.log('Tui: Received tuitter:new-tweet');
k['new-tweet']();
});
});
ipc.on('tuitter:will-suspend', (_: any, threshold: number) => {
const memKB = process.getProcessMemoryInfo().privateBytes;
console.log('Tui: Will suspend', threshold, memKB);
const memMB = memKB / 1000;
if (memMB > threshold) {
console.log('Tui: Memory usage exceeds the threshold. Request refreshing:', threshold, memMB);
ipc.sendToHost('tuitter:refresh-me', memKB);
}
});
}).catch(e => {
示例9:
editor.on('process-attached', () => {
const client = editor.getClient();
client.listRuntimePaths()
.then((rtp: string[]) => {
component_loader.loadFromRTP(rtp);
component_loader.initially_loaded = true;
});
runtime_api.subscribe(client);
element.addEventListener('drop', e => {
e.preventDefault();
const f = e.dataTransfer.files[0];
if (f) {
client.command('edit! ' + f.path);
}
});
app.on('open-file', (e: Event, p: string) => {
e.preventDefault();
client.command('edit! ' + p);
});
ipc.on('nyaovim:exec-commands', (_: Event, cmds: string[]) => {
console.log('ipc: nyaovim:exec-commands', cmds);
for (const c of cmds) {
client.command(c);
}
});
});
示例10: init
(function init() {
const { getPersistentAsJson } = Electron.remote.require("./remote");
const json = JSON.parse(getPersistentAsJson());
const config = json.config as Config;
store.mutations.resetConfig(config);
try {
const recentList = JSON.parse(localStorage.getItem("recentList") || "[]");
if (
recentList instanceof Array &&
recentList.every(v => typeof v === "string")
) {
store.mutations.resetRecentList(recentList);
} else {
console.warn("Failed to load recentList from localStorage");
}
} catch {
console.warn("Failed to load recentList from localStorage");
}
Electron.ipcRenderer.on(
"action",
(_event: string, name: string, payload: any) => {
(store.actions as any)[name](payload);
}
);
})();
示例11:
>(observer => {
ipc.on("kernel_specs_reply", (event: any, specs: Kernelspecs) => {
observer.next(specs);
observer.complete();
});
ipc.send("kernel_specs_request");
});
示例12: constructor
constructor(private readonly config: Config) {
this.switchTo(this.getFirstScreenName());
// After hiding window, <webview> loses its focus.
// So when window is shown again, need to give <webview> focus again.
// Note:
// remove.getCurrentWindow().on('focus', ...) is unavailable
// because callback remains after this web contents reloaded.
// Remained callback causes a 'trying to send message to removed web contents'
// error.
ipc.on('tuitter:window-focused', () => this.wv.focus());
ipc.on('tuitter:menu:new-tweet', () => this.wv.sendIpc('tuitter:new-tweet'));
ipc.on('tuitter:will-suspend', (__: any, threshold: number) => {
log.debug('Refresh app because system will be suspended. Threshold:', threshold, this.wv);
this.wv.sendIpc('tuitter:will-suspend', threshold);
});
}
示例13: RendererApp
ipc.once('tuitter:config', (_: any, config: Config) => {
log.debug('Config was sent from main:', config);
const app = new RendererApp(config);
ipc.on('tuitter:account', (__: any, index: number, screenName: string) => {
log.debug('Will switch to account', index, screenName);
app.switchTo(screenName.slice(1)); // Strip '@'
});
});
示例14: subscribe
subscribe(channel: string, listener: (event: any, args: any) => void) {
const wrappedListener = (event: any, args: any) => {
listener(event, args)
this.appRef.tick()
}
ipcRenderer.on(channel, wrappedListener)
return this
}
示例15: constructor
constructor() {
this.has_ipc = (typeof ipcRenderer != 'undefined');
// Set listener
if (this.has_ipc) {
ipcRenderer.on('asynchronous-reply', (event, arg) => {
console.log(arg); // prints "pong"
});
}
}