當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ipcRenderer.on方法代碼示例

本文整理匯總了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());
    }
  );
};
開發者ID:wireapp,項目名稱:wire-desktop,代碼行數:27,代碼來源:preload.ts

示例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);
        }
    };
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:33,代碼來源:processExplorerMain.ts

示例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();
};
開發者ID:laquereric,項目名稱:wexond,代碼行數:32,代碼來源:index.ts

示例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')
}
開發者ID:castaneai,項目名稱:nowpl,代碼行數:32,代碼來源:index.ts

示例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() {}) ;
    }
開發者ID:dcarlus,項目名稱:2D-Animation-Editor,代碼行數:36,代碼來源:ImageImportHandler.ts

示例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)))
}
開發者ID:m0g,項目名稱:ansel,代碼行數:28,代碼來源:ForegroundService.ts

示例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();
    });
}
開發者ID:finderL,項目名稱:node-party,代碼行數:13,代碼來源:main.ts

示例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 => {
開發者ID:rhysd,項目名稱:Tui,代碼行數:29,代碼來源:index.ts

示例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);
                }
            });
        });
開發者ID:AnujKosambi,項目名稱:NyaoVim,代碼行數:31,代碼來源:nyaovim-app.ts

示例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);
    }
  );
})();
開發者ID:wonderful-panda,項目名稱:inazuma,代碼行數:27,代碼來源:index.ts

示例11:

>(observer => {
  ipc.on("kernel_specs_reply", (event: any, specs: Kernelspecs) => {
    observer.next(specs);
    observer.complete();
  });
  ipc.send("kernel_specs_request");
});
開發者ID:nteract,項目名稱:nteract,代碼行數:7,代碼來源:zeromq-kernels.ts

示例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);
        });
    }
開發者ID:rhysd,項目名稱:Tui,代碼行數:17,代碼來源:app.ts

示例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 '@'
    });
});
開發者ID:rhysd,項目名稱:Tui,代碼行數:8,代碼來源:index.ts

示例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
  }
開發者ID:makaria,項目名稱:GReader,代碼行數:9,代碼來源:ipc.service.ts

示例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"
            });
        }
    }
開發者ID:aracen74,項目名稱:tsng2,代碼行數:9,代碼來源:homepage.component.ts


注:本文中的electron.ipcRenderer.on方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。