Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

fix: add missing window control permissions Add window control permissions (set-resizable, maximize, minimize, close) to capabilities. These permissions are required for proper window management on macOS. Related to #1112

Tw931776fff1ef9d
diff --git a/dist/cli.js b/dist/cli.js
index e1dfe16f..da4286cf 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -22,7 +22,7 @@ import * as psl from 'psl';
import { InvalidArgumentError, program as program$1, Option } from 'commander';
var name = "pake-cli";
-var version = "3.7.5";
+var version = "3.7.7";
var description = "🤱🏻 Turn any webpage into a desktop app with one command. 🤱🏻 一键打包网页生成轻量桌面应用。";
var engines = {
node: ">=18.0.0"
diff --git a/package.json b/package.json
index 1deddfaa..b1f7456e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "pake-cli",
- "version": "3.7.6",
+ "version": "3.7.7",
"description": "🤱🏻 Turn any webpage into a desktop app with one command. 🤱🏻 一键打包网页生成轻量桌面应用。",
"engines": {
"node": ">=18.0.0"
diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json
index 337dc745..ddc44b5e 100644
--- a/src-tauri/capabilities/default.json
+++ b/src-tauri/capabilities/default.json
@@ -13,6 +13,10 @@
"core:window:allow-toggle-maximize",
"core:window:allow-is-fullscreen",
"core:window:allow-set-fullscreen",
+ "core:window:allow-set-resizable",
+ "core:window:allow-maximize",
+ "core:window:allow-minimize",
+ "core:window:allow-close",
"core:webview:allow-internal-toggle-devtools",
"notification:allow-is-permission-granted",
"notification:allow-notify",
diff --git a/src-tauri/src/inject/component.js b/src-tauri/src/inject/component.js
index f55491d2..f00670e6 100644
--- a/src-tauri/src/inject/component.js
+++ b/src-tauri/src/inject/component.js
@@ -19,3 +19,240 @@ document.addEventListener("DOMContentLoaded", () => {
window.pakeToast = pakeToast;
});
+
+// Polyfill for HTML5 Fullscreen API in Tauri webview
+// This bridges the HTML5 Fullscreen API to Tauri's native window fullscreen
+// Works for all video sites (YouTube, Vimeo, Bilibili, etc.)
+(function () {
+ function initFullscreenPolyfill() {
+ if (!window.__TAURI__ || !document.head) {
+ setTimeout(initFullscreenPolyfill, 100);
+ return;
+ }
+
+ const appWindow = window.__TAURI__.window.getCurrentWindow();
+ let fullscreenElement = null;
+ let actualFullscreenElement = null;
+ let originalStyles = null;
+ let originalParent = null;
+ let originalNextSibling = null;
+ let wasInBody = false;
+
+ // Inject fullscreen styles
+ const styleEl = document.createElement('style');
+ styleEl.id = 'pake-fullscreen-style';
+ styleEl.textContent = `
+ body.pake-fullscreen-active {
+ overflow: hidden !important;
+ }
+ .pake-fullscreen-element {
+ position: fixed !important;
+ top: 0 !important;
+ left: 0 !important;
+ width: 100vw !important;
+ height: 100vh !important;
+ max-width: 100vw !important;
+ max-height: 100vh !important;
+ margin: 0 !important;
+ padding: 0 !important;
+ z-index: 2147483647 !important;
+ background: #000 !important;
+ object-fit: contain !important;
+ }
+ .pake-fullscreen-element video {
+ width: 100% !important;
+ height: 100% !important;
+ object-fit: contain !important;
+ }
+ `;
+ document.head.appendChild(styleEl);
+
+ // Find the actual video element
+ function findMediaElement() {
+ const videos = document.querySelectorAll('video');
+ if (videos.length > 0) {
+ let largestVideo = videos[0];
+ let maxArea = 0;
+ videos.forEach(video => {
+ const rect = video.getBoundingClientRect();
+ const area = rect.width * rect.height;
+ if (area > maxArea || !video.paused) {
+ maxArea = area;
+ largestVideo = video;
+ }
+ });
+ return largestVideo;
+ }
+ return null;
+ }
+
+ // Enter fullscreen
+ function enterFullscreen(element) {
+ fullscreenElement = element;
+
+ // If html/body element, find the video instead
+ let targetElement = element;
+ if (element === document.documentElement || element === document.body) {
+ const mediaElement = findMediaElement();
+ if (mediaElement) {
+ targetElement = mediaElement;
+ actualFullscreenElement = mediaElement;
+ } else {
+ actualFullscreenElement = element;
+ }
+ } else {
+ actualFullscreenElement = element;
+ }
+
+ // Save original state
+ originalStyles = {
+ position: targetElement.style.position,
+ top: targetElement.style.top,
+ left: targetElement.style.left,
+ width: targetElement.style.width,
+ height: targetElement.style.height,
+ maxWidth: targetElement.style.maxWidth,
+ maxHeight: targetElement.style.maxHeight,
+ margin: targetElement.style.margin,
+ padding: targetElement.style.padding,
+ zIndex: targetElement.style.zIndex,
+ background: targetElement.style.background,
+ objectFit: targetElement.style.objectFit,
+ };
+
+ wasInBody = targetElement.parentNode === document.body;
+ if (!wasInBody) {
+ originalParent = targetElement.parentNode;
+ originalNextSibling = targetElement.nextSibling;
+ }
+
+ // Apply fullscreen
+ targetElement.classList.add('pake-fullscreen-element');
+ document.body.classList.add('pake-fullscreen-active');
+
+ if (!wasInBody) {
+ document.body.appendChild(targetElement);
+ }
+
+ // Fullscreen window
+ appWindow.setFullscreen(true).then(() => {
+ const event = new Event('fullscreenchange', { bubbles: true });
+ document.dispatchEvent(event);
+ element.dispatchEvent(event);
+
+ const webkitEvent = new Event('webkitfullscreenchange', { bubbles: true });
+ document.dispatchEvent(webkitEvent);
+ element.dispatchEvent(webkitEvent);
+ });
+
+ return Promise.resolve();
+ }
+
+ // Exit fullscreen
+ function exitFullscreen() {
+ if (!fullscreenElement) {
+ return Promise.resolve();
+ }
+
+ const exitingElement = fullscreenElement;
+ const targetElement = actualFullscreenElement;
+
+ // Restore styles and position
+ targetElement.classList.remove('pake-fullscreen-element');
+ document.body.classList.remove('pake-fullscreen-active');
+
+ if (originalStyles) {
+ Object.keys(originalStyles).forEach(key => {
+ targetElement.style[key] = originalStyles[key];
+ });
+ }
+
+ if (!wasInBody && originalParent) {
+ if (originalNextSibling && originalNextSibling.parentNode === originalParent) {
+ originalParent.insertBefore(targetElement, originalNextSibling);
+ } else if (originalParent.isConnected) {
+ originalParent.appendChild(targetElement);
+ }
+ }
+
+ // Reset state
+ fullscreenElement = null;
+ actualFullscreenElement = null;
+ originalStyles = null;
+ originalParent = null;
+ originalNextSibling = null;
+ wasInBody = false;
+
+ // Exit window fullscreen
+ return appWindow.setFullscreen(false).then(() => {
+ const event = new Event('fullscreenchange', { bubbles: true });
+ document.dispatchEvent(event);
+ exitingElement.dispatchEvent(event);
+
+ const webkitEvent = new Event('webkitfullscreenchange', { bubbles: true });
+ document.dispatchEvent(webkitEvent);
+ exitingElement.dispatchEvent(webkitEvent);
+ });
+ }
+
+ // Override fullscreenEnabled
+ Object.defineProperty(document, 'fullscreenEnabled', {
+ get: () => true,
+ configurable: true
+ });
+ Object.defineProperty(document, 'webkitFullscreenEnabled', {
+ get: () => true,
+ configurable: true
+ });
+
+ // Override fullscreenElement
+ Object.defineProperty(document, 'fullscreenElement', {
+ get: () => fullscreenElement,
+ configurable: true
+ });
+ Object.defineProperty(document, 'webkitFullscreenElement', {
+ get: () => fullscreenElement,
+ configurable: true
+ });
+ Object.defineProperty(document, 'webkitCurrentFullScreenElement', {
+ get: () => fullscreenElement,
+ configurable: true
+ });
+
+ // Override requestFullscreen
+ Element.prototype.requestFullscreen = function () {
+ return enterFullscreen(this);
+ };
+ Element.prototype.webkitRequestFullscreen = function () {
+ return enterFullscreen(this);
+ };
+ Element.prototype.webkitRequestFullScreen = function () {
+ return enterFullscreen(this);
+ };
+
+ // Override exitFullscreen
+ document.exitFullscreen = exitFullscreen;
+ document.webkitExitFullscreen = exitFullscreen;
+ document.webkitCancelFullScreen = exitFullscreen;
+
+ // Handle Escape key
+ document.addEventListener('keydown', (e) => {
+ if (e.key === 'Escape' && fullscreenElement) {
+ exitFullscreen();
+ }
+ }, true);
+
+ // Monitor window fullscreen changes
+ let lastFullscreenState = false;
+ setInterval(() => {
+ appWindow.isFullscreen().then(isFullscreen => {
+ if (lastFullscreenState && !isFullscreen && fullscreenElement) {
+ exitFullscreen();
+ }
+ lastFullscreenState = isFullscreen;
+ }).catch(() => {});
+ }, 500);
+ }
+
+ initFullscreenPolyfill();
+})();