當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。