Skip to content

Commit

Permalink
Merge branch 'dd-87-ensure-name-in-bridge'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhihaoSAR committed Feb 11, 2021
2 parents c106538 + 328eb09 commit 5661226
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 115 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
5 changes: 1 addition & 4 deletions src/renderer/components/LoginPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,7 @@ export default {
.identify({
userId: undefined,
platform: 'desktop',
email: 'email',
traits: {
storage_used: ConfigStore.get('usage')
}
email: 'email'
})
.then(() => {
analytics.track({
Expand Down
14 changes: 11 additions & 3 deletions src/renderer/logic/sync/OneWayUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ConfigStore from '../../../main/config-store'
import SpaceUsage from '../utils/spaceusage'

import analytics from '../utils/analytics'
import { listenerCount } from 'nedb'

/*
* Sync Method: One Way, from LOCAL to CLOUD (Only Upload)
Expand All @@ -27,8 +28,10 @@ let lastSyncFailed = false
let timeoutInstance = null

function syncStop() {
ConfigStore.set('isSyncing', false)
ConfigStore.set('stopSync', true)
if (ConfigStore.get('isSyncing')) {
ConfigStore.set('isSyncing', false)
ConfigStore.set('stopSync', true)
}
app.emit('sync-off')
}

Expand Down Expand Up @@ -214,13 +217,18 @@ async function SyncLogic(callback) {
next =>
Uploader.uploadNewFiles()
.then(() => {
const limit = ConfigStore.get('limit') / 1024
const used = ConfigStore.get('usage') / 1024
const usage = Math.round(1000 * used / limit) / 10
analytics
.identify({
userId: undefined,
platform: 'desktop',
email: 'email',
traits: {
storage_used: ConfigStore.get('usage')
storage_used: used,
storage_limit: limit,
storage_usage: usage
}
})
.catch(err => {
Expand Down
13 changes: 10 additions & 3 deletions src/renderer/logic/sync/TwoWaySync.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ let timeoutInstance = null
const { app } = electron.remote

function syncStop() {
ConfigStore.set('isSyncing', false)
ConfigStore.set('stopSync', true)
if (ConfigStore.get('isSyncing')) {
ConfigStore.set('isSyncing', false)
ConfigStore.set('stopSync', true)
}
app.emit('sync-off')
}

Expand Down Expand Up @@ -233,13 +235,18 @@ async function SyncLogic(callback) {
// Search new files in local folder, and upload them
Uploader.uploadNewFiles()
.then(() => {
const limit = ConfigStore.get('limit') / 1024
const used = ConfigStore.get('usage') / 1024
const usage = Math.round(1000 * used / limit) / 10
analytics
.identify({
userId: undefined,
platform: 'desktop',
email: 'email',
traits: {
storage_used: ConfigStore.get('usage')
storage_used: used,
storage_limit: limit,
storage_usage: usage
}
})
.catch(err => {
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/logic/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ function getListFromFolder(folderPath) {

if (typeof invalid === 'undefined') {
results.push(data.fullPath)
} else {
console.log('ignored')
}
})
.on('warn', warn => Logger.error('READDIRP non-fatal error', warn))
Expand Down
Loading

0 comments on commit 5661226

Please sign in to comment.