mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-20 16:47:50 +02:00
Signed-off-by: Denis Gladkiy <denis.gladkiy@hardcoreeng.com>
101 lines
2.9 KiB
TypeScript
101 lines
2.9 KiB
TypeScript
//
|
|
// Copyright © 2025 Hardcore Engineering Inc.
|
|
//
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License. You may
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
//
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
import { BrowserWindow } from 'electron'
|
|
import { MenuBarAction, CommandLogout, CommandSelectWorkspace, CommandOpenSettings } from '../ui/types'
|
|
import { TrayController } from './tray'
|
|
|
|
export function dispatchMenuBarAction (mainWindow: BrowserWindow | undefined, action: MenuBarAction, tray: TrayController | undefined): void {
|
|
if (mainWindow == null) {
|
|
return
|
|
}
|
|
|
|
function performZoom (increment: number): void {
|
|
if (mainWindow == null) {
|
|
return
|
|
}
|
|
const currentZoom = mainWindow.webContents.getZoomFactor()
|
|
mainWindow.webContents.setZoomFactor(currentZoom + increment)
|
|
}
|
|
|
|
const zoomStep = 0.1
|
|
|
|
switch (action) {
|
|
case 'settings':
|
|
mainWindow.webContents.send(CommandOpenSettings)
|
|
break
|
|
case 'select-workspace':
|
|
mainWindow.webContents.send(CommandSelectWorkspace)
|
|
break
|
|
case 'logout':
|
|
mainWindow.webContents.send(CommandLogout)
|
|
break
|
|
case 'exit':
|
|
mainWindow.close()
|
|
break
|
|
case 'undo':
|
|
mainWindow.webContents.undo()
|
|
break
|
|
case 'redo':
|
|
mainWindow.webContents.redo()
|
|
break
|
|
case 'cut':
|
|
mainWindow.webContents.cut()
|
|
break
|
|
case 'copy':
|
|
mainWindow.webContents.copy()
|
|
break
|
|
case 'paste':
|
|
mainWindow.webContents.paste()
|
|
break
|
|
case 'delete':
|
|
mainWindow.webContents.delete()
|
|
break
|
|
case 'select-all':
|
|
mainWindow.webContents.selectAll()
|
|
break
|
|
case 'reload':
|
|
mainWindow?.reload()
|
|
break
|
|
case 'force-reload':
|
|
mainWindow.webContents.reloadIgnoringCache()
|
|
break
|
|
case 'toggle-devtools':
|
|
mainWindow.webContents.toggleDevTools()
|
|
break
|
|
case 'zoom-in':
|
|
performZoom(+zoomStep)
|
|
break
|
|
case 'zoom-out':
|
|
performZoom(-zoomStep)
|
|
break
|
|
case 'restore-size':
|
|
mainWindow.webContents.setZoomFactor(1.0)
|
|
break
|
|
case 'toggle-fullscreen':
|
|
mainWindow.setFullScreen(!mainWindow.isFullScreen())
|
|
break
|
|
case 'toggle-minimize-to-tray': {
|
|
if (tray != null) {
|
|
const newSetting = tray.toggleMinimizeToTray()
|
|
mainWindow.webContents.send('minimize-to-tray-setting-changed', newSetting)
|
|
}
|
|
break
|
|
}
|
|
default:
|
|
console.log('unknown menu action:', action)
|
|
}
|
|
}
|