Skip to content

Commit f8a7d2d

Browse files
committed
fix bug
1 parent 2124e8d commit f8a7d2d

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
"version": "0.0.1",
44
"description": "A browser extension that takes screenshots",
55
"license": "MIT",
6-
"repository": {
7-
"type": "git",
8-
"url": "https://github.com/lxieyang/chrome-extension-boilerplate-react.git"
9-
},
106
"scripts": {
117
"build": "node utils/build.js",
128
"start": "node utils/webserver.js",

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"icons": {
1414
"128": "icon-128.png"
1515
},
16-
"permissions": ["tabs", "downloads", "<all_urls>", "storage"],
16+
"permissions": ["tabs", "downloads", "<all_urls>", "storage", "activeTab"],
1717
"content_scripts": [
1818
{
1919
"matches": ["http://*/*", "https://*/*", "<all_urls>"],

src/pages/Background/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import '../../assets/img/icon-34.png';
22
import '../../assets/img/icon-128.png';
3+
import { defaults } from '../../shared/defaults';
34
import imageClipper from './image-clipper.js';
45

6+
chrome.storage.sync.set({ openInTab: defaults.openInTab });
7+
chrome.storage.sync.set({ download: defaults.download });
8+
59
const getImageDimensions = (file) => {
610
return new Promise(function (resolved, rejected) {
711
var img = new Image();
@@ -19,6 +23,9 @@ chrome.browserAction.setTitle({
1923

2024
chrome.browserAction.onClicked.addListener(function () {
2125
chrome.tabs.captureVisibleTab(function (screenshotUrl) {
26+
if (!screenshotUrl) {
27+
return;
28+
}
2229
chrome.storage.sync.get(['download', 'openInTab'], (result) => {
2330
// download image
2431
if (result.download) {
@@ -43,6 +50,9 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
4350
let rect = request.rect;
4451
let windowSize = request.windowSize;
4552
chrome.tabs.captureVisibleTab(function (screenshotUrl) {
53+
if (!screenshotUrl) {
54+
return;
55+
}
4656
getImageDimensions(screenshotUrl).then((imageDimensions) => {
4757
let scale = imageDimensions.w / windowSize.width;
4858
let x = Math.floor(rect.x * scale);

src/pages/Options/Options.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import React, { useState, useEffect } from 'react';
2+
import { defaults } from '../../shared/defaults';
23
import './Options.css';
34

45
const Options: React.FC = () => {
5-
const [openInTab, setOpenInTab] = useState(true);
6+
const [openInTab, setOpenInTab] = useState(false);
67
const [download, setDownload] = useState(false);
78

89
useEffect(() => {
910
chrome.storage.sync.get(['openInTab'], (result) => {
1011
if (result.openInTab === undefined) {
11-
chrome.storage.sync.set({ openInTab });
12+
chrome.storage.sync.set({ openInTab: defaults.openInTab });
1213
} else {
1314
setOpenInTab(result.openInTab);
1415
}
1516
});
1617

1718
chrome.storage.sync.get(['download'], (result) => {
1819
if (result.download === undefined) {
19-
chrome.storage.sync.set({ download });
20+
chrome.storage.sync.set({ download: defaults.download });
2021
} else {
2122
setDownload(result.download);
2223
}

src/shared/defaults.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const defaults = {
2+
openInTab: true,
3+
download: false,
4+
};

0 commit comments

Comments
 (0)