开启开发者模式引导
This commit is contained in:
parent
a26f1c5014
commit
51fe2a89e1
@ -15,7 +15,7 @@ import { subscribeScriptDelete, subscribeScriptEnable, subscribeScriptInstall }
|
||||
import { ScriptService } from "./script";
|
||||
import { runScript, stopScript } from "../offscreen/client";
|
||||
import { getRunAt } from "./utils";
|
||||
import { isUserScriptsAvailable, randomString } from "@App/pkg/utils/utils";
|
||||
import { InfoNotification, isUserScriptsAvailable, randomString } from "@App/pkg/utils/utils";
|
||||
import Cache from "@App/app/cache";
|
||||
import { dealPatternMatches, UrlMatch } from "@App/pkg/utils/match";
|
||||
import { ExtensionContentMessageSend } from "@Packages/message/extension_message";
|
||||
@ -27,6 +27,8 @@ import LoggerCore from "@App/app/logger/core";
|
||||
import PermissionVerify from "./permission_verify";
|
||||
import { SystemConfig } from "@App/pkg/config/config";
|
||||
import { ResourceService } from "./resource";
|
||||
import { LocalStorageDAO } from "@App/app/repo/localStorage";
|
||||
import i18n from "@App/locales/locales";
|
||||
|
||||
// 为了优化性能,存储到缓存时删除了code、value与resource
|
||||
export interface ScriptMatchInfo extends ScriptRunResouce {
|
||||
@ -49,6 +51,8 @@ export class RuntimeService {
|
||||
scriptCustomizeMatch: UrlMatch<string> = new UrlMatch<string>();
|
||||
scriptMatchCache: Map<string, ScriptMatchInfo> | null | undefined;
|
||||
|
||||
isEnableDeveloperMode = false;
|
||||
|
||||
constructor(
|
||||
private systemConfig: SystemConfig,
|
||||
private group: Group,
|
||||
@ -71,9 +75,32 @@ export class RuntimeService {
|
||||
this.group.on("pageLoad", this.pageLoad.bind(this));
|
||||
|
||||
// 检查是否开启了开发者模式
|
||||
if(!isUserScriptsAvailable()){
|
||||
this.isEnableDeveloperMode = isUserScriptsAvailable();
|
||||
if (!this.isEnableDeveloperMode) {
|
||||
// 未开启加上警告引导
|
||||
|
||||
// 判断是否首次
|
||||
const localStorage = new LocalStorageDAO();
|
||||
localStorage.get("firstShowDeveloperMode").then((res) => {
|
||||
if (!res) {
|
||||
localStorage.save({
|
||||
key: "firstShowDeveloperMode",
|
||||
value: true,
|
||||
});
|
||||
// 打开页面
|
||||
chrome.tabs.create({
|
||||
url: `https://docs.scriptcat.org/docs/use/open-dev/`,
|
||||
});
|
||||
}
|
||||
});
|
||||
chrome.action.setBadgeBackgroundColor({
|
||||
color: "#ff8c00",
|
||||
});
|
||||
chrome.action.setBadgeTextColor({
|
||||
color: "#ffffff",
|
||||
});
|
||||
chrome.action.setBadgeText({
|
||||
text: "!",
|
||||
});
|
||||
}
|
||||
// 读取inject.js注入页面
|
||||
this.registerInjectScript();
|
||||
@ -439,7 +466,7 @@ export class RuntimeService {
|
||||
this.addScriptMatch(scriptMatchInfo);
|
||||
|
||||
// 如果脚本开启, 则注册脚本
|
||||
if (script.status === SCRIPT_STATUS_ENABLE) {
|
||||
if (this.isEnableDeveloperMode && script.status === SCRIPT_STATUS_ENABLE) {
|
||||
if (!scriptRes.metadata["noframes"]) {
|
||||
registerScript.allFrames = true;
|
||||
}
|
||||
@ -467,7 +494,7 @@ export class RuntimeService {
|
||||
}
|
||||
|
||||
async unregistryPageScript(uuid: string) {
|
||||
if (!(await Cache.getInstance().get("registryScript:" + uuid))) {
|
||||
if (!this.isEnableDeveloperMode || !(await Cache.getInstance().get("registryScript:" + uuid))) {
|
||||
return;
|
||||
}
|
||||
chrome.userScripts.unregister(
|
||||
|
@ -21,7 +21,7 @@ import { ResourceService } from "./resource";
|
||||
import { ValueService } from "./value";
|
||||
import { compileScriptCode } from "../content/utils";
|
||||
import { SystemConfig } from "@App/pkg/config/config";
|
||||
import i18n from "@App/locales/locales";
|
||||
import i18n, { localePath } from "@App/locales/locales";
|
||||
|
||||
export class ScriptService {
|
||||
logger: Logger;
|
||||
@ -109,10 +109,6 @@ export class ScriptService {
|
||||
}
|
||||
);
|
||||
// 获取i18n
|
||||
let localePath = "";
|
||||
if (i18n.language !== "zh-CN") {
|
||||
localePath = `/en`;
|
||||
}
|
||||
// 重定向到脚本安装页
|
||||
chrome.declarativeNetRequest.updateDynamicRules(
|
||||
{
|
||||
|
@ -27,10 +27,15 @@ i18n.use(initReactI18next).init({
|
||||
},
|
||||
});
|
||||
|
||||
export let localePath = "";
|
||||
|
||||
chrome.i18n.getAcceptLanguages((lngs) => {
|
||||
systemConfig.getLanguage().then((lng) => {
|
||||
systemConfig.getLanguage(lngs).then((lng) => {
|
||||
i18n.changeLanguage(lng);
|
||||
dayjs.locale(lng.toLocaleLowerCase());
|
||||
if (lng !== "zh-CN") {
|
||||
localePath = "en";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -368,5 +368,6 @@
|
||||
"eslint_config_format_error": "eslint配置格式错误",
|
||||
"export_success": "导出成功",
|
||||
"get_backup_dir_url_failed": "获取备份目录地址失败",
|
||||
"get_backup_files_failed": "获取备份文件失败"
|
||||
"get_backup_files_failed": "获取备份文件失败",
|
||||
"develop_mode_guide": "检测到当前未开启开发者模式,您的脚本无法正常使用,<a href=\"https://docs.scriptcat.org/docs/use/open-dev/\" target=\"black\" style=\"color: var(--color-text-1)\">👉点我了解如何开启</a>"
|
||||
}
|
@ -18,7 +18,7 @@ import ScriptMenuList from "../components/ScriptMenuList";
|
||||
import { popupClient } from "../store/features/script";
|
||||
import { ScriptMenu } from "@App/app/service/service_worker/popup";
|
||||
import { systemConfig } from "../store/global";
|
||||
import { SystemConfig } from "@App/pkg/config/config";
|
||||
import { isUserScriptsAvailable } from "@App/pkg/utils/utils";
|
||||
|
||||
const CollapseItem = Collapse.Item;
|
||||
|
||||
@ -79,6 +79,10 @@ function App() {
|
||||
});
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
{!isUserScriptsAvailable() && (
|
||||
<Alert type="warning" content={<div dangerouslySetInnerHTML={{ __html: t("develop_mode_guide") }} />} />
|
||||
)}
|
||||
<Card
|
||||
size="small"
|
||||
title={
|
||||
@ -113,7 +117,6 @@ function App() {
|
||||
iconOnly
|
||||
onClick={() => {
|
||||
setShowAlert(!showAlert);
|
||||
console.log(checkUpdate);
|
||||
checkUpdate.isRead = true;
|
||||
setCheckUpdate(checkUpdate);
|
||||
systemConfig.setCheckUpdate(checkUpdate);
|
||||
@ -206,7 +209,7 @@ function App() {
|
||||
{semver.lt(ExtVersion, checkUpdate.version) && (
|
||||
<span
|
||||
onClick={() => {
|
||||
window.open(`https://github.com/scriptscat/scriptcat/releases/tag/v${version}`);
|
||||
window.open(`https://github.com/scriptscat/scriptcat/releases/tag/v${checkUpdate.version}`);
|
||||
}}
|
||||
className="text-1 font-500"
|
||||
style={{ cursor: "pointer" }}
|
||||
@ -216,6 +219,7 @@ function App() {
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -225,19 +225,20 @@ export class SystemConfig {
|
||||
this.set("menu_expand_num", val);
|
||||
}
|
||||
|
||||
async getLanguage() {
|
||||
const defaultLanguage = await new Promise<string>((resolve) => {
|
||||
chrome.i18n.getAcceptLanguages((lngs) => {
|
||||
async getLanguage(acceptLanguages?: string[]): Promise<string> {
|
||||
const defaultLanguage = await new Promise<string>(async (resolve) => {
|
||||
if (!acceptLanguages) {
|
||||
acceptLanguages = await chrome.i18n.getAcceptLanguages();
|
||||
}
|
||||
// 遍历数组寻找匹配语言
|
||||
for (let i = 0; i < lngs.length; i += 1) {
|
||||
const lng = lngs[i];
|
||||
for (let i = 0; i < acceptLanguages.length; i += 1) {
|
||||
const lng = acceptLanguages[i];
|
||||
if (i18n.hasResourceBundle(lng, "translation")) {
|
||||
resolve(lng);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return this.get("language", defaultLanguage || chrome.i18n.getUILanguage());
|
||||
}
|
||||
|
||||
|
@ -266,7 +266,6 @@ export function errorMsg(e: any): string {
|
||||
}
|
||||
|
||||
export function isUserScriptsAvailable() {
|
||||
return false;
|
||||
try {
|
||||
// Property access which throws if developer mode is not enabled.
|
||||
chrome.userScripts;
|
||||
|
Loading…
x
Reference in New Issue
Block a user