Skip to content

Commit

Permalink
hide some item of traymenu when user is not sign-in
Browse files Browse the repository at this point in the history
  • Loading branch information
zhihaoSAR committed Feb 11, 2021
1 parent 065d1ae commit 328eb09
Showing 1 changed file with 99 additions and 92 deletions.
191 changes: 99 additions & 92 deletions src/main/traymenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,115 +75,122 @@ class TrayMenu {
const userFooter = [
{
type: 'separator'
},
{
label: 'Change sync folder',
click: function() {
const newDir = dialog.showOpenDialogSync({
properties: ['openDirectory']
})
if (newDir && newDir.length > 0 && fs.existsSync(newDir[0])) {
app.emit('new-folder-path', newDir[0])
} else {
Logger.info('Sync folder change error or cancelled')
}
}
}
]
if (userEmail) {
userFooter.push(
{
label: 'Change sync folder',
click: function () {
const newDir = dialog.showOpenDialogSync({
properties: ['openDirectory']
})
if (newDir && newDir.length > 0 && fs.existsSync(newDir[0])) {
app.emit('new-folder-path', newDir[0])
} else {
Logger.info('Sync folder change error or cancelled')
}
}
})
}

userMenu = Array.concat(userEmailDisplay, userUsage, userFooter)
}

const contextMenuTemplate = [
{
const contextMenuTemplate = []
if (userEmail) {
contextMenuTemplate.push({
label: 'Open folder',
click: function() {
click: function () {
app.emit('open-folder')
}
},
{
label: 'Sync options',
enabled: true,
submenu: [
{
label: 'Two Way Sync',
type: 'radio',
enabled: true,
checked: ConfigStore.get('syncMode') === 'two-way',
click: () => {
Logger.info('User switched to two way sync mode')
ConfigStore.set('syncMode', 'two-way')
app.emit('sync-stop')
app.emit('switch-mode')
}
},
{
label: 'Upload Only Mode',
type: 'radio',
enabled: true,
checked: ConfigStore.get('syncMode') === 'one-way-upload',
click: () => {
Logger.info('User switched to one way upload mode')
ConfigStore.set('syncMode', 'one-way-upload')
app.emit('sync-stop')
}
})
}
contextMenuTemplate.push({
label: 'Sync options',
enabled: true,
submenu: [
{
label: 'Two Way Sync',
type: 'radio',
enabled: true,
checked: ConfigStore.get('syncMode') === 'two-way',
click: () => {
Logger.info('User switched to two way sync mode')
ConfigStore.set('syncMode', 'two-way')
app.emit('sync-stop')
app.emit('switch-mode')
}
]
},
{
label: 'Force sync',
click: function() {
app.emit('force-sync')
}
},
{
label: 'Open logs',
click: function() {
try {
const logFile = electronLog.transports.file.getFile().path
const logPath = path.dirname(logFile)
shell.openItem(logPath)
} catch (e) {
Logger.error('Error opening log path: %s', e.message)
},
{
label: 'Upload Only Mode',
type: 'radio',
enabled: true,
checked: ConfigStore.get('syncMode') === 'one-way-upload',
click: () => {
Logger.info('User switched to one way upload mode')
ConfigStore.set('syncMode', 'one-way-upload')
app.emit('sync-stop')
}
}
},
{
label: 'Billing',
click: function() {
shell.openExternal(`${process.env.API_URL}/storage`)
}
},
{
label: 'Launch at login',
type: 'checkbox',
checked: ConfigStore.get('autoLaunch'),
click: function(check) {
ConfigStore.set('autoLaunch', check.checked)
console.log(check.checked)
app.emit('change-auto-launch')
]
})
if (userEmail) {
contextMenuTemplate.push({
label: 'Force sync',
click: function () {
app.emit('force-sync')
}
},
{
label: 'Contact Support',
click: function() {
shell.openExternal(`mailto:[email protected]?subject=Support Ticket&body=If you want to upload log files to our tech teams. Please, find them on the Open Logs option in the menu.`)
})
}
contextMenuTemplate.push({
label: 'Open logs',
click: function () {
try {
const logFile = electronLog.transports.file.getFile().path
const logPath = path.dirname(logFile)
shell.openItem(logPath)
} catch (e) {
Logger.error('Error opening log path: %s', e.message)
}
},
{
type: 'separator'
},
{
}
}, {
label: 'Billing',
click: function () {
shell.openExternal(`${process.env.API_URL}/storage`)
}
}, {
label: 'Launch at login',
type: 'checkbox',
checked: ConfigStore.get('autoLaunch'),
click: function (check) {
ConfigStore.set('autoLaunch', check.checked)
console.log(check.checked)
app.emit('change-auto-launch')
}
}, {
label: 'Contact Support',
click: function () {
shell.openExternal(`mailto:[email protected]?subject=Support Ticket&body=If you want to upload log files to our tech teams. Please, find them on the Open Logs option in the menu.`)
}
},
{
type: 'separator'
})

if (userEmail) {
contextMenuTemplate.push({
label: 'Log out',
click: function() {
click: function () {
app.emit('user-logout')
}
},
{
label: 'Quit',
click: this.appClose
}
]
})
}
contextMenuTemplate.push({
label: 'Quit',
click: this.appClose
})

return Menu.buildFromTemplate(Array.concat(userMenu, contextMenuTemplate))
}

Expand Down

0 comments on commit 328eb09

Please sign in to comment.