From 3911b4dfd47c1b83ab4c84c005e411a1d29ba0fd Mon Sep 17 00:00:00 2001 From: ulong32 Date: Thu, 12 Jan 2023 15:37:14 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A2=E3=82=B9=E3=83=9A=E3=82=AF=E3=83=88?= =?UTF-8?q?=E6=AF=94=E5=9B=BA=E5=AE=9A=E6=A9=9F=E8=83=BD=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 103 +++++++++++++++++++++++++++++++++++++---------------- preload.js | 4 +++ 2 files changed, 76 insertions(+), 31 deletions(-) diff --git a/main.js b/main.js index 30cfbea..a52d350 100644 --- a/main.js +++ b/main.js @@ -6,8 +6,9 @@ const { app, BrowserWindow, dialog, Menu, shell, ipcMain } = require('electron') const path = require('path'); let isSetNoTimeout = false; +let isLockAspectRatio = false; let key = null; -let intervalID = null; +let idMainWindow = null; @@ -24,15 +25,53 @@ const createMainWindow = () => { preload: path.join(__dirname, 'preload.js') } }); + idMainWindow = win.id; win.webContents.on('new-window', (e, url) => { shell.openExternal(url); }); - win.loadURL('https://allb-browser.pokelabo.jp/web/play?type=' + configData['playVersion']); - intervalID = setInterval(() => { - if(win.title != 'Shukuchi'){ - win.title = 'Shukuchi' + ipcMain.on('change-fullscreen', () => { + if (win.isFullScreen()){ + win.setFullScreen(false); + win.setMenuBarVisibility(true); + win.setAutoHideMenuBar(false); + } else { + win.setFullScreen(true); + win.setMenuBarVisibility(false); + win.setAutoHideMenuBar(false); + } + }) + let windowSize, contentSize, UISize, edge, currentSize; + win.on('will-resize', (e,size,detail) => { + windowSize = win.getSize(); + contentSize = win.getContentSize(); + UISize = [windowSize[0] - contentSize[0],windowSize[1] - contentSize[1]]; + currentSize = size; + edge = detail.edge; + }) + + win.on('resize', () => { + if(!isLockAspectRatio) return; + switch(edge) { + case 'bottom': + win.setSize(parseInt((currentSize.height - UISize[1]) * 16 / 9) + UISize[0], currentSize.height); + break; + case 'left': + case 'right': + win.setSize(currentSize.width, parseInt((currentSize.width - UISize[0]) * 9 / 16) + UISize[1]); + break; + default : + if(Math.abs(currentSize.height - windowSize[1]) - Math.abs(currentSize.width - windowSize[0]) > 0) { + win.setSize(currentSize.width, parseInt((currentSize.width - UISize[0]) * 9 / 16) + UISize[1]); + } else { + win.setSize(parseInt((currentSize.height - UISize[1]) * 16 / 9) + UISize[0], currentSize.height); + } + break; } - }, 1000); + }) + + win.loadURL('https://allb-browser.pokelabo.jp/web/play?type=' + configData['playVersion']); + + win.setTitle("Shukuchi"); }; @@ -81,6 +120,9 @@ ipcMain.on('close-setting', () => { }) createMainWindow(); }); +ipcMain.on("DOM loaded", () => { + BrowserWindow.fromId(idMainWindow).setTitle('Shukuchi'); +}); const templateMenu = [ { @@ -107,7 +149,6 @@ const templateMenu = [ { label: '全画面表示(&S)', type: 'checkbox', - accelerator: 'F11', click(item, focusedWindow) { if (focusedWindow) { if (focusedWindow.isFullScreen()){ @@ -137,16 +178,11 @@ const templateMenu = [ } }, { - type: 'separator' - }, - { - label: 'アプリのリセット', - role: 'forceReload' - }, - { - label: '開発者ツール', + label: 'アスペクト比固定', type: 'checkbox', - role: 'toggleDevTools' + click() { + isLockAspectRatio = !isLockAspectRatio; + } } ] }, @@ -166,25 +202,30 @@ const templateMenu = [ } } }, + { + label: 'アプリのリセット', + role: 'forceReload' + }, + { + label: '開発者ツール', + type: 'checkbox', + role: 'toggleDevTools' + }, + { + type: 'separator' + }, { label: '設定', click(item, focusedWindow) { key = dialog.showMessageBoxSync( - { - type: 'question', - buttons: ['Yes', 'No'], - title: '確認', - message: '設定画面を開きます', - detail: '設定の反映のため、アプリケーションを一旦終了します。\nよろしいですか?' - }); - - if(key == 0){ - clearInterval(intervalID); - focusedWindow.close(); - createSettingWindow(); - } - - + { + type: 'question', + buttons: ['Yes', 'No'], + title: '確認', + message: '設定画面を開きます', + detail: '設定の反映のため、設定終了後にアプリケーションを再起動します。\nよろしいですか?' + }); + if(key == 0) createSettingWindow(); } } ] diff --git a/preload.js b/preload.js index 527d1c7..11ca2b3 100644 --- a/preload.js +++ b/preload.js @@ -12,6 +12,7 @@ window.addEventListener('DOMContentLoaded', () => { gestureModal.style.display = 'none'; } }, 100); + ipcRenderer.send('DOM loaded'); }); function clickCanvas() { @@ -27,6 +28,9 @@ ipcRenderer.on('no-timeout-false', () => { console.log("click interval clear"); }) +addEventListener('keydown',(e)=> { + if(e.key == "F11") ipcRenderer.send('change-fullscreen'); +})