Example #1
0
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());
    }
  );
};
Example #2
0
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);
		}
	};
}
Example #3
0
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();
};
Example #4
0
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')
}
    /**
     * @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() {}) ;
    }
Example #6
0
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)))
}
Example #7
0
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();
    });
}
Example #8
0
File: index.ts Project: rhysd/Tui
 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 => {
Example #9
0
        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);
                }
            });
        });
Example #10
0
(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);
    }
  );
})();