当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript BrowserWindow.loadFile方法代码示例

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


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

示例1: createMainWindow

export function createMainWindow(): Electron.BrowserWindow {
  console.log(`Creating main window`);
  const browserWindow = new BrowserWindow(getMainWindowOptions());
  browserWindow.loadFile('./dist/static/index.html');

  browserWindow.webContents.once('dom-ready', () => {
    browserWindow.show();

    if (browserWindow) {
      createContextMenu(browserWindow);
    }
  });

  browserWindow.on('closed', () => {
    browserWindows = browserWindows
      .filter((bw) => browserWindow !== bw);
  });

  browserWindow.webContents.on('new-window', (event, url) => {
    event.preventDefault();
    shell.openExternal(url);
  });

  browserWindow.webContents.on('will-navigate', (event, url) => {
    event.preventDefault();
    shell.openExternal(url);
  });

  browserWindows.push(browserWindow);

  return browserWindow;
}
开发者ID:bpasero,项目名称:fiddle,代码行数:32,代码来源:windows.ts

示例2: createWindow

function createWindow() {
  const electronScreen = screen;
  const size = electronScreen.getPrimaryDisplay().workAreaSize;

  // Create the browser window.
  mainWindow = new BrowserWindow({
    x: 0,
    y: 0,
    width: size.width,
    height: size.height
  });

  if (liveReload) {
    require('electron-reload')(__dirname, { electron: require(`${__dirname}/node_modules/electron`) });
    mainWindow.loadURL('http://localhost:4200');
    mainWindow.webContents.openDevTools();
  } else {
    // Load the index.html of the app.
    mainWindow.loadFile('dist.electron/index.html');
  }

  // Emitted when the window is closed.
  mainWindow.on('closed', () => {
    // Dereference the window object, usually you would store window
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });
}
开发者ID:sinedied,项目名称:sk-angular2,代码行数:29,代码来源:__electron.electron.main.ts

示例3: it

    it('returns an array of web contents', async () => {
      w.loadFile(path.join(fixturesPath, 'pages', 'webview-zoom-factor.html'))

      await emittedOnce(w.webContents, 'did-attach-webview')

      w.webContents.openDevTools()

      await emittedOnce(w.webContents, 'devtools-opened')

      const all = webContents.getAllWebContents().sort((a, b) => {
        return a.id - b.id
      })

      expect(all).to.have.length(3)
      expect(all[0].getType()).to.equal('window')
      expect(all[all.length - 2].getType()).to.equal('webview')
      expect(all[all.length - 1].getType()).to.equal('remote')
    })
开发者ID:doridoridoriand,项目名称:electron,代码行数:18,代码来源:api-web-contents-spec.ts

示例4: BrowserWindow

app.on('ready', () => {
    window = new BrowserWindow({
        acceptFirstMouse: true,
        width: 1280,
        height: 720,
        minWidth: 500,
        minHeight: 500,
        backgroundColor: "#DDDDDD",
        frame: false,
        hasShadow: true
    });

    // window.setMenu(null);
    window.loadFile(join(__dirname, "../", "index.html"));

    window.on('closed', function () {
        window = undefined;
    });
});
开发者ID:reverse-squared,项目名称:OldMaterialClicker,代码行数:19,代码来源:window.ts

示例5: EstablishElectronWindow

function EstablishElectronWindow() {
  // If not prod, install Vue devtools.
  if (isDev) {
    require('vue-devtools').install()
  }
  /* Check whether we are started in the hidden state as part of the computer startup process. */
  const loginSettings = elc.app.getLoginItemSettings()
  let hiddenStartAtBoot = loginSettings.wasOpenedAsHidden
  // ^ Only applies to Mac OS
  if (process.platform === 'win32') {
    // ^ Windows version of above
    for (let arg of process.argv) {
      if (arg === '--hidden') {
        hiddenStartAtBoot = true
      }
    }
  }

  // Create the browser window.
  // let dm = elc.screen.getPrimaryDisplay().size
  let bounds = getWinBounds()
  let windowSpec: any = {
    show: false,
    // width: dm.width * 0.8,
    width: bounds.w,
    // height: dm.height * 0.8,
    height: bounds.h,
    title: 'Aether',
    fullscreenWindowTitle: true,
    backgroundColor: '#292b2f',
    disableBlinkFeatures: 'Auxclick', // disable middle click new window
    autoHideMenuBar: true,
    webPreferences: {
      // blinkFeatures: 'OverlayScrollbars'
    },
  }
  if (process.platform === 'win32') {
    windowSpec.frame = false // We have our traffic lights implementation for Win
  }
  if (process.platform === 'darwin') {
    windowSpec.titleBarStyle = 'hiddenInset' // Mac traffic lights
  }
  if (process.platform === 'linux') {
    windowSpec.darkTheme = true // GTK3+ Only
    // Nothing specific for the frame for now.
  }
  win = new elc.BrowserWindow(windowSpec)
  win.once('ready-to-show', function() {
    // We want to show the window only after Electron is done readying itself.
    setTimeout(function() {
      if (!hiddenStartAtBoot) {
        win.show()
      }
    }, 100)
    // Unfortunately, there's a race condition from the Electron side here (I might be making a mistake also, but it is simple enough to reproduce that there is not much space for me to make a mistake). If the setTimeout is 0 or is not present, there's about 1/10 chance the window is painted but completely frozen. Having 100ms seems to make it go away, but it's a little icky, because that basically is my guess. Not great. Hopefully they'll fix this in upcoming Electron 3.
  })
  win.loadFile('index.html')
  if (isDev) {
    // Open the DevTools.
    win.webContents.openDevTools({ mode: 'bottom' })
  }

  // win.webContents.openDevTools({ mode: 'bottom' })

  win.on('close', function(e: any) {
    e.preventDefault()
    // ^ Prevents the app from continuing on with destroying the window element. We need that element.
    closeAppWindow()
    // DOM_READY = false // This is useful when the electron window fully shuts down, not when it's not fully shut down.
  })

  win.webContents.on('dom-ready', function() {
    DOM_READY = true
    // This is needed because the renderer process won't be able to respond to IPC requests before this event happens.

    if (process.platform == 'win32') {
      /*----------  Windows specific deep linker  ----------*/
      /*
        This is the windows-specific implementation of the open-url in the will-finish-launching event.

        This code is available in two different places. This one handles deep-linking from cold boot.
      */
      // Keep only command line / deep linked arguments
      if (typeof process.argv.slice(1)[0] !== 'undefined') {
        linkToLoadAtBoot = process.argv.slice(1)[0].substring(8)
      }
    }
    // Normal open-url event works for Mac and Linux
    if (linkToLoadAtBoot.length > 0) {
      ipc.callRenderer(win, 'RouteTo', linkToLoadAtBoot)
    }
  })
  win.webContents.on('will-navigate', function(e: any, reqUrl: any) {
    e.preventDefault()
    elc.shell.openExternal(reqUrl)
    // return
    // let getHost = function(url: any) { require('url').parse(url).host }
    // let reqHost = getHost(reqUrl)
    // let isExternal = reqHost && reqHost != getHost(win.webContents.getURL())
    // if (isExternal) {
//.........这里部分代码省略.........
开发者ID:nehbit,项目名称:aether-public,代码行数:101,代码来源:mainmain.ts

示例6: async

export const loadFile = async (appPath: string) => {
  mainWindow = await createWindow()
  mainWindow.loadFile(appPath)
  mainWindow.focus()
}
开发者ID:malept,项目名称:electron,代码行数:5,代码来源:default_app.ts


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