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 73b25ee7b34..fb87d0de038 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 25ffdac99ef..c63b31114af 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.reportAnIssueMenuItem = () => { return { label: locale.translation('reportAnIssue'), diff --git a/app/extensions/brave/locales/en-US/menu.properties b/app/extensions/brave/locales/en-US/menu.properties index 1a333825a81..2f28175c855 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… reportAnIssue=Report an Issue submitFeedback=Submit Feedback… bookmarksToolbar=Bookmarks Toolbar diff --git a/app/index.js b/app/index.js index 10c632045bd..348e8558bda 100644 --- a/app/index.js +++ b/app/index.js @@ -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') @@ -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) => { @@ -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 }) diff --git a/app/locale.js b/app/locale.js index eca05ddeff9..5bfd263fab7 100644 --- a/app/locale.js +++ b/app/locale.js @@ -158,6 +158,7 @@ var rendererIdentifiers = function () { 'settings', 'bookmarksManager', 'importBrowserData', + 'exportBookmarks', 'reportAnIssue', 'submitFeedback', 'bookmarksToolbar', 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: _,