better window handeling

This commit is contained in:
Daniel Haller 2024-04-30 03:20:47 +02:00
parent 1aab3ffbf4
commit e788e5374d
7 changed files with 103 additions and 52 deletions

View File

@ -811,4 +811,17 @@ select {
-webkit-appearance: none !important; -webkit-appearance: none !important;
appearance: none !important; appearance: none !important;
} }
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
body {
animation: fadein 0.5s;
}
</style> </style>

View File

@ -72,4 +72,17 @@ const login = async () => {
font-weight: 1000; font-weight: 1000;
font-style: normal; font-style: normal;
} }
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
body {
animation: fadein 0.5s;
}
</style> </style>

View File

@ -72,4 +72,17 @@ const login = async () => {
font-weight: 1000; font-weight: 1000;
font-style: normal; font-style: normal;
} }
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
body {
animation: fadein 0.5s;
}
</style> </style>

View File

@ -196,4 +196,17 @@ body {
left: 0%; left: 0%;
} }
} }
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
body {
animation: fadein 0.5s;
}
</style> </style>

View File

@ -28,4 +28,17 @@ const options = ref(["Main", "Output", "Naming", "Crunchyroll", "About"]);
const activeIndex = ref(0); const activeIndex = ref(0);
</script> </script>
<style></style> <style>
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
body {
animation: fadein 0.5s;
}
</style>

View File

@ -13,9 +13,8 @@ process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true'
const isProduction = process.env.NODE_ENV !== 'development' const isProduction = process.env.NODE_ENV !== 'development'
const platform: 'darwin' | 'win32' | 'linux' = process.platform as any const platform: 'darwin' | 'win32' | 'linux' = process.platform as any
const architucture: '64' | '32' = os.arch() === 'x64' ? '64' : '32' const architucture: '64' | '32' = os.arch() === 'x64' ? '64' : '32'
const headerSize = 32
const modules = [titleBarActionsModule, macMenuModule, updaterModule] const modules = [titleBarActionsModule, macMenuModule, updaterModule]
var mainWindow: BrowserWindow; var mainWindow: BrowserWindow
function createWindow() { function createWindow() {
console.log('System info', { isProduction, platform, architucture }) console.log('System info', { isProduction, platform, architucture })
@ -34,50 +33,32 @@ function createWindow() {
titleBarOverlay: { titleBarOverlay: {
color: 'rgba(0,0,0,0)', color: 'rgba(0,0,0,0)',
symbolColor: '#ffffff', symbolColor: '#ffffff',
height: 40, height: 40
}, },
resizable: false, resizable: false,
fullscreen: false, fullscreen: false,
maximizable: false, maximizable: false,
vibrancy: 'fullscreen-ui', vibrancy: 'fullscreen-ui',
backgroundMaterial: 'acrylic', backgroundMaterial: 'acrylic',
}) show: false
mainWindow.webContents.setWindowOpenHandler(() => {
return {
action: 'allow',
overrideBrowserWindowOptions: {
icon: __dirname + '/icon/favicon.ico',
backgroundColor: '#111111',
webPreferences: {
devTools: true,
nodeIntegration: true,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
},
titleBarStyle: 'hidden',
titleBarOverlay: {
color: '#111111',
symbolColor: '#ffffff',
height: 40
},
resizable: false,
fullscreen: false,
maximizable: false,
vibrancy: 'fullscreen-ui',
backgroundMaterial: 'acrylic',
}
}
}) })
mainWindow.on('blur', () => { mainWindow.on('blur', () => {
mainWindow.setBackgroundColor('#00000000') mainWindow.setBackgroundColor('#00000000')
}) })
mainWindow.on('focus', () => { mainWindow.on('focus', () => {
mainWindow.setBackgroundColor('#00000000') mainWindow.setBackgroundColor('#00000000')
}) })
mainWindow.once('ready-to-show', () => {
mainWindow.show()
})
mainWindow.on('closed', () => {
app.quit()
})
// Lock app to single instance // Lock app to single instance
if (singleInstance(app, mainWindow)) return if (singleInstance(app, mainWindow)) return
@ -93,14 +74,13 @@ function createWindow() {
// App events // App events
// ========== // ==========
app.whenReady().then(async () => { app.whenReady().then(async () => {
startAPI() startAPI()
const mainWindow = createWindow() const mainWindow = createWindow()
if (!mainWindow) return if (!mainWindow) return
// Load renderer process // Load renderer process
dynamicRenderer(mainWindow) await dynamicRenderer(mainWindow)
// Initialize modules // Initialize modules
console.log('-'.repeat(30) + '\n[+] Loading modules...') console.log('-'.repeat(30) + '\n[+] Loading modules...')
@ -113,13 +93,6 @@ app.whenReady().then(async () => {
}) })
console.log('[!] Loading modules: Done.' + '\r\n' + '-'.repeat(30)) console.log('[!] Loading modules: Done.' + '\r\n' + '-'.repeat(30))
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
// if (BrowserWindow.getAllWindows().length === 0) createWindow()
mainWindow.show()
})
}) })
export async function messageBox( export async function messageBox(
@ -143,9 +116,7 @@ export async function messageBox(
console.log(response) console.log(response)
} }
export async function setProgressBar( export async function setProgressBar(c: number) {
c: number
) {
mainWindow.setProgressBar(c) mainWindow.setProgressBar(c)
} }
@ -190,6 +161,8 @@ app.on('window-all-closed', () => {
} }
}) })
const openWindows = new Map();
// Open New Window // Open New Window
ipcMain.handle( ipcMain.handle(
'window:openNewWindow', 'window:openNewWindow',
@ -202,7 +175,13 @@ ipcMain.handle(
height: number height: number
} }
) => { ) => {
const mainWindow = new BrowserWindow({ if (openWindows.has(opt.title)) {
const existingWindow = openWindows.get(opt.title);
existingWindow.focus();
return;
}
const newWindow = new BrowserWindow({
title: opt.title, title: opt.title,
icon: __dirname + '/icon/favicon.ico', icon: __dirname + '/icon/favicon.ico',
width: opt.width, width: opt.width,
@ -224,12 +203,19 @@ ipcMain.handle(
maximizable: false, maximizable: false,
vibrancy: 'fullscreen-ui', vibrancy: 'fullscreen-ui',
backgroundMaterial: 'acrylic', backgroundMaterial: 'acrylic',
}) show: false
});
mainWindow.webContents.once('did-finish-load', () => { newWindow.once('ready-to-show', () => {
mainWindow.show() newWindow.show();
}) });
mainWindow.loadURL(opt.url) newWindow.loadURL(opt.url);
openWindows.set(opt.title, newWindow);
newWindow.on('closed', () => {
openWindows.delete(opt.title);
});
} }
) );

View File

@ -11,7 +11,7 @@ const isProduction = process.env.NODE_ENV !== 'development'
// Dynamic Renderer // Dynamic Renderer
// ================ // ================
export default function (mainWindow: BrowserWindow) { export default async function (mainWindow: BrowserWindow) {
if (!isProduction) return mainWindow.loadURL('http://localhost:3000/') if (!isProduction) return mainWindow.loadURL('http://localhost:3000/')
const app = express() const app = express()
app.use('/', serveStatic(path.join(__dirname, '../../public'))) app.use('/', serveStatic(path.join(__dirname, '../../public')))