From 71789a8ab832f5fb72064297e8c209314674e3b7 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Thu, 12 Jan 2017 11:17:26 +0100 Subject: [PATCH] Added export bookmars functionality Resolves #1002 Auditors: @bbondy @bsclifton Test Plan: - Go to Bookmards menu - Select Export Bookmarks - Select destination - Bookmarks are exported and you see notification --- app/bookmarksExporter.js | 32 +++++++++++++++++++ app/browser/menu.js | 3 +- app/common/commonMenu.js | 13 ++++++++ .../brave/locales/en-US/menu.properties | 1 + app/index.js | 11 +++++++ app/locale.js | 1 + js/constants/messages.js | 1 + 7 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 app/bookmarksExporter.js diff --git a/app/bookmarksExporter.js b/app/bookmarksExporter.js new file mode 100644 index 00000000000..be8a647e05c --- /dev/null +++ b/app/bookmarksExporter.js @@ -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) + } + }) +} diff --git a/app/browser/menu.js b/app/browser/menu.js index e64ed164835..365cc900dc3 100644 --- a/app/browser/menu.js +++ b/app/browser/menu.js @@ -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')) diff --git a/app/common/commonMenu.js b/app/common/commonMenu.js index cc98e58b932..06d1b7bcd43 100644 --- a/app/common/commonMenu.js +++ b/app/common/commonMenu.js @@ -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'), diff --git a/app/extensions/brave/locales/en-US/menu.properties b/app/extensions/brave/locales/en-US/menu.properties index 058836bdee8..d1f2bc412ec 100644 --- a/app/extensions/brave/locales/en-US/menu.properties +++ b/app/extensions/brave/locales/en-US/menu.properties @@ -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 diff --git a/app/index.js b/app/index.js index d9271fc6326..42fb07e4f39 100644 --- a/app/index.js +++ b/app/index.js @@ -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') @@ -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) => { @@ -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 }) diff --git a/app/locale.js b/app/locale.js index 7e17671bdcb..ff3c895bf38 100644 --- a/app/locale.js +++ b/app/locale.js @@ -159,6 +159,7 @@ var rendererIdentifiers = function () { 'settings', 'bookmarksManager', 'importBrowserData', + 'exportBookmarks', 'submitFeedback', 'bookmarksToolbar', 'bravery', diff --git a/js/constants/messages.js b/js/constants/messages.js index 09a284dbc62..86615607f9b 100644 --- a/js/constants/messages.js +++ b/js/constants/messages.js @@ -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: _,