export function popup(items: IContextMenuItem[], options?: IPopupOptions): void { const processedItems: IContextMenuItem[] = []; const contextMenuId = contextMenuIdPool++; const onClickChannel = `vscode:onContextMenu${contextMenuId}`; const onClickChannelHandler = (_event: Event, itemId: number, context: IContextMenuEvent) => { const item = processedItems[itemId]; if (item.click) { item.click(context); } }; ipcRenderer.once(onClickChannel, onClickChannelHandler); ipcRenderer.once(CONTEXT_MENU_CLOSE_CHANNEL, (_event: Event, closedContextMenuId: number) => { if (closedContextMenuId !== contextMenuId) { return; } ipcRenderer.removeListener(onClickChannel, onClickChannelHandler); if (options && options.onHide) { options.onHide(); } }); ipcRenderer.send(CONTEXT_MENU_CHANNEL, contextMenuId, items.map(item => createItem(item, processedItems)), onClickChannel, options); }
export function popup(items: IContextMenuItem[], options?: IPopupOptions): void { const processedItems: IContextMenuItem[] = []; const onClickChannel = `vscode:onContextMenu${onClickChannelIds++}`; const onClickChannelHandler = (event: Event, itemId: number, context: IContextMenuEvent) => processedItems[itemId].click(context); ipcRenderer.once(onClickChannel, onClickChannelHandler); ipcRenderer.once(CONTEXT_MENU_CLOSE_CHANNEL, () => { ipcRenderer.removeListener(onClickChannel, onClickChannelHandler); if (options && options.onHide) { options.onHide(); } }); ipcRenderer.send(CONTEXT_MENU_CHANNEL, items.map(item => createItem(item, processedItems)), onClickChannel, options); }
return new Promise<boolean>((resolve, reject) => { ipcRenderer.once( 'open-external-result', (event: Electron.IpcMessageEvent, { result }: { result: boolean }) => { resolve(result) } ) ipcRenderer.send('open-external', { path }) })
return new Promise((resolve, reject) => { ipcRenderer.send('game:start', {version}); ipcRenderer.once('game:started', (event, arg) => { switch (arg.status) { case 'success': console.log('running'); break; case 'missing-library': // TODO missing library console.log(arg.missing); const err = new Error('missing-library'); err['missing'] = arg.missing; reject(err); break; case 'error': alert(arg.error); } resolve(); }); })
function main(server: Server, initData: ISharedProcessInitData, configuration: ISharedProcessConfiguration): void { const services = new ServiceCollection(); const disposables: IDisposable[] = []; const onExit = () => dispose(disposables); process.once('exit', onExit); ipcRenderer.once('handshake:goodbye', onExit); disposables.push(server); const environmentService = new EnvironmentService(initData.args, process.execPath); const mainRoute = () => TPromise.as('main'); const logLevelClient = new LogLevelSetterChannelClient(server.getChannel('loglevel', { routeCall: mainRoute, routeEvent: mainRoute })); const logService = new FollowerLogService(logLevelClient, createSpdLogService('sharedprocess', initData.logLevel, environmentService.logsPath)); disposables.push(logService); logService.info('main', JSON.stringify(configuration)); services.set(IEnvironmentService, environmentService); services.set(ILogService, logService); services.set(IConfigurationService, new SyncDescriptor(ConfigurationService)); services.set(IRequestService, new SyncDescriptor(RequestService)); services.set(IDownloadService, new SyncDescriptor(DownloadService)); const windowsChannel = server.getChannel('windows', { routeCall: mainRoute, routeEvent: mainRoute }); const windowsService = new WindowsChannelClient(windowsChannel); services.set(IWindowsService, windowsService); const activeWindowManager = new ActiveWindowManager(windowsService); const route = () => activeWindowManager.getActiveClientId(); const dialogChannel = server.getChannel('dialog', { routeCall: route, routeEvent: route }); services.set(IDialogService, new DialogChannelClient(dialogChannel)); const instantiationService = new InstantiationService(services); instantiationService.invokeFunction(accessor => { const services = new ServiceCollection(); const environmentService = accessor.get(IEnvironmentService); const { appRoot, extensionsPath, extensionDevelopmentLocationURI, isBuilt, installSourcePath } = environmentService; const telemetryLogService = new FollowerLogService(logLevelClient, createSpdLogService('telemetry', initData.logLevel, environmentService.logsPath)); telemetryLogService.info('The below are logs for every telemetry event sent from VS Code once the log level is set to trace.'); telemetryLogService.info('==========================================================='); let appInsightsAppender: ITelemetryAppender | null = NullAppender; if (!extensionDevelopmentLocationURI && !environmentService.args['disable-telemetry'] && product.enableTelemetry) { if (product.aiConfig && product.aiConfig.asimovKey && isBuilt) { appInsightsAppender = new AppInsightsAppender(eventPrefix, null, product.aiConfig.asimovKey, telemetryLogService); disposables.push(appInsightsAppender); // Ensure the AI appender is disposed so that it flushes remaining data } const config: ITelemetryServiceConfig = { appender: combinedAppender(appInsightsAppender, new LogAppender(logService)), commonProperties: resolveCommonProperties(product.commit, pkg.version, configuration.machineId, installSourcePath), piiPaths: [appRoot, extensionsPath] }; services.set(ITelemetryService, new SyncDescriptor(TelemetryService, [config])); } else { services.set(ITelemetryService, NullTelemetryService); } server.registerChannel('telemetryAppender', new TelemetryAppenderChannel(appInsightsAppender)); services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService)); services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService)); services.set(ILocalizationsService, new SyncDescriptor(LocalizationsService)); const instantiationService2 = instantiationService.createChild(services); instantiationService2.invokeFunction(accessor => { const extensionManagementService = accessor.get(IExtensionManagementService); const channel = new ExtensionManagementChannel(extensionManagementService); server.registerChannel('extensions', channel); // clean up deprecated extensions (extensionManagementService as ExtensionManagementService).removeDeprecatedExtensions(); const localizationsService = accessor.get(ILocalizationsService); const localizationsChannel = new LocalizationsChannel(localizationsService); server.registerChannel('localizations', localizationsChannel); createSharedProcessContributions(instantiationService2); disposables.push(extensionManagementService as ExtensionManagementService); }); }); }
return new TPromise<ISharedProcessInitData>((c, e) => { ipcRenderer.once('handshake:hey there', (_: any, r: ISharedProcessInitData) => c(r)); ipcRenderer.send('handshake:hello'); });
const data = await new Promise<ISharedProcessInitData>(c => { ipcRenderer.once('handshake:hey there', (_: any, r: ISharedProcessInitData) => c(r)); ipcRenderer.send('handshake:hello'); });
const pluginPaths = new Promise<string[]>(resolve => { ipc.once('tuitter:plugin-paths', (_: any, paths: string[]) => { console.log('Tui: Received plugin paths:', paths); resolve(paths); }); });
const receivedKeymaps = new Promise<KeymapsConfig>(resolve => { ipc.once('tuitter:keymaps', (_: any, k: KeymapsConfig) => { console.log('Tui: Received keymappings:', k); resolve(k); }); });
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * */ import {IpcMessageEvent, ipcRenderer} from 'electron'; import {EVENT_TYPE} from '../../lib/eventType'; ipcRenderer.once(EVENT_TYPE.ABOUT.LOCALE_RENDER, (event: IpcMessageEvent, labels: string[]) => { for (const label in labels) { const labelElement = document.querySelector(`[data-string="${label}"]`); if (labelElement) { labelElement.innerHTML = labels[label]; } } }); interface Details { copyright: string; electronVersion: string; environment: string; productName: string; webappVersion: string; } ipcRenderer.once(EVENT_TYPE.ABOUT.LOADED, (event: Event, details: Details) => { const nameElement = document.getElementById('name'); if (nameElement) {