Skip to content

Commit ce86bdc

Browse files
committed
Merge branch 'dev'
2 parents fbe6b9f + 3b5fc84 commit ce86bdc

13 files changed

Lines changed: 109 additions & 30 deletions

File tree

extension.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"dist": "HeaderEditor-{VER}",
33
"auto": {
4-
"xpi": true,
54
"amo": true,
65
"cws": true,
76
"crx": true,
8-
"edge": true
7+
"edge": true,
8+
"xpi": true
99
},
1010
"crx": [
1111
{

scripts/pack-utils/amo.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async function packSourceCode(rootPath) {
8585
}
8686
}
8787

88-
const waitSubmit = [];
88+
export const waitSubmit = [];
8989
export async function submitAddon(
9090
rootPath,
9191
uploadSourceCode = false,

scripts/pack-utils/xpi.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { rename } from 'node:fs/promises';
2+
import { setTimeout as sleep } from 'node:timers/promises';
23
import { signAddon } from 'sign-addon';
34
import { getOutputFile, getVersion, join } from '../config.mjs';
45
import { outputJSON } from '../utils.mjs';
6+
import { waitSubmit } from './amo.mjs';
57

68
async function packXpi({
79
sourcePath,
@@ -19,6 +21,12 @@ async function packXpi({
1921

2022
const version = await getVersion(sourcePath);
2123

24+
if (waitSubmit.length > 0) {
25+
const last = waitSubmit[waitSubmit.length - 1];
26+
// wait 60s for AMO submit
27+
await sleep(last + 60000);
28+
}
29+
2230
const { success, downloadedFiles } = await signAddon({
2331
xpiPath: zipPath,
2432
version,

scripts/pack.mjs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const packUtils = {
4444
* @param {*} extensionConfig 对应extension.json中的配置
4545
* @returns
4646
*/
47-
async function packOnePlatform(name, browserConfig, extensionConfig) {
47+
async function prepareOnePlatform(name, extensionConfig) {
4848
if (typeof packUtils[name] === 'undefined') {
4949
console.error(`pack-utils for ${name} not found`);
5050
return;
@@ -68,8 +68,19 @@ async function packOnePlatform(name, browserConfig, extensionConfig) {
6868
// 打包成zip
6969
console.log(`zip ${thisPack} -> ${zipPath}`);
7070
await createZip(thisPack, zipPath);
71-
// 执行上传等操作
72-
console.log(`Running ${name} pack...`);
71+
} catch (e) {
72+
console.error(`Prepare ${name} error`);
73+
console.error(e);
74+
}
75+
return { dirName, thisPack, zipPath };
76+
}
77+
async function packOnePlatform(name, prepare, browserConfig, extensionConfig) {
78+
const { thisPack, zipPath } = prepare;
79+
if (typeof packUtils[name] === 'undefined') {
80+
console.error(`pack-utils for ${name} not found`);
81+
return;
82+
}
83+
try {
7384
const res = await packUtils[name]({
7485
rootPath: _path.root,
7586
sourcePath: thisPack,
@@ -122,7 +133,8 @@ async function main() {
122133
const platformConfig = extension[name];
123134
for (const item of platformConfig) {
124135
const browser = browserConfig[item.browser];
125-
queue.push(packOnePlatform(name, browser, item));
136+
const prepare = await prepareOnePlatform(name, item);
137+
queue.push(packOnePlatform(name, { ...prepare }, browser, item));
126138
}
127139
}
128140

src/pages/options/sections/rules/edit/form-content/test.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
import { Input, useFormState } from '@douyinfe/semi-ui';
2-
import { useDebounceEffect, useGetState } from 'ahooks';
2+
import { useDebounceEffect } from 'ahooks';
3+
import equal from 'fast-deep-equal';
4+
import { cloneDeep } from 'lodash-es';
35
import { RE2JS } from 're2js';
46
import { useRef, useState } from 'react';
57
import { IS_MATCH } from '@/share/core/constant';
6-
import { initRule, isMatchUrl } from '@/share/core/rule-utils';
8+
import { detectRunner, initRule, isMatchUrl } from '@/share/core/rule-utils';
79
import type { InitdRule } from '@/share/core/types';
810
import { t } from '@/share/core/utils';
11+
import useStateIfChanged from '@/share/hooks/use-state-if-changed';
912
import { getRuleFromInput } from '../utils';
1013

1114
const Test = () => {
1215
const rule = useRef<InitdRule>();
1316
const lastValue = useRef<any>();
1417
const { values } = useFormState();
1518
const [url, setUrl] = useState('');
16-
const [result, setResult, getResult] = useGetState('');
19+
const [result, setResult] = useStateIfChanged('');
1720

1821
useDebounceEffect(
1922
() => {
2023
if (url === '') {
21-
if (getResult() !== '') {
22-
setResult('');
23-
}
24+
setResult('');
2425
return;
2526
}
2627

27-
if (lastValue.current !== values || !rule.current) {
28+
if (!equal(lastValue.current, values) || !rule.current) {
2829
const ruleContent = getRuleFromInput(values);
2930
try {
31+
rule.current = initRule(ruleContent, true);
3032
if (ruleContent.condition?.regex) {
3133
// check re2 syntax
32-
RE2JS.compile(ruleContent.condition.regex);
34+
rule.current._re2 = RE2JS.compile(ruleContent.condition.regex);
3335
}
34-
rule.current = initRule(ruleContent, true);
3536
} catch (e) {
3637
// 出错
3738
setResult((e as Error).message);
3839
return;
3940
}
41+
lastValue.current = cloneDeep(values);
4042
}
4143
if (!rule.current) {
4244
return;
@@ -61,7 +63,9 @@ const Test = () => {
6163
// 只有重定向支持测试详细功能,其他只返回匹配
6264
if (initdRule.ruleType === 'redirect' && initdRule.to) {
6365
let redirect = '';
64-
if (initdRule?._reg) {
66+
if (detectRunner(initdRule) === 'dnr' && initdRule._re2 && ENABLE_DNR) {
67+
redirect = initdRule._re2.matcher(url).replaceAll(initdRule.to);
68+
} else if (initdRule?._reg) {
6569
initdRule._reg.lastIndex = 0;
6670
redirect = url.replace(initdRule._reg, initdRule.to);
6771
} else {

src/pages/options/sections/rules/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import {
1010
import {
1111
Button,
1212
ButtonGroup,
13-
Modal,
1413
Space,
1514
Spin,
1615
Typography,
1716
} from '@douyinfe/semi-ui';
1817
import { css, cx } from '@emotion/css';
1918
import * as React from 'react';
2019
import { selectGroup } from '@/pages/options/utils';
20+
import Modal from '@/share/components/modal';
2121
import {
2222
EVENTs,
2323
type TABLE_NAMES,

src/pages/options/sections/rules/rule-group-card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
ButtonGroup,
1818
Card,
1919
Dropdown,
20-
Modal,
2120
Popover,
2221
Switch,
2322
Table,
@@ -30,6 +29,7 @@ import type {
3029
import { css } from '@emotion/css';
3130
import { useResponsive } from 'ahooks';
3231
import { getExportName, selectGroup } from '@/pages/options/utils';
32+
import Modal from '@/share/components/modal';
3333
import RuleContentSwitcher from '@/share/components/rule-content-switcher';
3434
import RuleDetail from '@/share/components/rule-detail';
3535
import { TABLE_NAMES_ARR, VIRTUAL_KEY } from '@/share/core/constant';

src/pages/popup/rules/quick-edit.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { IconEdit, IconItalic, IconPlusCircle } from '@douyinfe/semi-icons';
2-
import { Button, Form, Input, Modal, Tabs } from '@douyinfe/semi-ui';
2+
import { Button, Form, Input, Tabs } from '@douyinfe/semi-ui';
33
import { css } from '@emotion/css';
44
import { useLatest } from 'ahooks';
55
import { type ReactNode, useCallback, useEffect, useState } from 'react';
6+
import Modal from '@/share/components/modal';
67
import { RULE_TYPE } from '@/share/core/constant';
78
import type { Rule } from '@/share/core/types';
89
import { t } from '@/share/core/utils';

src/share/components/modal.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Modal as SemiModal } from '@douyinfe/semi-ui';
2+
import { currentLocale } from './semi-locale';
3+
4+
const modalLocale = currentLocale.Modal || {};
5+
6+
const Modal = { ...SemiModal };
7+
8+
['confirm', 'warning', 'info', 'success', 'error'].forEach(key => {
9+
(Modal as any)[key] = (props: any) =>
10+
(SemiModal as any)[key]({
11+
okText: modalLocale.confirm,
12+
cancelText: modalLocale.cancel,
13+
...props,
14+
});
15+
});
16+
17+
export default Modal;
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import { i18n } from 'webextension-polyfill';
21
import { LocaleProvider } from '@douyinfe/semi-ui';
32
import React from 'react';
3+
import { i18n } from 'webextension-polyfill';
44

5-
const allLocales = {};
5+
const allLocales: any = {};
66

77
// @ts-ignore
8-
const context = require.context('@douyinfe/semi-ui/lib/es/locale/source', false, /\.js$/);
8+
const context = require.context(
9+
'@douyinfe/semi-ui/lib/es/locale/source',
10+
false,
11+
/\.js$/,
12+
);
913
context.keys().forEach((key: string) => {
1014
const locale = context(key);
1115
if (locale.default) {
@@ -18,12 +22,12 @@ context.keys().forEach((key: string) => {
1822

1923
// 默认使用 en-US
2024
const lang = i18n.getUILanguage();
21-
const currentLocale = typeof allLocales[lang] === 'object' ? allLocales[lang] : allLocales['en-US'];
25+
const currentLocale =
26+
typeof allLocales[lang] === 'object' ? allLocales[lang] : allLocales['en-US'];
2227

2328
const SemiLocale = (props: any) => (
24-
<LocaleProvider locale={currentLocale}>
25-
{props.children}
26-
</LocaleProvider>
29+
<LocaleProvider locale={currentLocale}>{props.children}</LocaleProvider>
2730
);
2831

32+
export { currentLocale };
2933
export default SemiLocale;

0 commit comments

Comments
 (0)