更新
更旧
/**
*
* Copyright (c) 2020 Silicon Labs
*
* Licensed under the Apache 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
*
* http://www.apache.org/licenses/LICENSE-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.
*/
const queryGeneric = require('../db/query-generic.js')
const querySession = require('../db/query-session.js')
const uiJs = require('./ui-util.js')
const preference = require('../main-process/preference.js')
const about = require('../main-process/about.js')
const dbEnum = require('../../src-shared/db-enum.js')
const commonUrl = require('../../src-shared/common-url.js')
const newConfiguration = 'New Configuration'
const template = (db, httpPort) => [
accelerator: 'CmdOrCtrl+N',
uiJs.openNewConfiguration(menuItem.httpPort)
label: 'Open File...',
accelerator: 'CmdOrCtrl+O',
label: 'Save',
accelerator: 'CmdOrCtrl+S',
click(menuItem, browserWindow, event) {
doSave(menuItem.db, browserWindow)
},
},
{
label: 'Save As...',
click(menuItem, browserWindow, event) {
doSaveAs(menuItem.db, browserWindow)
preference.createOrShowPreferencesWindow(
browserWindow,
menuItem.httpPort
)
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
type: 'separator',
},
{
role: 'close',
},
{
type: 'separator',
},
{
role: 'quit',
},
],
},
{
role: 'editMenu',
},
{
role: 'viewMenu',
},
{
role: 'windowMenu',
},
{
label: 'Help',
submenu: [
{
label: 'Documentation',
click(menuItem, browserWindow, event) {
shell.openExternal(commonUrl.documentationUrl)
},
},
{
label: 'User and session information',
getUserSessionInfoMessage(menuItem.db, browserWindow)
.then((msg) => {
dialog.showMessageBox(browserWindow, {
title: 'User and session information',
message: msg,
.catch((err) => uiJs.showErrorMessage('Session info', err))
{
label: 'Renderer API information',
click(menuItem, browserWindow, event) {
browserApi.getRendererApiInformation(browserWindow).then((msg) => {
dialog.showMessageBox(browserWindow, {
title: 'Renderer API information',
message: msg,
buttons: ['Dismiss'],
})
})
},
},
{
label: 'Start progress',
click(menuItem, browserWindow) {
browserApi.progressStart(browserWindow, 'Test progress indication.')
},
},
{
label: 'End progress',
click(menuItem, browserWindow) {
browserApi.progressEnd(browserWindow)
},
},
label: 'About',
click(menuItem, browserWindow, event) {
about.createOrShowAboutWindow(browserWindow, menuItem.httpPort)
async function getUserSessionInfoMessage(db, browserWindow) {
let userKey = await browserApi.getUserKeyFromBrowserWindow(browserWindow)
let session = await querySession.getSessionInfoFromSessionKey(db, userKey)
let sessionUuid = await browserApi.getSessionUuidFromBrowserWindow(
browserWindow
)
return `
Browser session UUID: ${sessionUuid}
Browser user key: ${userKey}
Session id: ${session.sessionId}
Session creationTime: ${new Date(session.creationTime)}
Session session key: ${session.sessionKey}
`
}
/**
* Perform a file->open operation.
*
* @param {*} menuItem
* @param {*} browserWindow
* @param {*} event
*/
.selectFileLocation(db, dbEnum.fileLocationCategory.save)
let opts = {
properties: ['openFile', 'multiSelections'],
}
if (filePath != null) {
opts.defaultPath = filePath
}
return dialog.showOpenDialog(opts)
})
.catch((err) => uiJs.showErrorMessage('Open file', err))
/**
* Perform a save, defering to save as if file is not yet selected.
*
* @param {*} menuItem
* @param {*} browserWindow
* @param {*} event
*/
function doSave(db, browserWindow) {
if (browserWindow.getTitle().includes(newConfiguration)) {
} else {
fileSave(browserWindow, null)
}
}
/**
* Perform save as.
*
* @param {*} menuItem
* @param {*} browserWindow
* @param {*} event
*/
function doSaveAs(db, browserWindow) {
.selectFileLocation(db, dbEnum.fileLocationCategory.save)
let opts = {
filters: [
{ name: 'ZAP Config', extensions: ['zap'] },
{ name: 'All Files', extensions: ['*'] },
],
}
if (filePath != null) {
opts.defaultPath = filePath
return dialog.showSaveDialog(opts)
})
.then((result) => {
fileSave(browserWindow, result.filePath)
return result.filePath
queryGeneric.insertFileLocation(
filePath,
dbEnum.fileLocationCategory.save
)
.catch((err) => uiJs.showErrorMessage('Save file', err))
* @param {*} browserWindow
* @param {*} filePath
* @returns Promise of saving.
*/
function fileSave(browserWindow, filePath) {
browserApi.executeSave(browserWindow, filePath)
* Perform the do open action, possibly reading in multiple files.
uiJs.openFileConfiguration(filePath, httpPort)
/**
* Initialize a menu.
*
* @export
* @param {*} port
*/
function initMenu(db, httpPort) {
const menu = Menu.buildFromTemplate(template(db, httpPort))
exports.newConfiguration = newConfiguration