fix: enable disable extension error

This commit is contained in:
scarqin 2023-03-08 21:48:48 +08:00
parent e095a18f95
commit 54ee1309c0
7 changed files with 34 additions and 38 deletions

View File

@ -89,8 +89,6 @@ export class AppModule {
private notification: NotificationService
) {
this.init();
//! Feature show init before extensionService init
this.feature.init();
}
async init() {
//* Init language
@ -98,6 +96,9 @@ export class AppModule {
this.lang.init();
}
//* Init feature before extension install
this.feature.init();
//* Inject extension global data
this.global.injectGlobalData();
//* Init local mock server
@ -108,10 +109,10 @@ export class AppModule {
//* Init Extension
await this.extensionService.init();
this.theme.queryExtensionThemes();
//*Reset theme after theme/extension theme loading
Promise.all([promiseSystem]).then(() => {
this.theme.afterAllThemeLoad();
this.theme.watchInstalledExtensionsChange();
});
//* Init notification

View File

@ -8,9 +8,10 @@ type configKey = keyof typeof featureJSON;
})
export class FeatureControlService {
config: { [key: configKey | string]: boolean };
constructor(private message: MessageService) {}
init() {
constructor(private message: MessageService) {
this.config = featureJSON;
}
init() {
this.watchExtensionChange();
}
watchExtensionChange() {
@ -18,7 +19,11 @@ export class FeatureControlService {
if (inArg.type !== 'extensionsChange') return;
const extension = inArg.data.extension;
if (!extension?.features?.featureControl?.length) return;
switch (inArg.data.action) {
let aciton = inArg.data.action;
if (inArg.data.action === 'init') {
aciton = extension.enable ? 'enable' : 'disable';
}
switch (aciton) {
case 'install':
case 'enable': {
this.openFearure(extension?.features?.featureControl);

View File

@ -31,6 +31,7 @@ export class ThemeService {
) {
this.currentThemeID = this.setting.get('workbench.colorTheme') || this.defaultTheme;
this.coreThemes = this.getCoreThemes();
this.watchInstalledExtensionsChange();
}
async initTheme() {
await this.querySystemThemes();

View File

@ -77,7 +77,7 @@ type messageItem = {
export class ChatgptRobotComponent implements OnInit {
title = $localize`ChatGPT Robot`;
loading = false;
MAX_LIMIT = 10;
MAX_LIMIT = 5;
nowUsage = StorageUtil.get('cr_usage');
initMessage = {
date: new Date(),
@ -103,9 +103,7 @@ export class ChatgptRobotComponent implements OnInit {
private store: StoreService
) {}
ngOnInit() {
setTimeout(() => {
this.watchExtensionChange();
}, 5000);
this.watchExtensionChange();
}
login() {
window.open(APP_CONFIG.GITHUB_REPO_URL, '_blank');
@ -134,7 +132,7 @@ export class ChatgptRobotComponent implements OnInit {
this.loading = false;
if (!res?.result) {
this.messages.push({
text: `ChatGPT Error:${res?.msg}`,
text: `ChatGPT Error: ${res?.error || res?.msg || 'unknown error'}`,
date: new Date(),
reply: true,
type: 'text',

View File

@ -108,6 +108,7 @@ export class ApiComponent implements OnInit, OnDestroy {
}
async initExtensionExtra() {
this.rightExtras = [];
if (!this.router.url.includes('home/workspace/project/api/http/detail')) return;
const apiPreviewTab = this.extensionService.getValidExtensionsByFature('apiPreviewTab');
apiPreviewTab?.forEach(async (value, key) => {
const module = await this.extensionService.getExtensionPackage(key);

View File

@ -5,6 +5,7 @@ import { LanguageService } from 'eo/workbench/browser/src/app/core/services/lang
import { DISABLE_EXTENSION_NAMES } from 'eo/workbench/browser/src/app/shared/constants/storageKeys';
import { FeatureInfo, ExtensionInfo, SidebarView } from 'eo/workbench/browser/src/app/shared/models/extension-manager';
import { MessageService } from 'eo/workbench/browser/src/app/shared/services/message';
import StorageUtil from 'eo/workbench/browser/src/app/utils/storage/storage.utils';
import { APP_CONFIG } from 'eo/workbench/browser/src/environments/environment';
import { lastValueFrom, Subscription } from 'rxjs';
@ -39,6 +40,7 @@ export class ExtensionService {
this.updateInstalledInfo(this.getExtensions(), {
action: 'init'
});
return;
}
//* Web Installl
@ -52,9 +54,12 @@ export class ExtensionService {
const uniqueNames = [...Array.from(new Set(installedName)), ...this.webExtensionService.debugExtensionNames];
for (let i = 0; i < uniqueNames.length; i++) {
const name = uniqueNames[i];
await this.installExtension({
name
});
await this.installExtension(
{
name
},
true
);
}
}
getExtension(name: string) {
@ -173,14 +178,17 @@ export class ExtensionService {
* install extension by id
*
* @param id
* @param isInit first time install
* @returns if install success
*/
async installExtension({ name, version = 'latest' }): Promise<boolean> {
async installExtension({ name, version = 'latest' }, isInit = false): Promise<boolean> {
const successCallback = () => {
this.updateInstalledInfo(this.getExtensions(), {
action: 'install',
name
action: isInit ? 'init' : 'install',
name,
extension: this.installedList.find(val => val.name === name)
});
if (isInit) return;
if (!this.isEnable(name)) {
this.toggleEnableExtension(name, true);
}
@ -254,7 +262,7 @@ export class ExtensionService {
}
private setDisabledExtension(arr: string[]) {
localStorage.setItem(DISABLE_EXTENSION_NAMES, JSON.stringify(arr));
StorageUtil.set(DISABLE_EXTENSION_NAMES, arr);
this.disabledExtensionNames = arr;
}
async getExtensionPackage(name: string): Promise<any> {
@ -298,11 +306,7 @@ export class ExtensionService {
return result;
}
private getDisableExtensionNames() {
try {
return JSON.parse(localStorage.getItem(DISABLE_EXTENSION_NAMES) || '[]');
} catch (error) {
return [];
}
return StorageUtil.get(DISABLE_EXTENSION_NAMES) || [];
}
private async requestDetail(id) {
const debugExtension = this.webExtensionService.debugExtensions.find(val => val.name === id);

View File

@ -1,7 +1,5 @@
import { Injectable } from '@angular/core';
import { TranslateService } from 'eo/platform/common/i18n';
import { DISABLE_EXTENSION_NAMES } from 'eo/workbench/browser/src/app/shared/constants/storageKeys';
import { eoDeepCopy, JSONParse } from 'eo/workbench/browser/src/app/utils/index.utils';
import { eoDeepCopy } from 'eo/workbench/browser/src/app/utils/index.utils';
import StorageUtil from 'eo/workbench/browser/src/app/utils/storage/storage.utils';
import { APP_CONFIG } from 'eo/workbench/browser/src/environments/environment';
@ -141,18 +139,6 @@ export class WebExtensionService {
return true;
}
isEnable(name: string) {
return !this.getDisabledExtensionNames().includes(name);
}
getDisabledExtensionNames() {
try {
return (this.disabledExtensionNames = JSON.parse(localStorage.getItem(DISABLE_EXTENSION_NAMES) || '[]'));
} catch (error) {
return [];
}
}
insertScript(scriptText) {
const script = document.createElement('script');
script.type = 'text/javascript';