webview-bun icon indicating copy to clipboard operation
webview-bun copied to clipboard

Setting window size according to the screen size or maximize the window

Open dev-swarup opened this issue 1 year ago • 0 comments

I am using tr1ckydev/webview-bun. I want to launch a maximized window. Currently, I achieved this using.

// index.ts

import { Webview, SizeHint } from "webview-bun";
const document = new Webview(true, { width: 300, height: 300, hint: SizeHint.NONE });

document.bind('setWindowSize', async (height: number, width: number) => {
    document
        .size = { height, width, hint: SizeHint.FIXED };
    return true;
});

document
    .setHTML(await Bun.file(require('path').join(import.meta.dir, 'index.html')).text()); document.run();
<!-- index.html -->
<html lang="en">

<head>
    <title>Document</title>
</head>

<body>
    <script>
        (async () => {
            await setWindowSize(Math.round(window.screen.availHeight), Math.round(window.screen.availWidth));
        })();
    </script>
</body>

</html>

This is also well achieved, and it launched with maximized window. But the problem is the window is first opened at center respect to the height and width set as 300. After resetting the width and height, it simply increases the width and height from the position it launched, is it possible to set the window position to (0,0) or internal way to maximize the window.

dev-swarup avatar Feb 19 '24 16:02 dev-swarup