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 28, 2017
1 parent 3a75059 commit 71789a8
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)

This comment has been minimized.

Copy link
@bbondy

bbondy Jan 28, 2017

This is still TODO for the actual export right? This is the front end part only for now I think. Please prefix the PR with WIP for now because we won't be able to land it until we have a call to do it. Thanks for the PR!

This comment has been minimized.

Copy link
@NejcZdovc

NejcZdovc Jan 28, 2017

Author Owner

@bbondy This PR is finished, but this is my first commit that you were checking out, this PR has 3 commits. I prefer to have multiple commits when developing and only after PR is confirmed I squashed commits into one so that when it is merged into the master, git log tree is clean. If you prefer I can squash it, in the future, after PR is done and ready for review. Would you like me to squash this PR now?

Commit explanations:
1 commit: front-end implementation
2 commit: logic implementation
3 commit: test's added

This comment has been minimized.

Copy link
@bbondy

bbondy Jan 29, 2017

cool, thanks!

}
})
}
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')

// temporary fix for #4517, #4518 and #4472
app.commandLine.appendSwitch('enable-use-zoom-for-dsf', 'false')
Expand Down Expand Up @@ -727,6 +728,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 @@ -749,6 +755,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 71789a8

Please sign in to comment.