Skip to content

Instantly share code, notes, and snippets.

@LeeDDHH
Last active August 14, 2021 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeeDDHH/b27244b5b39ad1e84896f6cc5119619b to your computer and use it in GitHub Desktop.
Save LeeDDHH/b27244b5b39ad1e84896f6cc5119619b to your computer and use it in GitHub Desktop.
Electron実装時のtips

フレームレスウィンドウにして、動かす

mainプロセス

settingWindow = new BrowserWindow({
  width: 800,
  height: 600,
  frame: false,
  maximizable: false,
  fullscreenable: false,
  resizable: false,
  webPreferences: windowOption,
});

rendererプロセス

<head><!--場合によっては必要-->
  <meta
    http-equiv="Content-Security-Policy"
    content="default-src 'self' 'unsafe-eval' 'unsafe-inline';"
  />
  <meta
    http-equiv="X-Content-Security-Policy"
    content="default-src 'self';"
  />
  <!----></head><body style="-webkit-app-region: drag"></body>

ソース

windows版でBrowserWindowの大きさをsetSizeで変更しても、変更通りにならないときにやること

  • setSizeの処理の前に、setMinimumSizeを指定する

win.setMinimumSize(minWidth, minHeight);
win.setSize(width, height);

ソース

menuBrowserWindow 内のコンテキストメニューとしてポップアップさせる際に、 window を指定する方法

TypeScriptで指定する

const menu = new Menu();
menu.popup({ window: windowInstance });

ソース

Creating a custom menu bar in Electron - DEV Community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment