Skip to content

Commit

Permalink
Merge branch 'main' into feature/angular-extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfuboy committed May 18, 2022
2 parents a0e5043 + 61094d4 commit ef30440
Show file tree
Hide file tree
Showing 39 changed files with 892 additions and 341 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
"**/*.js.map": true,
}
}

39 changes: 34 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
"electron:serve": "wait-on tcp:4200 && npm run electron:dev",
"electron:dev:static": "npm run electron:tsc && electron .",
"electron:dev": "npm run electron:tsc && electron . --development",
"electron:build": "npm-run-all -p build:* && npm run electron:tsc && electron-builder build",
"build": "electron-builder build",
"release": "electron-builder",
"build": "npm-run-all -p build:* && npm run electron:tsc && electron-builder build",
"release": "npm run build && electron-builder --publish=always",
"test": "npm-run-all --serial test:*",
"electron:tsc": "tsc -p tsconfig.json"
},
Expand Down Expand Up @@ -57,5 +56,35 @@
"typescript": "~4.6.4",
"wait-on": "6.0.1"
},
"__npminstall_done": false
}
"__npminstall_done": false,
"build": {
"appId": "com.foo.bar",
"productName": "Foo Bar",
"copyright": "Copyright © 2022 eolink",
"directories": {
"output": "release"
},
"files": [
"dist/",
"index.html",
"main.js",
"package.json"
],
"mac": {
"category": "public.app-category.utilities",
"icon": "resources/app.icns",
"artifactName": "eoapi_mac_${version}.${ext}",
"target": [
"dmg",
"zip"
]
},
"publish": [
{
"provider": "github",
"owner": "eolinker",
"repo": "eoapi"
}
]
}
}
2 changes: 1 addition & 1 deletion src/app/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ try {
} else if (arg.action === 'getFeature') {
returnValue = moduleManager.getFeature(arg.data.featureKey);
} else if (arg.action === 'saveSettings') {
returnValue = configuration.saveSettings(arg.data.settings);
returnValue = configuration.saveSettings(arg.data);
} else if (arg.action === 'saveModuleSettings') {
returnValue = configuration.saveModuleSettings(arg.data.moduleID, arg.data.settings);
} else if (arg.action === 'deleteModuleSettings') {
Expand Down
2 changes: 2 additions & 0 deletions src/app/electron-main/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const appVersion = require('../../../package.json').version;
export class EoUpdater {
constructor() {
this.watchLog();
// 是否自动更新
// autoUpdater.autoDownload = window.eo.getModuleSettings('common.app.autoUpdate') !== false;
if (appVersion.includes('beta')) autoUpdater.channel = 'beta';
console.log('appVersion', appVersion, autoUpdater.channel);
}
Expand Down
9 changes: 7 additions & 2 deletions src/platform/browser/IndexedDB/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class Storage extends Dexie implements StorageInterface {
}
});
table
.bulkGet(uuids)
.bulkGet(uuids.map(Number))
.then((existItems) => {
if (existItems) {
let newItems: Array<StorageItem> = [];
Expand All @@ -146,7 +146,12 @@ export class Storage extends Dexie implements StorageInterface {
});
// @ts-ignore
table
.bulkPut(newItems)
.bulkPut(
newItems.map((n: any) => ({
...n,
groupID: ~~n.groupID.replace('group-', ''),
}))
)
.then((result) => {
obs.next({ number: result, items: newItems });
obs.complete();
Expand Down
9 changes: 6 additions & 3 deletions src/platform/electron-browser/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@ window.eo.storageRemote = (args) => {
return output;
};

window.eo.saveSettings = (settings) => {
return ipcRenderer.sendSync('eo-sync', { action: 'saveSettings', data: { settings: settings } });
window.eo.saveSettings = ({ settings, nestedSettings }) => {
return ipcRenderer.sendSync('eo-sync', { action: 'saveSettings', data: { settings, nestedSettings } });
};

window.eo.saveModuleSettings = (moduleID, settings) => {
return ipcRenderer.sendSync('eo-sync', { action: 'saveModuleSettings', data: { moduleID: moduleID, settings: settings } });
return ipcRenderer.sendSync('eo-sync', {
action: 'saveModuleSettings',
data: { moduleID: moduleID, settings: settings },
});
};

window.eo.deleteModuleSettings = (moduleID) => {
Expand Down
51 changes: 28 additions & 23 deletions src/platform/node/configuration/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as path from 'path';
import { fileExists, readJson, writeJson } from '../../../../shared/node/file';

export class Configuration implements ConfigurationInterface {

/**
* 配置文件地址
*/
Expand Down Expand Up @@ -36,65 +35,71 @@ export class Configuration implements ConfigurationInterface {
* 保存配置文件
*/
private saveConfig(data: ConfigurationValueInterface): boolean {
return writeJson(this.configPath, data);
return writeJson(this.configPath, data, true);
}

/**
* 保存全局配置
*/
saveSettings(settings: ConfigurationValueInterface): boolean {
saveSettings({ settings = {}, nestedSettings = {} }): boolean {
let data = this.loadConfig();
data.settings = settings;
return this.saveConfig(data);
data.nestedSettings = nestedSettings;
return this.saveConfig(data);
}

/**
* 保存模块配置
* @param moduleID
* @param settings
* @param moduleID
* @param settings
*/
saveModuleSettings(moduleID: string, settings: ConfigurationValueInterface): boolean {
let data = this.loadConfig();
if (!data.settings) {
data.settings = {};
}
data.settings ??= {};
data.nestedSettings ??= {};
data.settings[moduleID] = settings;
const propArr = moduleID.split('.');
const target = propArr.slice(0, -1).reduce((p, k) => p[k], data.nestedSettings);
target[propArr.at(-1)] = settings;
return this.saveConfig(data);
}

/**
* 删除模块配置
* @param moduleID
* @returns
* @param moduleID
* @returns
*/
deleteModuleSettings(moduleID: string): boolean {
let data = this.loadConfig();
if (data.settings && data.settings[moduleID]) {
delete(data.settings[moduleID]);
delete data.settings[moduleID];
return this.saveConfig(data);
}
return false;
}

/**
* 获取全局配置
* 获取全局配置
* @returns
*/
getSettings(): ConfigurationValueInterface {
const data = this.loadConfig();
return data.settings;
return data;
}

/**
* 获取模块配置
* @param moduleID
* @returns
* 获取模块配置, 以小数点分割的属性链,如:common.app.update
* @param section
* @returns
*/
getModuleSettings(moduleID: string): ConfigurationValueInterface {
const settings = this.getSettings();
return settings[moduleID] || {};
}

getModuleSettings(section?: string): ConfigurationValueInterface {
const localSettings = this.getSettings();
localSettings.nestedSettings ??= {};
if (section) {
return section.split('.').reduce((p, k) => p[k], localSettings.nestedSettings);
}
return localSettings.nestedSettings;
}
}

export default () => new Configuration();
12 changes: 6 additions & 6 deletions src/platform/node/extension-manager/lib/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class ModuleManager implements ModuleManagerInterface {

/**
* 获取所有功能点列表
* @returns
* @returns
*/
getFeatures(): Map<string, Map<string, object>> {
return this.features;
Expand All @@ -134,11 +134,11 @@ export class ModuleManager implements ModuleManagerInterface {
}
return this.modules.get(moduleID);
}

/**
* 获取某个功能点的集合
* @param featureKey
* @returns
* @param featureKey
* @returns
*/
getFeature(featureKey: string): Map<string, object> {
return this.features.get(featureKey);
Expand Down Expand Up @@ -181,7 +181,7 @@ export class ModuleManager implements ModuleManagerInterface {

/**
* 清除功能点集合中的模块功能点
* @param moduleInfo
* @param moduleInfo
*/
private deleteFeatures(moduleInfo: ModuleInfo) {
if (moduleInfo.features && typeof moduleInfo.features === 'object' && isNotEmpty(moduleInfo.features)) {
Expand All @@ -200,7 +200,7 @@ export class ModuleManager implements ModuleManagerInterface {
private setup(moduleInfo: ModuleInfo) {
if (isNotEmpty(moduleInfo.moduleID)) {
this.set(moduleInfo);
}
}
}

/**
Expand Down
15 changes: 12 additions & 3 deletions src/platform/node/extension-manager/types/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ModuleHandlerResult } from './handler';
export enum ModuleType {
system = 'system',
app = 'app',
feature = 'feature'
feature = 'feature',
}

/**
Expand Down Expand Up @@ -58,11 +58,20 @@ export interface ModuleInfo {
sidePosition?: SidePosition;
// 配置项
configuration?: ModuleConfiguration;
/** 贡献点 */
contributes: ModuleContributes;
// 功能点配置
features?: {
[index: string]: object
[index: string]: object;
};
}
/**
* 贡献点
*/

export type ModuleContributes = {
configuration: ModuleConfiguration;
};

/**
* 模块配置项接口
Expand All @@ -71,7 +80,7 @@ export interface ModuleConfiguration {
title: string;
properties: {
[index: string]: ModuleConfigurationField;
}
};
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/shared/node/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import * as path from 'path';
* @param file
* @param data
*/
export const writeJson = (file: string, data: object): boolean => {
return writeFile(file, JSON.stringify(data));
export const writeJson = (file: string, data: object, formatted = false): boolean => {
return writeFile(file, formatted ? JSON.stringify(data, null, 2) : JSON.stringify(data));
};

/**
* Read json file, then return object.
* @param file
*/
export const readJson = (file: string): (object | null) => {
export const readJson = (file: string): object | null => {
const data: string = readFile(file);
if ('' === data) {
return null;
Expand All @@ -37,7 +37,7 @@ export const readFile = (file: string): string => {
/**
* Delete file.
* @param file string
* @returns
* @returns
*/
export const deleteFile = (file: string): boolean => {
try {
Expand All @@ -46,7 +46,7 @@ export const deleteFile = (file: string): boolean => {
} catch (e) {
return false;
}
}
};

/**
* Write data into file.
Expand Down
Loading

0 comments on commit ef30440

Please sign in to comment.