Skip to content

Commit

Permalink
Added export bookmars functionality
Browse files Browse the repository at this point in the history
Resolves brave#1002

Auditors:
@bbondy @bsclifton

Test Plan:
- Go to Bookmards menu
- Select Export Bookmarks
- Select destination
- Bookmarks are exported and you see notification
  • Loading branch information
NejcZdovc committed Feb 2, 2017
1 parent c82af5a commit ae9d0db
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 1 deletion.
32 changes: 32 additions & 0 deletions app/bookmarksExporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

'strict mode'

const electron = require('electron')
const dialog = electron.dialog
const app = electron.app
const BrowserWindow = electron.BrowserWindow
const path = require('path')
const moment = require('moment')
const getSetting = require('../js/settings').getSetting
const settings = require('../js/constants/settings')

module.exports.dialog = () => {
const focusedWindow = BrowserWindow.getFocusedWindow()
const fileName = moment().format('DD_MM_YYYY') + '.html'
const defaultPath = path.join(getSetting(settings.DEFAULT_DOWNLOAD_SAVE_PATH) || app.getPath('downloads'), fileName)

dialog.showSaveDialog(focusedWindow, {
defaultPath: defaultPath,
filters: [{
name: 'HTML',
extensions: ['html']
}]
}, (filePath) => {
if (filePath) {
console.log(filePath)
}
})
}
3 changes: 2 additions & 1 deletion app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ const createBookmarksSubmenu = () => {
CommonMenu.bookmarksManagerMenuItem(),
CommonMenu.bookmarksToolbarMenuItem(),
CommonMenu.separatorMenuItem,
CommonMenu.importBrowserDataMenuItem()
CommonMenu.importBrowserDataMenuItem(),
CommonMenu.exportBookmarksMenuItem()
]

const bookmarks = menuUtil.createBookmarkTemplateItems(appStore.getState().get('sites'))
Expand Down
13 changes: 13 additions & 0 deletions app/common/commonMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ module.exports.importBrowserDataMenuItem = () => {
}
}

module.exports.exportBookmarksMenuItem = () => {
return {
label: locale.translation('exportBookmarks'),
click: function (item, focusedWindow) {
if (process.type === 'browser') {
process.emit(messages.EXPORT_BOOKMARKS)
} else {
electron.ipcRenderer.send(messages.EXPORT_BOOKMARKS)
}
}
}
}

module.exports.submitFeedbackMenuItem = () => {
return {
label: locale.translation('submitFeedback'),
Expand Down
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/menu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ preferences=Preferences…
settings=Settings…
bookmarksManager=Bookmarks Manager…
importBrowserData=Import Browser Data…
exportBookmarks=Export Bookmarks…
submitFeedback=Submit Feedback…
bookmarksToolbar=Bookmarks Toolbar
bravery=Shields
Expand Down
11 changes: 11 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const contentSettings = require('../js/state/contentSettings')
const privacy = require('../js/state/privacy')
const async = require('async')
const settings = require('../js/constants/settings')
const BookmarksExporter = require('./bookmarksExporter')

app.commandLine.appendSwitch('enable-features', 'BlockSmallPluginContent,PreferHtmlOverPlugins')

Expand Down Expand Up @@ -725,6 +726,11 @@ app.on('ready', () => {
Importer.init()
})

// TODO check if needed
ipcMain.on(messages.EXPORT_BOOKMARKS, () => {
BookmarksExporter.dialog()
})

// This loads package.json into an object
// TODO: Seems like this can be done with app.getVersion() insteand?
PackageLoader.load((err, pack) => {
Expand All @@ -747,6 +753,11 @@ app.on('ready', () => {
process.on(messages.IMPORT_BROWSER_DATA_NOW, () => {
Importer.init()
})

// This is fired by a menu entry
process.on(messages.EXPORT_BOOKMARKS, () => {
BookmarksExporter.dialog()
})
})
ready = true
})
Expand Down
1 change: 1 addition & 0 deletions app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ var rendererIdentifiers = function () {
'settings',
'bookmarksManager',
'importBrowserData',
'exportBookmarks',
'submitFeedback',
'bookmarksToolbar',
'bravery',
Expand Down
1 change: 1 addition & 0 deletions js/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const messages = {
ABOUT_COMPONENT_INITIALIZED: _,
CLEAR_BROWSING_DATA_NOW: _,
IMPORT_BROWSER_DATA_NOW: _,
EXPORT_BOOKMARKS: _,
IMPORTER_LIST: _,
// Autofill
AUTOFILL_SET_ADDRESS: _,
Expand Down

0 comments on commit ae9d0db

Please sign in to comment.