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 Jan 15, 2017
1 parent 0ece625 commit 76e5c5d
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.reportAnIssueMenuItem = () => {
return {
label: locale.translation('reportAnIssue'),
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…
reportAnIssue=Report an Issue
submitFeedback=Submit Feedback…
bookmarksToolbar=Bookmarks Toolbar
Expand Down
11 changes: 11 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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')

// temporary fix for #4517, #4518 and #4472
app.commandLine.appendSwitch('enable-use-zoom-for-dsf', 'false')
Expand Down Expand Up @@ -722,6 +723,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 @@ -744,6 +750,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 @@ -158,6 +158,7 @@ var rendererIdentifiers = function () {
'settings',
'bookmarksManager',
'importBrowserData',
'exportBookmarks',
'reportAnIssue',
'submitFeedback',
'bookmarksToolbar',
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 76e5c5d

Please sign in to comment.