mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-27 00:19:55 +03:00
More work
This commit is contained in:
parent
c80473329e
commit
ca68117921
|
@ -28,7 +28,8 @@
|
||||||
"test:app": "cross-env BABEL_ENV=test jest test/app",
|
"test:app": "cross-env BABEL_ENV=test jest test/app",
|
||||||
"test:chrome": "jest test/chrome",
|
"test:chrome": "jest test/chrome",
|
||||||
"test:electron": "jest test/electron",
|
"test:electron": "jest test/electron",
|
||||||
"test": "npm run test:app && npm run build:extension && npm run test:chrome && npm run test:electron"
|
"test": "npm run test:app && npm run build:extension && npm run test:chrome && npm run test:electron",
|
||||||
|
"type-check": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@redux-devtools/app": "^1.0.0-8",
|
"@redux-devtools/app": "^1.0.0-8",
|
||||||
|
|
|
@ -357,6 +357,7 @@ export interface ErrorMessage {
|
||||||
readonly payload: string;
|
readonly payload: string;
|
||||||
readonly source: typeof source;
|
readonly source: typeof source;
|
||||||
readonly instanceId: number;
|
readonly instanceId: number;
|
||||||
|
readonly message?: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InitInstanceMessage {
|
interface InitInstanceMessage {
|
||||||
|
@ -449,16 +450,34 @@ export function sendMessage<S, A extends Action<unknown>>(
|
||||||
config = {}; // eslint-disable-line no-param-reassign
|
config = {}; // eslint-disable-line no-param-reassign
|
||||||
if (action) amendedAction = amendActionType(action, config, sendMessage);
|
if (action) amendedAction = amendActionType(action, config, sendMessage);
|
||||||
}
|
}
|
||||||
const message = {
|
if (action) {
|
||||||
type: action ? 'ACTION' : 'STATE',
|
toContentScript(
|
||||||
action: amendedAction,
|
{
|
||||||
payload: state,
|
type: 'ACTION',
|
||||||
maxAge: config.maxAge,
|
action: amendedAction,
|
||||||
source,
|
payload: state,
|
||||||
name: config.name || name,
|
maxAge: config.maxAge,
|
||||||
instanceId: config.instanceId || instanceId || 1,
|
source,
|
||||||
};
|
name: config.name || name,
|
||||||
toContentScript(message, config.serialize, config.serialize);
|
instanceId: config.instanceId || instanceId || 1,
|
||||||
|
},
|
||||||
|
config.serialize,
|
||||||
|
config.serialize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
toContentScript(
|
||||||
|
{
|
||||||
|
type: 'STATE',
|
||||||
|
action: amendedAction,
|
||||||
|
payload: state,
|
||||||
|
maxAge: config.maxAge,
|
||||||
|
source,
|
||||||
|
name: config.name || name,
|
||||||
|
instanceId: config.instanceId || instanceId || 1,
|
||||||
|
},
|
||||||
|
config.serialize,
|
||||||
|
config.serialize
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMessages(event: MessageEvent<ContentScriptToPageScriptMessage>) {
|
function handleMessages(event: MessageEvent<ContentScriptToPageScriptMessage>) {
|
||||||
|
@ -609,7 +628,11 @@ export function connect(preConfig: Config) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendMessage(amendedAction, amendedState, config);
|
sendMessage(
|
||||||
|
amendedAction as StructuralPerformAction<A>,
|
||||||
|
amendedState,
|
||||||
|
config
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const init = <S, A extends Action<unknown>>(
|
const init = <S, A extends Action<unknown>>(
|
||||||
|
|
|
@ -7,6 +7,8 @@ import Actions from '@redux-devtools/app/lib/containers/Actions';
|
||||||
import Header from '@redux-devtools/app/lib/components/Header';
|
import Header from '@redux-devtools/app/lib/components/Header';
|
||||||
import { clearNotification } from '@redux-devtools/app/lib/actions';
|
import { clearNotification } from '@redux-devtools/app/lib/actions';
|
||||||
import { StoreState } from '@redux-devtools/app/lib/reducers';
|
import { StoreState } from '@redux-devtools/app/lib/reducers';
|
||||||
|
import { SingleMessage } from '../middlewares/api';
|
||||||
|
import { Position } from '../api/openWindow';
|
||||||
|
|
||||||
type StateProps = ReturnType<typeof mapStateToProps>;
|
type StateProps = ReturnType<typeof mapStateToProps>;
|
||||||
type DispatchProps = ResolveThunks<typeof actionCreators>;
|
type DispatchProps = ResolveThunks<typeof actionCreators>;
|
||||||
|
@ -15,13 +17,17 @@ interface OwnProps {
|
||||||
}
|
}
|
||||||
type Props = StateProps & DispatchProps & OwnProps;
|
type Props = StateProps & DispatchProps & OwnProps;
|
||||||
|
|
||||||
|
function sendMessage(message: SingleMessage) {
|
||||||
|
chrome.runtime.sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
class App extends Component<Props> {
|
class App extends Component<Props> {
|
||||||
openWindow = (position: string) => {
|
openWindow = (position: Position) => {
|
||||||
chrome.runtime.sendMessage({ type: 'OPEN', position });
|
sendMessage({ type: 'OPEN', position });
|
||||||
};
|
};
|
||||||
openOptionsPage = () => {
|
openOptionsPage = () => {
|
||||||
if (navigator.userAgent.indexOf('Firefox') !== -1) {
|
if (navigator.userAgent.indexOf('Firefox') !== -1) {
|
||||||
chrome.runtime.sendMessage({ type: 'OPEN_OPTIONS' });
|
sendMessage({ type: 'OPEN_OPTIONS' });
|
||||||
} else {
|
} else {
|
||||||
chrome.runtime.openOptionsPage();
|
chrome.runtime.openOptionsPage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@ import syncOptions, {
|
||||||
OptionsMessage,
|
OptionsMessage,
|
||||||
SyncOptions,
|
SyncOptions,
|
||||||
} from '../../browser/extension/options/syncOptions';
|
} from '../../browser/extension/options/syncOptions';
|
||||||
import openDevToolsWindow from '../../browser/extension/background/openWindow';
|
import openDevToolsWindow, {
|
||||||
|
DevToolsPosition,
|
||||||
|
} from '../../browser/extension/background/openWindow';
|
||||||
import { getReport } from '../../browser/extension/background/logging';
|
import { getReport } from '../../browser/extension/background/logging';
|
||||||
import {
|
import {
|
||||||
CustomAction,
|
CustomAction,
|
||||||
|
@ -32,6 +34,7 @@ import {
|
||||||
BackgroundAction,
|
BackgroundAction,
|
||||||
LiftedActionAction,
|
LiftedActionAction,
|
||||||
} from '../stores/backgroundStore';
|
} from '../stores/backgroundStore';
|
||||||
|
import { Position } from '../api/openWindow';
|
||||||
|
|
||||||
interface TabMessageBase {
|
interface TabMessageBase {
|
||||||
readonly type: string;
|
readonly type: string;
|
||||||
|
@ -87,7 +90,7 @@ interface NAAction {
|
||||||
interface InitMessage<S, A extends Action<unknown>> {
|
interface InitMessage<S, A extends Action<unknown>> {
|
||||||
readonly type: 'INIT';
|
readonly type: 'INIT';
|
||||||
readonly payload: string;
|
readonly payload: string;
|
||||||
readonly instanceId: string;
|
instanceId: string;
|
||||||
readonly source: '@devtools-page';
|
readonly source: '@devtools-page';
|
||||||
action?: string;
|
action?: string;
|
||||||
name?: string | undefined;
|
name?: string | undefined;
|
||||||
|
@ -98,7 +101,7 @@ interface InitMessage<S, A extends Action<unknown>> {
|
||||||
interface LiftedMessage {
|
interface LiftedMessage {
|
||||||
readonly type: 'LIFTED';
|
readonly type: 'LIFTED';
|
||||||
readonly liftedState: { readonly isPaused: boolean | undefined };
|
readonly liftedState: { readonly isPaused: boolean | undefined };
|
||||||
readonly instanceId: string;
|
instanceId: number;
|
||||||
readonly source: '@devtools-page';
|
readonly source: '@devtools-page';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +115,7 @@ interface SerializedPartialStateMessage {
|
||||||
readonly type: 'PARTIAL_STATE';
|
readonly type: 'PARTIAL_STATE';
|
||||||
readonly payload: SerializedPartialLiftedState;
|
readonly payload: SerializedPartialLiftedState;
|
||||||
readonly source: '@devtools-page';
|
readonly source: '@devtools-page';
|
||||||
readonly instanceId: string;
|
instanceId: number;
|
||||||
readonly maxAge: number;
|
readonly maxAge: number;
|
||||||
readonly actionsById: string;
|
readonly actionsById: string;
|
||||||
readonly computedStates: string;
|
readonly computedStates: string;
|
||||||
|
@ -124,14 +127,14 @@ interface SerializedExportMessage {
|
||||||
readonly payload: string;
|
readonly payload: string;
|
||||||
readonly committedState: string | undefined;
|
readonly committedState: string | undefined;
|
||||||
readonly source: '@devtools-page';
|
readonly source: '@devtools-page';
|
||||||
readonly instanceId: string;
|
instanceId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SerializedActionMessage {
|
interface SerializedActionMessage {
|
||||||
readonly type: 'ACTION';
|
readonly type: 'ACTION';
|
||||||
readonly payload: string;
|
readonly payload: string;
|
||||||
readonly source: '@devtools-page';
|
readonly source: '@devtools-page';
|
||||||
readonly instanceId: string;
|
instanceId: number;
|
||||||
readonly action: string;
|
readonly action: string;
|
||||||
readonly maxAge: number;
|
readonly maxAge: number;
|
||||||
readonly nextActionId: number;
|
readonly nextActionId: number;
|
||||||
|
@ -144,7 +147,7 @@ interface SerializedStateMessage<S, A extends Action<unknown>> {
|
||||||
'actionsById' | 'computedStates' | 'committedState'
|
'actionsById' | 'computedStates' | 'committedState'
|
||||||
>;
|
>;
|
||||||
readonly source: '@devtools-page';
|
readonly source: '@devtools-page';
|
||||||
readonly instanceId: string;
|
instanceId: string;
|
||||||
readonly libConfig?: LibConfig;
|
readonly libConfig?: LibConfig;
|
||||||
readonly actionsById: string;
|
readonly actionsById: string;
|
||||||
readonly computedStates: string;
|
readonly computedStates: string;
|
||||||
|
@ -165,7 +168,7 @@ interface EmptyUpdateStateAction {
|
||||||
|
|
||||||
interface UpdateStateAction<S, A extends Action<unknown>> {
|
interface UpdateStateAction<S, A extends Action<unknown>> {
|
||||||
readonly type: typeof UPDATE_STATE;
|
readonly type: typeof UPDATE_STATE;
|
||||||
readonly request: UpdateStateRequest<S, A>;
|
request: UpdateStateRequest<S, A>;
|
||||||
readonly id: string | number;
|
readonly id: string | number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,8 +198,8 @@ type MonitorPort = Omit<chrome.runtime.Port, 'postMessage'> & {
|
||||||
postMessage: (message: MonitorMessage) => void;
|
postMessage: (message: MonitorMessage) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const CONNECTED = 'socket/CONNECTED';
|
export const CONNECTED = 'socket/CONNECTED';
|
||||||
const DISCONNECTED = 'socket/DISCONNECTED';
|
export const DISCONNECTED = 'socket/DISCONNECTED';
|
||||||
const connections: {
|
const connections: {
|
||||||
readonly tab: { [K in number | string]: TabPort };
|
readonly tab: { [K in number | string]: TabPort };
|
||||||
readonly panel: { [K in number | string]: PanelPort };
|
readonly panel: { [K in number | string]: PanelPort };
|
||||||
|
@ -248,19 +251,78 @@ interface ImportMessage {
|
||||||
|
|
||||||
type ToContentScriptMessage = ImportMessage | LiftedActionAction;
|
type ToContentScriptMessage = ImportMessage | LiftedActionAction;
|
||||||
|
|
||||||
function toContentScript({
|
function toContentScript(messageBody: ToContentScriptMessage) {
|
||||||
message,
|
if (messageBody.message === 'DISPATCH') {
|
||||||
action,
|
const { message, action, id, instanceId, state } = messageBody;
|
||||||
id,
|
connections.tab[id!].postMessage({
|
||||||
instanceId,
|
type: message,
|
||||||
state,
|
action,
|
||||||
}: ToContentScriptMessage) {
|
state: nonReduxDispatch(
|
||||||
connections.tab[id!].postMessage({
|
window.store,
|
||||||
type: message,
|
message,
|
||||||
action,
|
instanceId,
|
||||||
state: nonReduxDispatch(window.store, message, instanceId, action, state),
|
action as AppDispatchAction,
|
||||||
id: instanceId.toString().replace(/^[^\/]+\//, ''),
|
state
|
||||||
});
|
),
|
||||||
|
id: instanceId.toString().replace(/^[^\/]+\//, ''),
|
||||||
|
});
|
||||||
|
} else if (messageBody.message === 'IMPORT') {
|
||||||
|
const { message, action, id, instanceId, state } = messageBody;
|
||||||
|
connections.tab[id!].postMessage({
|
||||||
|
type: message,
|
||||||
|
action,
|
||||||
|
state: nonReduxDispatch(
|
||||||
|
window.store,
|
||||||
|
message,
|
||||||
|
instanceId,
|
||||||
|
action as unknown as AppDispatchAction,
|
||||||
|
state
|
||||||
|
),
|
||||||
|
id: instanceId.toString().replace(/^[^\/]+\//, ''),
|
||||||
|
});
|
||||||
|
} else if (messageBody.message === 'ACTION') {
|
||||||
|
const { message, action, id, instanceId, state } = messageBody;
|
||||||
|
connections.tab[id!].postMessage({
|
||||||
|
type: message,
|
||||||
|
action,
|
||||||
|
state: nonReduxDispatch(
|
||||||
|
window.store,
|
||||||
|
message,
|
||||||
|
instanceId,
|
||||||
|
action as unknown as AppDispatchAction,
|
||||||
|
state
|
||||||
|
),
|
||||||
|
id: instanceId.toString().replace(/^[^\/]+\//, ''),
|
||||||
|
});
|
||||||
|
} else if (messageBody.message === 'EXPORT') {
|
||||||
|
const { message, action, id, instanceId, state } = messageBody;
|
||||||
|
connections.tab[id!].postMessage({
|
||||||
|
type: message,
|
||||||
|
action,
|
||||||
|
state: nonReduxDispatch(
|
||||||
|
window.store,
|
||||||
|
message,
|
||||||
|
instanceId,
|
||||||
|
action as unknown as AppDispatchAction,
|
||||||
|
state
|
||||||
|
),
|
||||||
|
id: instanceId.toString().replace(/^[^\/]+\//, ''),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const { message, action, id, instanceId, state } = messageBody;
|
||||||
|
connections.tab[id!].postMessage({
|
||||||
|
type: message,
|
||||||
|
action,
|
||||||
|
state: nonReduxDispatch(
|
||||||
|
window.store,
|
||||||
|
message,
|
||||||
|
instanceId,
|
||||||
|
action as AppDispatchAction,
|
||||||
|
state
|
||||||
|
),
|
||||||
|
id: (instanceId as number).toString().replace(/^[^\/]+\//, ''),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toAllTabs(msg: TabMessage) {
|
function toAllTabs(msg: TabMessage) {
|
||||||
|
@ -302,9 +364,28 @@ function togglePersist() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface OpenMessage {
|
||||||
|
readonly type: 'OPEN';
|
||||||
|
readonly position: Position;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OpenOptionsMessage {
|
||||||
|
readonly type: 'OPEN_OPTIONS';
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GetOptionsMessage {
|
||||||
|
readonly type: 'GET_OPTIONS';
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SingleMessage =
|
||||||
|
| OpenMessage
|
||||||
|
| OpenOptionsMessage
|
||||||
|
| GetOptionsMessage;
|
||||||
|
|
||||||
type BackgroundStoreMessage<S, A extends Action<unknown>> =
|
type BackgroundStoreMessage<S, A extends Action<unknown>> =
|
||||||
| PageScriptToContentScriptMessageWithoutDisconnectOrInitInstance<S, A>
|
| PageScriptToContentScriptMessageWithoutDisconnectOrInitInstance<S, A>
|
||||||
| SplitMessage;
|
| SplitMessage
|
||||||
|
| SingleMessage;
|
||||||
type BackgroundStoreResponse = { readonly options: Options };
|
type BackgroundStoreResponse = { readonly options: Options };
|
||||||
|
|
||||||
// Receive messages from content scripts
|
// Receive messages from content scripts
|
||||||
|
@ -338,13 +419,13 @@ function messaging<S, A extends Action<unknown>>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (request.type === 'OPEN') {
|
if (request.type === 'OPEN') {
|
||||||
let position = 'devtools-left';
|
let position: DevToolsPosition = 'devtools-left';
|
||||||
if (
|
if (
|
||||||
['remote', 'panel', 'left', 'right', 'bottom'].indexOf(
|
['remote', 'panel', 'left', 'right', 'bottom'].indexOf(
|
||||||
request.position
|
request.position
|
||||||
) !== -1
|
) !== -1
|
||||||
) {
|
) {
|
||||||
position = 'devtools-' + request.position;
|
position = ('devtools-' + request.position) as DevToolsPosition;
|
||||||
}
|
}
|
||||||
openDevToolsWindow(position);
|
openDevToolsWindow(position);
|
||||||
return;
|
return;
|
||||||
|
@ -372,19 +453,20 @@ function messaging<S, A extends Action<unknown>>(
|
||||||
type: UPDATE_STATE,
|
type: UPDATE_STATE,
|
||||||
request,
|
request,
|
||||||
id: tabId,
|
id: tabId,
|
||||||
};
|
} as UpdateStateAction<S, A>;
|
||||||
const instanceId = `${tabId}/${request.instanceId}`;
|
const instanceId = `${tabId}/${request.instanceId}`;
|
||||||
if ('split' in request) {
|
if ('split' in request) {
|
||||||
if (request.split === 'start') {
|
if (request.split === 'start') {
|
||||||
chunks[instanceId] = request;
|
chunks[instanceId] = request as any;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (request.split === 'chunk') {
|
if (request.split === 'chunk') {
|
||||||
chunks[instanceId][request.chunk[0]] =
|
(chunks[instanceId] as any)[request.chunk[0]] =
|
||||||
(chunks[instanceId][request.chunk[0]] || '') + request.chunk[1];
|
((chunks[instanceId] as any)[request.chunk[0]] || '') +
|
||||||
|
request.chunk[1];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
action.request = chunks[instanceId];
|
action.request = chunks[instanceId] as any;
|
||||||
delete chunks[instanceId];
|
delete chunks[instanceId];
|
||||||
}
|
}
|
||||||
if (request.instanceId) {
|
if (request.instanceId) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { createStore, applyMiddleware, PreloadedState } from 'redux';
|
import { createStore, applyMiddleware, PreloadedState } from 'redux';
|
||||||
import rootReducer, { BackgroundState } from '../reducers/background';
|
import rootReducer, { BackgroundState } from '../reducers/background';
|
||||||
import api from '../middlewares/api';
|
import api, { CONNECTED, DISCONNECTED } from '../middlewares/api';
|
||||||
import { LIFTED_ACTION } from '@redux-devtools/app/lib/constants/actionTypes';
|
import { LIFTED_ACTION } from '@redux-devtools/app/lib/constants/actionTypes';
|
||||||
import {
|
import {
|
||||||
CustomAction,
|
CustomAction,
|
||||||
|
@ -26,6 +26,7 @@ interface LiftedActionImportAction extends LiftedActionActionBase {
|
||||||
message: 'IMPORT';
|
message: 'IMPORT';
|
||||||
state: string;
|
state: string;
|
||||||
preloadedState?: unknown | undefined;
|
preloadedState?: unknown | undefined;
|
||||||
|
action?: never;
|
||||||
}
|
}
|
||||||
interface LiftedActionActionAction extends LiftedActionActionBase {
|
interface LiftedActionActionAction extends LiftedActionActionBase {
|
||||||
type: typeof LIFTED_ACTION;
|
type: typeof LIFTED_ACTION;
|
||||||
|
@ -36,6 +37,7 @@ interface LiftedActionExportAction extends LiftedActionActionBase {
|
||||||
type: typeof LIFTED_ACTION;
|
type: typeof LIFTED_ACTION;
|
||||||
message: 'EXPORT';
|
message: 'EXPORT';
|
||||||
toExport: boolean;
|
toExport: boolean;
|
||||||
|
action?: never;
|
||||||
}
|
}
|
||||||
export type LiftedActionAction =
|
export type LiftedActionAction =
|
||||||
| LiftedActionDispatchAction
|
| LiftedActionDispatchAction
|
||||||
|
@ -49,10 +51,20 @@ interface TogglePersistAction {
|
||||||
readonly id: string | number | undefined;
|
readonly id: string | number | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ConnectedAction {
|
||||||
|
readonly type: typeof CONNECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DisconnectedAction {
|
||||||
|
readonly type: typeof DISCONNECTED;
|
||||||
|
}
|
||||||
|
|
||||||
export type BackgroundAction =
|
export type BackgroundAction =
|
||||||
| StoreActionWithoutLiftedAction
|
| StoreActionWithoutLiftedAction
|
||||||
| LiftedActionAction
|
| LiftedActionAction
|
||||||
| TogglePersistAction;
|
| TogglePersistAction
|
||||||
|
| ConnectedAction
|
||||||
|
| DisconnectedAction;
|
||||||
|
|
||||||
export default function configureStore(
|
export default function configureStore(
|
||||||
preloadedState?: PreloadedState<BackgroundState>
|
preloadedState?: PreloadedState<BackgroundState>
|
||||||
|
|
|
@ -1,48 +1,48 @@
|
||||||
// Mock not supported chrome.* API for Firefox and Electron
|
// Mock not supported chrome.* API for Firefox and Electron
|
||||||
|
|
||||||
window.isElectron =
|
(window as any).isElectron =
|
||||||
window.navigator && window.navigator.userAgent.indexOf('Electron') !== -1;
|
window.navigator && window.navigator.userAgent.indexOf('Electron') !== -1;
|
||||||
|
|
||||||
const isFirefox = navigator.userAgent.indexOf('Firefox') !== -1;
|
const isFirefox = navigator.userAgent.indexOf('Firefox') !== -1;
|
||||||
|
|
||||||
// Background page only
|
// Background page only
|
||||||
if (
|
if (
|
||||||
(window.isElectron &&
|
((window as any).isElectron &&
|
||||||
location.pathname === '/_generated_background_page.html') ||
|
location.pathname === '/_generated_background_page.html') ||
|
||||||
isFirefox
|
isFirefox
|
||||||
) {
|
) {
|
||||||
chrome.runtime.onConnectExternal = {
|
(chrome.runtime as any).onConnectExternal = {
|
||||||
addListener() {},
|
addListener() {},
|
||||||
};
|
};
|
||||||
chrome.runtime.onMessageExternal = {
|
(chrome.runtime as any).onMessageExternal = {
|
||||||
addListener() {},
|
addListener() {},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (window.isElectron) {
|
if ((window as any).isElectron) {
|
||||||
chrome.notifications = {
|
(chrome.notifications as any) = {
|
||||||
onClicked: {
|
onClicked: {
|
||||||
addListener() {},
|
addListener() {},
|
||||||
},
|
},
|
||||||
create() {},
|
create() {},
|
||||||
clear() {},
|
clear() {},
|
||||||
};
|
};
|
||||||
chrome.contextMenus = {
|
(chrome.contextMenus as any) = {
|
||||||
onClicked: {
|
onClicked: {
|
||||||
addListener() {},
|
addListener() {},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
chrome.storage.sync = chrome.storage.local;
|
(chrome.storage as any).sync = chrome.storage.local;
|
||||||
chrome.runtime.onInstalled = {
|
(chrome.runtime as any).onInstalled = {
|
||||||
addListener: (cb) => cb(),
|
addListener: (cb: any) => cb(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.isElectron) {
|
if ((window as any).isElectron) {
|
||||||
if (!chrome.storage.local || !chrome.storage.local.remove) {
|
if (!chrome.storage.local || !chrome.storage.local.remove) {
|
||||||
chrome.storage.local = {
|
(chrome.storage as any).local = {
|
||||||
set(obj, callback) {
|
set(obj: any, callback: any) {
|
||||||
Object.keys(obj).forEach((key) => {
|
Object.keys(obj).forEach((key) => {
|
||||||
localStorage.setItem(key, obj[key]);
|
localStorage.setItem(key, obj[key]);
|
||||||
});
|
});
|
||||||
|
@ -50,8 +50,8 @@ if (window.isElectron) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
get(obj, callback) {
|
get(obj: any, callback: any) {
|
||||||
const result = {};
|
const result: any = {};
|
||||||
Object.keys(obj).forEach((key) => {
|
Object.keys(obj).forEach((key) => {
|
||||||
result[key] = localStorage.getItem(key) || obj[key];
|
result[key] = localStorage.getItem(key) || obj[key];
|
||||||
});
|
});
|
||||||
|
@ -60,7 +60,7 @@ if (window.isElectron) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Electron ~ 1.4.6
|
// Electron ~ 1.4.6
|
||||||
remove(items, callback) {
|
remove(items: any, callback: any) {
|
||||||
if (Array.isArray(items)) {
|
if (Array.isArray(items)) {
|
||||||
items.forEach((name) => {
|
items.forEach((name) => {
|
||||||
localStorage.removeItem(name);
|
localStorage.removeItem(name);
|
||||||
|
@ -75,7 +75,7 @@ if (window.isElectron) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Avoid error: chrome.runtime.sendMessage is not supported responseCallback
|
// Avoid error: chrome.runtime.sendMessage is not supported responseCallback
|
||||||
const originSendMessage = chrome.runtime.sendMessage;
|
const originSendMessage = (chrome.runtime as any).sendMessage;
|
||||||
chrome.runtime.sendMessage = function () {
|
chrome.runtime.sendMessage = function () {
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
return originSendMessage(...arguments);
|
return originSendMessage(...arguments);
|
||||||
|
@ -87,6 +87,6 @@ if (window.isElectron) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFirefox || window.isElectron) {
|
if (isFirefox || (window as any).isElectron) {
|
||||||
chrome.storage.sync = chrome.storage.local;
|
(chrome.storage as any).sync = chrome.storage.local;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Include this script in Chrome apps and extensions for remote debugging
|
// Include this script in Chrome apps and extensions for remote debugging
|
||||||
// <script src="chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljd/js/redux-devtools-extension.bundle.js"></script>
|
// <script src="chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljd/js/redux-devtools-extension.bundle.js"></script>
|
||||||
|
|
||||||
|
import { Options } from '../options/syncOptions';
|
||||||
|
|
||||||
window.devToolsExtensionID = 'lmhkpmbekcpmknklioeibfkpmmfibljd';
|
window.devToolsExtensionID = 'lmhkpmbekcpmknklioeibfkpmmfibljd';
|
||||||
require('./contentScript');
|
require('./contentScript');
|
||||||
require('./pageScript');
|
require('./pageScript');
|
||||||
|
@ -8,7 +10,7 @@ require('./pageScript');
|
||||||
chrome.runtime.sendMessage(
|
chrome.runtime.sendMessage(
|
||||||
window.devToolsExtensionID,
|
window.devToolsExtensionID,
|
||||||
{ type: 'GET_OPTIONS' },
|
{ type: 'GET_OPTIONS' },
|
||||||
function (response) {
|
function (response: { readonly options: Options }) {
|
||||||
if (!response.options.inject) {
|
if (!response.options.inject) {
|
||||||
const urls = response.options.urls.split('\n').filter(Boolean).join('|');
|
const urls = response.options.urls.split('\n').filter(Boolean).join('|');
|
||||||
if (!location.href.match(new RegExp(urls))) return;
|
if (!location.href.match(new RegExp(urls))) return;
|
||||||
|
|
|
@ -5,7 +5,6 @@ import { SET_STATE } from '../constants/actionTypes';
|
||||||
import { InstancesState, State } from '../reducers/instances';
|
import { InstancesState, State } from '../reducers/instances';
|
||||||
import { Dispatch, MiddlewareAPI } from 'redux';
|
import { Dispatch, MiddlewareAPI } from 'redux';
|
||||||
import { DispatchAction, StoreAction } from '../actions';
|
import { DispatchAction, StoreAction } from '../actions';
|
||||||
import { StoreState } from '../reducers';
|
|
||||||
|
|
||||||
export function sweep(state: State): State {
|
export function sweep(state: State): State {
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user