Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed Composer Electron startup window dimensions #2769

Merged
merged 6 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Composer/packages/electron-server/src/electronWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { app, BrowserWindow, screen } from 'electron';

import { isDevelopment } from './utility/env';
import { getUnpackedAsarPath } from './utility/getUnpackedAsarPath';
import logger from './utility/logger';
const log = logger.extend('electron-window');

export default class ElectronWindow {
private static instance: ElectronWindow | undefined;
Expand All @@ -21,10 +23,14 @@ export default class ElectronWindow {

private constructor() {
// Create the browser window.
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
const { height, width } = screen.getPrimaryDisplay().workAreaSize;
log(`Raw screen dimensions: ${height} x ${width}`);
const adjustedHeight = Math.floor(height * 0.9); // take up 90% of screen height
const adjustedWidth = Math.floor((4 / 3) * adjustedHeight); // snap to 4:3 aspect ratio (16:9 doesn't look as good when scaled down)
log(`Electron window dimensions: ${adjustedHeight} x ${adjustedWidth}`);
const browserWindowOptions: Electron.BrowserWindowConstructorOptions = {
width: width * 0.75,
height: height * 0.9,
width: adjustedWidth,
height: adjustedHeight,
webPreferences: {
nodeIntegration: false,
preload: join(__dirname, 'preload.js'),
Expand All @@ -39,6 +45,7 @@ export default class ElectronWindow {
}
this._currentBrowserWindow = new BrowserWindow(browserWindowOptions);
this._currentBrowserWindow.on('page-title-updated', ev => ev.preventDefault()); // preserve explicit window title
log('Rendered Electron window dimensions: ', this._currentBrowserWindow.getSize());
}

public static destroy() {
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/electron-server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async function loadServer() {
async function main() {
const mainWindow = ElectronWindow.getInstance().browserWindow;
if (mainWindow) {
if (isDevelopment) {
if (process.env.COMPOSER_DEV_TOOLS) {
mainWindow.webContents.openDevTools();
}

Expand Down