mirror of
https://github.com/Elvanos/fantasia-archive.git
synced 2024-06-21 11:40:33 +12:00
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
|
/**
|
||
|
* This file is used specifically for security reasons.
|
||
|
* Here you can access Nodejs stuff and inject functionality into
|
||
|
* the renderer thread (accessible there through the "window" object)
|
||
|
*
|
||
|
* WARNING!
|
||
|
* If you import anything from node_modules, then make sure that the package is specified
|
||
|
* in package.json > dependencies and NOT in devDependencies
|
||
|
*
|
||
|
* Example (injects window.myAPI.doAThing() into renderer thread):
|
||
|
*
|
||
|
* import { contextBridge } from 'electron'
|
||
|
*
|
||
|
* contextBridge.exposeInMainWorld('myAPI', {
|
||
|
* doAThing: () => {}
|
||
|
* })
|
||
|
*
|
||
|
* WARNING!
|
||
|
* If accessing Node functionality (like importing @electron/remote) then in your
|
||
|
* electron-main.ts you will need to set the following when you instantiate BrowserWindow:
|
||
|
*
|
||
|
* mainWindow = new BrowserWindow({
|
||
|
* // ...
|
||
|
* webPreferences: {
|
||
|
* // ...
|
||
|
* sandbox: false // <-- to be able to import @electron/remote in preload script
|
||
|
* }
|
||
|
* }
|
||
|
*/
|
||
|
|
||
|
import { contextBridge } from 'electron'
|
||
|
import { BrowserWindow } from '@electron/remote'
|
||
|
|
||
|
contextBridge.exposeInMainWorld('faWindowAPI', {
|
||
|
|
||
|
minimize () {
|
||
|
const currentWindow = BrowserWindow.getFocusedWindow()
|
||
|
|
||
|
if (currentWindow !== null) {
|
||
|
currentWindow.minimize()
|
||
|
}
|
||
|
},
|
||
|
|
||
|
toggleMaximize () {
|
||
|
const currentWindow = BrowserWindow.getFocusedWindow()
|
||
|
|
||
|
if (currentWindow !== null) {
|
||
|
if (currentWindow.isMaximized()) {
|
||
|
currentWindow.unmaximize()
|
||
|
} else {
|
||
|
currentWindow.maximize()
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
close () {
|
||
|
const currentWindow = BrowserWindow.getFocusedWindow()
|
||
|
if (currentWindow !== null) {
|
||
|
currentWindow.close()
|
||
|
}
|
||
|
}
|
||
|
})
|