Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Firefox recovery.jsonlz4 / backup.jsonlz4 / sessionstore.jsonlz4 #884

Merged
merged 4 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lodash": "^4.17.21",
"loglevel": "^1.6.7",
"moment": "^2.24.0",
"mozlz4a": "^1.1.0",
"prop-types": "^15.7.2",
"query-string": "^6.11.1",
"react": "^16.13.1",
Expand All @@ -32,6 +33,7 @@
"@babel/preset-react": "^7.9.4",
"babel-loader": "^8.1.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"buffer": "^6.0.3",
"clean-webpack-plugin": "^0.1.19",
"copy-webpack-plugin": "^9.0.1",
"css-loader": "^6.2.0",
Expand Down
61 changes: 60 additions & 1 deletion src/options/components/ImportSessionsComponent.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import React, { Component } from "react";
import browser from "webextension-polyfill";
import moment from "moment";
import mozlz4a from "mozlz4a";
import uuidv4 from "uuid/v4";
import OptionContainer from "./OptionContainer";


const fileOpen = file => {
if (/(?:\.jsonlz4|\.baklz4)(-\d+)?$/.test(file.name.toLowerCase())) {
// sessionstore.jsonlz4
// previous.jsonlz4
// recovery.baklz4
// upgrade.jsonlz4-20211001010123
return new Promise(resolve => {
const reader = new FileReader();
reader.onload = () => {
let input = new Uint8Array(reader.result);
let output = mozlz4a.decompress(input);
return resolve(convertMozLz4Sessionstore(output));
};
reader.readAsArrayBuffer(file);
});
}

return new Promise(resolve => {
const reader = new FileReader();
reader.onload = () => {
Expand Down Expand Up @@ -167,6 +185,46 @@ const convertSessionManager = file => {
return [session];
};

const convertMozLz4Sessionstore = async file => {
const mozSession = JSON.parse(new TextDecoder().decode(file));
if (!(mozSession.version[0] === 'sessionrestore' && mozSession.version[1] === 1)) {
return;
}

let session = {};
session.windows = {};
session.windowsNumber = 0;
session.tabsNumber = 0;
session.name = 'sessionstore backup ' + moment(mozSession.session.lastUpdate).toLocaleString();
session.date = mozSession.session.lastUpdate;
session.lastEditedTime = Date.now();
session.tag = [];
session.sessionStartTime = mozSession.session.startTime;
session.id = uuidv4();

for (const win in mozSession.windows) {
session.windows[win] = {};
let index = 0;
for (const tab of mozSession.windows[win].tabs) {
const entryIndex = tab.index - 1;
session.windows[win][index] = {
id: index,
index: index,
windowId: parseInt(win),
lastAccessed: tab.lastAccessed,
url: tab.entries[entryIndex].url,
title: tab.entries[entryIndex].title,
favIconUrl: tab.image,
discarded: true,
};
index++;
}
session.tabsNumber += index;
}
session.windowsNumber = Object.keys(session.windows).length;
return [session];
};

const getSessionsState = sessions => {
const sessionLabel = browser.i18n.getMessage("sessionLabel").toLowerCase();
const sessionsLabel = browser.i18n.getMessage("sessionsLabel").toLowerCase();
Expand Down Expand Up @@ -270,12 +328,13 @@ export default class ImportSessionsComponent extends Component {
- Tab Session Manager (.json)<br />
- Session Buddy (.json)<br />
- Session Manager (.session)<br />
- Firefox Session Store Backup (.jsonlz4)<br />
<a href="https://github.com/sienori/Tab-Session-Manager/wiki/Q&A:-How-to-import-sessions-from-other-extensions"
target="_blank">{browser.i18n.getMessage("importCaptionLabel3")} </a>
</p>}
type="file"
value="importButtonLabel"
accept=".json, .session"
accept=".json, .session, .jsonlz4, .baklz4"
multiple={true}
onChange={this.readSessions.bind(this)}
>
Expand Down
7 changes: 5 additions & 2 deletions webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
getCopyPlugins,
getFirefoxCopyPlugins,
getMiniCssExtractPlugin,
getBufferPlugin,
getEntry
} = require("./webpack.utils");
const path = require("path");
Expand Down Expand Up @@ -79,7 +80,8 @@ module.exports = [
plugins: [
...getMiniCssExtractPlugin(),
...getHTMLPlugins("chrome", config.devDirectory, config.chromePath),
...getCopyPlugins("chrome", config.devDirectory, config.chromePath)
...getCopyPlugins("chrome", config.devDirectory, config.chromePath),
...getBufferPlugin(),
]
},
{
Expand All @@ -89,7 +91,8 @@ module.exports = [
plugins: [
...getMiniCssExtractPlugin(),
...getFirefoxCopyPlugins("firefox", config.devDirectory, config.firefoxPath),
...getHTMLPlugins("firefox", config.devDirectory, config.firefoxPath)
...getHTMLPlugins("firefox", config.devDirectory, config.firefoxPath),
...getBufferPlugin(),
]
}
];
7 changes: 5 additions & 2 deletions webpack.config.dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
getZipPlugin,
getFirefoxCopyPlugins,
getMiniCssExtractPlugin,
getBufferPlugin,
getEntry
} = require("./webpack.utils");
const path = require("path");
Expand Down Expand Up @@ -90,7 +91,8 @@ module.exports = [
...getMiniCssExtractPlugin(),
...getHTMLPlugins("chrome", config.tempDirectory, config.chromePath),
...getCopyPlugins("chrome", config.tempDirectory, config.chromePath),
getZipPlugin(`${config.extName}-for-chrome-${extVersion}`, config.distDirectory)
getZipPlugin(`${config.extName}-for-chrome-${extVersion}`, config.distDirectory),
...getBufferPlugin(),
]
},
{
Expand All @@ -105,7 +107,8 @@ module.exports = [
...getMiniCssExtractPlugin(),
...getHTMLPlugins("firefox", config.tempDirectory, config.firefoxPath),
...getFirefoxCopyPlugins("firefox", config.tempDirectory, config.firefoxPath),
getZipPlugin(`${config.extName}-for-firefox-${ffExtVersion}`, config.distDirectory)
getZipPlugin(`${config.extName}-for-firefox-${ffExtVersion}`, config.distDirectory),
...getBufferPlugin(),
]
},
{
Expand Down
8 changes: 8 additions & 0 deletions webpack.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ZipPlugin = require("zip-webpack-plugin");
const path = require("path");
const webpack = require("webpack");

const getHTMLPlugins = (browserDir, outputDir = "dev", sourceDir = "src") => [
new HtmlWebpackPlugin({
Expand Down Expand Up @@ -113,12 +114,19 @@ const getZipPlugin = (browserDir, outputDir = "dist", exclude = "") =>
exclude: exclude
});

const getBufferPlugin = () => [
new webpack.ProvidePlugin({
Buffer: [require.resolve("buffer/"), "Buffer"],
}),
];

module.exports = {
getHTMLPlugins,
getOutput,
getCopyPlugins,
getFirefoxCopyPlugins,
getMiniCssExtractPlugin,
getBufferPlugin,
getZipPlugin,
getEntry
};