mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 06:29:20 +08:00
feat: 浏览器扩展完全支持热更新
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import { createApp, type App } from 'vue';
|
||||
|
||||
import { emitFeatureEvent } from '@/features/runtime/mainWorldAdapters';
|
||||
|
||||
import FloatingPanel from './FloatingPanel.vue';
|
||||
import styles from './styles.css?inline';
|
||||
|
||||
const HOST_ID = 'ecbi-float-host';
|
||||
const LAUNCHER_ID = 'ecbi-float-launcher';
|
||||
const FEATURE_ID = 'pdd-ad-fee';
|
||||
|
||||
let app: App<Element> | null = null;
|
||||
let visible = false;
|
||||
@@ -53,6 +56,7 @@ function showLauncher() {
|
||||
btn.addEventListener('click', () => {
|
||||
minimized = false;
|
||||
setFloatingVisible(true);
|
||||
emitFeatureEvent(FEATURE_ID, 'restored');
|
||||
});
|
||||
document.documentElement.appendChild(btn);
|
||||
}
|
||||
@@ -87,6 +91,7 @@ function mountApp() {
|
||||
unmountApp();
|
||||
showLauncher();
|
||||
visible = true;
|
||||
emitFeatureEvent(FEATURE_ID, 'minimized');
|
||||
},
|
||||
});
|
||||
app.mount(mountEl);
|
||||
@@ -98,10 +103,14 @@ export function isFloatingVisible(): boolean {
|
||||
|
||||
export function setFloatingVisible(next: boolean): boolean {
|
||||
if (!next) {
|
||||
const wasVisible = visible;
|
||||
visible = false;
|
||||
minimized = false;
|
||||
unmountApp();
|
||||
removeLauncher();
|
||||
if (wasVisible) {
|
||||
emitFeatureEvent(FEATURE_ID, 'closed');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -352,19 +352,19 @@ button.ecbi-heat-cell:disabled {
|
||||
}
|
||||
|
||||
.ecbi-heat-l1 {
|
||||
background: #bae0ff;
|
||||
background: #9be9a8;
|
||||
}
|
||||
|
||||
.ecbi-heat-l2 {
|
||||
background: #69b1ff;
|
||||
background: #40c463;
|
||||
}
|
||||
|
||||
.ecbi-heat-l3 {
|
||||
background: #1677ff;
|
||||
background: #30a14e;
|
||||
}
|
||||
|
||||
.ecbi-heat-l4 {
|
||||
background: #0958d9;
|
||||
background: #216e39;
|
||||
}
|
||||
|
||||
.ecbi-heat-out {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { resolveAdapter } from '@/platform/core/PlatformDetector';
|
||||
import {
|
||||
getActiveFeatureId,
|
||||
isFeatureUiVisible,
|
||||
mountFeature,
|
||||
unmountActiveFeature,
|
||||
} from '@/features/runtime/registry';
|
||||
import { startBridgeHost } from '@/features/runtime/bridgeHost';
|
||||
import { resolveAdapter } from '@/platform/core/PlatformDetector';
|
||||
import { ExtensionError } from '@/shared/errors';
|
||||
import {
|
||||
isExtensionMessage,
|
||||
@@ -12,11 +14,7 @@ import {
|
||||
} from '@/shared/messages';
|
||||
import type { AdvertisingCostBatch } from '@/types/advertisingCost';
|
||||
|
||||
import {
|
||||
isFloatingVisible,
|
||||
setFloatingVisible,
|
||||
toggleFloatingPanel,
|
||||
} from './floating/mount';
|
||||
startBridgeHost();
|
||||
|
||||
async function handleMessage(message: ExtensionMessage): Promise<ExtensionResponse> {
|
||||
const adapter = resolveAdapter(location.href);
|
||||
@@ -37,18 +35,32 @@ async function handleMessage(message: ExtensionMessage): Promise<ExtensionRespon
|
||||
return { ok: true, data };
|
||||
}
|
||||
case 'TOGGLE_FLOATING_PANEL': {
|
||||
const visible = toggleFloatingPanel();
|
||||
return { ok: true, data: { visible } };
|
||||
if (isFeatureUiVisible()) {
|
||||
await unmountActiveFeature();
|
||||
return { ok: true, data: { visible: false } };
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
code: 'UNKNOWN',
|
||||
message: '请从 Popup 打开功能(需下载远程脚本)',
|
||||
};
|
||||
}
|
||||
case 'SET_FLOATING_PANEL': {
|
||||
const visible = setFloatingVisible(message.payload.visible);
|
||||
return { ok: true, data: { visible } };
|
||||
if (!message.payload.visible) {
|
||||
await unmountActiveFeature();
|
||||
return { ok: true, data: { visible: false } };
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
code: 'UNKNOWN',
|
||||
message: '请从 Popup 打开功能(需下载远程脚本)',
|
||||
};
|
||||
}
|
||||
case 'GET_FLOATING_PANEL_STATE': {
|
||||
return { ok: true, data: { visible: isFloatingVisible() } };
|
||||
return { ok: true, data: { visible: isFeatureUiVisible() } };
|
||||
}
|
||||
case 'MOUNT_FEATURE': {
|
||||
await mountFeature(message.payload.featureId);
|
||||
await mountFeature(message.payload.featureId, message.payload.code);
|
||||
return { ok: true, data: { featureId: message.payload.featureId } };
|
||||
}
|
||||
case 'UNMOUNT_FEATURE': {
|
||||
|
||||
Reference in New Issue
Block a user