• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript electron.ipcMain类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中electron.ipcMain的典型用法代码示例。如果您正苦于以下问题:TypeScript ipcMain类的具体用法?TypeScript ipcMain怎么用?TypeScript ipcMain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ipcMain类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: isTrustedSender

const indexPath = path.resolve(app.getAppPath(), 'index.html')

function isTrustedSender (webContents: Electron.WebContents) {
  if (webContents !== (mainWindow && mainWindow.webContents)) {
    return false
  }

  const parsedUrl = new URL(webContents.getURL())
  return parsedUrl.protocol === 'file:' && parsedUrl.pathname === indexPath
}

ipcMain.on('bootstrap', (event) => {
  try {
    event.returnValue = isTrustedSender(event.sender) ? electronPath : null
  } catch {
    event.returnValue = null
  }
})

async function createWindow () {
  await app.whenReady()

  const options: Electron.BrowserWindowConstructorOptions = {
    width: 900,
    height: 600,
    autoHideMenuBar: true,
    backgroundColor: '#FFFFFF',
    webPreferences: {
      preload: path.resolve(__dirname, 'preload.js'),
      contextIsolation: true,
开发者ID:malept,项目名称:electron,代码行数:30,代码来源:default_app.ts


示例2: getMainWindow

import {app, ipcMain, nativeImage, BrowserWindow, screen} from "electron";
import menu from "./Menu";


let browserWindow: Electron.BrowserWindow = undefined;

if (app.dock) {
    app.dock.setIcon(nativeImage.createFromPath("icon.png"));
}

app.on("open-file", (event: Event, file: string) => getMainWindow().webContents.send("change-working-directory", file));
app.on("ready", getMainWindow);
app.on("activate", getMainWindow);
app.on("mainWindow-all-closed", () => process.platform === "darwin" || app.quit());

ipcMain.on("quit", app.quit);

function getMainWindow(): Electron.BrowserWindow {
    const workAreaSize = screen.getPrimaryDisplay().workAreaSize;

    if (!browserWindow) {
        let options: Electron.BrowserWindowOptions = {
            webPreferences: {
                experimentalFeatures: true,
                experimentalCanvasFeatures: true,
            },
            titleBarStyle: "hidden",
            title: "Black Screen",
            resizable: true,
            minWidth: 500,
            minHeight: 300,
开发者ID:scottwarren,项目名称:black-screen,代码行数:31,代码来源:Main.ts


示例3: startCleanExit

  }

  if (!isReadyToQuit) event.preventDefault();
});

function startCleanExit() {
  console.log("Exiting cleanly...");
  if (mainWindow != null) mainWindow.webContents.send("quit");
  isQuitting = true;
}

electron.ipcMain.on("ready-to-quit", (event) => {
  if (event.sender !== mainWindow.webContents) return;

  SupAppIPC.saveAuthorizations(userDataPath);

  console.log("Exited cleanly.");
  isReadyToQuit = true;
  electron.app.quit();
});

electron.ipcMain.on("show-main-window", () => { restoreMainWindow(); });

function onAppReady() {
  menu.setup(electron.app);

  getPaths((dataPathErr, pathToCore, pathToUserData) => {
    userDataPath = pathToUserData;
    corePath = pathToCore;

    SupAppIPC.loadAuthorizations(userDataPath);
开发者ID:nitpum,项目名称:superpowers-app,代码行数:31,代码来源:main.ts


示例4: closeServer

ipcMain
    .on('pageLoad', (event, arg) => { // the renderer will send a 'pageLoad' message once the index.html document is loaded. (implies that the mainWindow exists)       
        if (wss != null || event.sender == null) {
            return;
        }

        wss = new WebSocket.Server({ port: Config.PORT });
        connectionHandler.announceServer();
        let ipcClient = event.sender;

        // wss events should be registered immediately
        wss.on('connection', (ws, req) => {
            console.log("ws(incoming connection)", req.connection.remoteAddress)
            // const clientAddress = req.connection.remoteAddress;
            ipcClient.send('clientConnected', '');

            ws.on('message', message => {
                console.log('ws(message): ', message)
                // TODO: da sempre false, perchè?
                // è necessario questo controllo?
                if (!uiHandler.mainWindow) {
                    return;
                }

                let messageObj = JSON.parse(message.toString());

                scanHandler.onWsMessage(ws, messageObj);
                connectionHandler.onWsMessage(ws, messageObj);

                ipcClient.send(messageObj.action, messageObj);
            });

            ws.on('close', () => {
                console.log('ws(close)', req.connection.remoteAddress);
                connectionHandler.onWsClose(ws);
            });

            ws.on('error', (err) => {
                console.log('ws(error): ', err, req.connection.remoteAddress);
                connectionHandler.onWsError(ws, err);
            });
        });

        // app.on('before-quit', (event) => {
        //    closeServer();
        // })

        app.on('window-all-closed', () => { // TODO: test on windows
           closeServer();
        });
        updateHandler.checkUpdates();
    })
开发者ID:jazzkell,项目名称:barcode-to-pc-server,代码行数:52,代码来源:main.ts


示例5: now

app.on('ready', () => {
  if (isDuplicateInstance || handlingSquirrelEvent) {
    return
  }

  readyTime = now() - launchTime

  app.setAsDefaultProtocolClient('x-github-client')

  if (__DEV__) {
    app.setAsDefaultProtocolClient('x-github-desktop-dev-auth')
  } else {
    app.setAsDefaultProtocolClient('x-github-desktop-auth')
  }

  // Also support Desktop Classic's protocols.
  if (__DARWIN__) {
    app.setAsDefaultProtocolClient('github-mac')
  } else if (__WIN32__) {
    app.setAsDefaultProtocolClient('github-windows')
  }

  createWindow()

  let menu = buildDefaultMenu()
  Menu.setApplicationMenu(menu)

  ipcMain.on(
    'update-preferred-app-menu-item-labels',
    (
      event: Electron.IpcMessageEvent,
      labels: { editor?: string; pullRequestLabel?: string; shell: string }
    ) => {
      menu = buildDefaultMenu(
        labels.editor,
        labels.shell,
        labels.pullRequestLabel
      )
      Menu.setApplicationMenu(menu)
      if (mainWindow) {
        mainWindow.sendAppMenu()
      }
    }
  )

  ipcMain.on('menu-event', (event: Electron.IpcMessageEvent, args: any[]) => {
    const { name }: { name: MenuEvent } = event as any
    if (mainWindow) {
      mainWindow.sendMenuEvent(name)
    }
  })

  /**
   * An event sent by the renderer asking that the menu item with the given id
   * is executed (ie clicked).
   */
  ipcMain.on(
    'execute-menu-item',
    (event: Electron.IpcMessageEvent, { id }: { id: string }) => {
      const menuItem = findMenuItemByID(menu, id)
      if (menuItem) {
        const window = BrowserWindow.fromWebContents(event.sender)
        const fakeEvent = { preventDefault: () => {}, sender: event.sender }
        menuItem.click(fakeEvent, window, event.sender)
      }
    }
  )

  ipcMain.on(
    'update-menu-state',
    (
      event: Electron.IpcMessageEvent,
      items: Array<{ id: string; state: IMenuItemState }>
    ) => {
      let sendMenuChangedEvent = false

      for (const item of items) {
        const { id, state } = item
        const menuItem = findMenuItemByID(menu, id)

        if (menuItem) {
          // Only send the updated app menu when the state actually changes
          // or we might end up introducing a never ending loop between
          // the renderer and the main process
          if (
            state.enabled !== undefined &&
            menuItem.enabled !== state.enabled
          ) {
            menuItem.enabled = state.enabled
            sendMenuChangedEvent = true
          }
        } else {
          fatalError(`Unknown menu id: ${id}`)
        }
      }

      if (sendMenuChangedEvent && mainWindow) {
        mainWindow.sendAppMenu()
      }
    }
//.........这里部分代码省略.........
开发者ID:Ahskys,项目名称:desktop,代码行数:101,代码来源:main.ts


示例6: async

export const runExtensionsService = (window: BrowserWindow) => {
  ipcMain.on(API_TABS_QUERY, (e: Electron.IpcMessageEvent) => {
    window.webContents.send(API_TABS_QUERY, e.sender.id);
  });

  ipcMain.on(
    API_TABS_CREATE,
    (e: Electron.IpcMessageEvent, data: chrome.tabs.CreateProperties) => {
      window.webContents.send(API_TABS_CREATE, data, e.sender.id);
    },
  );

  ipcMain.on(
    API_TABS_INSERT_CSS,
    (
      e: Electron.IpcMessageEvent,
      tabId: number,
      details: chrome.tabs.InjectDetails,
    ) => {
      window.webContents.send(API_TABS_INSERT_CSS, tabId, details, e.sender.id);
    },
  );

  ipcMain.on(
    API_TABS_EXECUTE_SCRIPT,
    (
      e: Electron.IpcMessageEvent,
      tabId: number,
      details: chrome.tabs.InjectDetails,
    ) => {
      window.webContents.send(
        API_TABS_EXECUTE_SCRIPT,
        tabId,
        details,
        e.sender.id,
      );
    },
  );

  ipcMain.on(
    API_RUNTIME_RELOAD,
    (e: Electron.IpcMessageEvent, extensionId: string) => {
      if (global.backgroundPages[extensionId]) {
        const contents = webContents.fromId(e.sender.id);
        contents.reload();
      }
    },
  );

  ipcMain.on(
    API_RUNTIME_CONNECT,
    async (e: Electron.IpcMessageEvent, data: any) => {
      const { extensionId, portId, sender, name } = data;
      const bgPage = global.backgroundPages[extensionId];

      if (e.sender.id !== bgPage.webContentsId) {
        const contents = webContents.fromId(bgPage.webContentsId);
        contents.send(API_RUNTIME_CONNECT, { portId, sender, name });
      }
    },
  );

  ipcMain.on(API_PORT_POSTMESSAGE, (e: Electron.IpcMessageEvent, data: any) => {
    const { portId, msg } = data;

    Object.keys(global.backgroundPages).forEach(key => {
      const bgPage = global.backgroundPages[key];
      if (e.sender.id !== bgPage.webContentsId) {
        const contents = webContents.fromId(bgPage.webContentsId);
        contents.send(API_PORT_POSTMESSAGE + portId, msg);
      }
    });

    window.webContents.send(API_PORT_POSTMESSAGE, {
      portId,
      msg,
      senderId: e.sender.id,
    });
  });

  ipcMain.on(
    API_STORAGE_OPERATION,
    (e: Electron.IpcMessageEvent, data: any) => {
      const contents = webContents.fromId(e.sender.id);
      const storage = global.databases[data.extensionId];
      const msg = API_STORAGE_OPERATION + data.id;

      if (data.type === 'get') {
        storage[data.area].get(data.arg, d => {
          for (const key in d) {
            if (Buffer.isBuffer(d[key])) {
              d[key] = JSON.parse(d[key].toString());
            }
          }
          contents.send(msg, d);
        });
      } else if (data.type === 'set') {
        storage[data.area].set(data.arg, () => {
          contents.send(msg);
        });
//.........这里部分代码省略.........
开发者ID:laquereric,项目名称:wexond,代码行数:101,代码来源:extensions-service.ts


示例7: function

  // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', function() {
  // On OS X it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (mainWindow === null) {
    createWindow(devTools);
  }
});


start();

// save map file
ipcMain.on('map:save', (event: Electron.IpcMessageEvent, data: string, filepath: string) => {
  IO.saveMap(data, filepath);
});

ipcMain.on('map:load', (event: Electron.IpcMessageEvent, filepath: string) => {
  IO.loadMap(mainWindow.webContents, filepath);
});

ipcMain.on('terrain:load', (event: Electron.IpcMessageEvent, terrainFilePath: string, mapFilePath: string) => {
  IO.loadTerrain(mainWindow.webContents, terrainFilePath, mapFilePath);
});
开发者ID:andrew-ni,项目名称:warcraft2-tools-unofficial,代码行数:30,代码来源:main.ts


示例8: function

    });

    mainWindow.loadURL(__dirname + '/index.html');

    if (env.name !== 'production') {
        mainWindow.webContents.openDevTools();
    }

    mainWindow.webContents.on('did-finish-load', function () {
        mainWindow.webContents.send('scheduler-load', app.getPath('userData'), 'schedules-main.json');
        mainWindow.webContents.send('scheduler-tray-click', 'hey!');
    });

    mainWindow.on('close', (e) => {
        if (mainWindow.forceClose) return;
        e.preventDefault();
        mainWindow.hide();
    });

});

app.on('window-all-closed', function () {
    app.quit();
});

ipcMain.on('schedules-loaded', (event, arg) => {
    schedulesData = arg;
    const contextMenu = schedulesMenu(app, mainWindow, arg);
    var menus = [contextMenu, closeMenu];
    tray.setContextMenu(Menu.buildFromTemplate(menus));
});
开发者ID:frieck,项目名称:WiN,代码行数:31,代码来源:desktop.ts


示例9: subscribe

 subscribe(c: ChannelFromRenderer, cb: Function) {
     ipc.on(c, (_, ...args) => {
         log.debug('<--- Channel:', c);
         cb.apply(this, args);
     });
 }
开发者ID:DevenLu,项目名称:YourFukurou,代码行数:6,代码来源:twitter.ts


示例10: existsSync

  .default("kernel", "python3")
  .alias("k", "kernel")
  .alias("v", "version")
  .alias("h", "help")
  .describe("verbose", "Display debug information")
  .help("help")
  .parse(process.argv.slice(1));

log.info("args", argv);

const notebooks = argv._.filter(x => /(.ipynb)$/.test(x)).filter(x =>
  existsSync(resolve(x))
);

ipc.on("new-kernel", (_event: any, k: KernelspecInfo) => {
  launchNewNotebook(k);
});

ipc.on("open-notebook", (_event: any, filename: string) => {
  launch(resolve(filename));
});

ipc.on("reload", (event: Event) => {
  event.sender.reload();
  event.returnValue = null;
});

ipc.on("show-message-box", (event: Event, arg: any) => {
  const response = dialog.showMessageBox(arg);
  event.sender.send("show-message-box-response", response);
});
开发者ID:nteract,项目名称:nteract,代码行数:31,代码来源:index.ts



注:本文中的electron.ipcMain类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript electron.ipcRenderer类代码示例发布时间:2022-05-25
下一篇:
TypeScript electron.globalShortcut类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap