first commit

This commit is contained in:
编码猿
2024-09-27 01:23:51 +08:00
commit 72ab70b6fd
212 changed files with 30296 additions and 0 deletions

View File

@@ -0,0 +1 @@
d087137f-1bfb-4d06-96ef-473d70be7e66

View File

@@ -0,0 +1,63 @@
import Config from "@config/Index.config";
import Utils from "@utils/Index.utils";
import {Http} from "@net/Http.net";
/**
* @Ipc()
* 实现居中IPC的注册用在controller方法上
* @param IpcParams 传入需要被注册的ipc类
* @constructor
*/
export function Ipc(IpcParams: { new (...args: any[]): {}; }[] ) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
/**
* 因为TS没有提供像java那种可以直接提取某个类中所有方法的系统方法
* 这边原本使用 Object.getOwnPropertyNames 能够正常提取类中方法,但是如果类中有被 @Inject() 依赖注入的属性
* 那么这个属性也会被 (new IpcParams())[val](),这样是肯定报错的,所以做下面约定!
* 在IPC 类中,如果在类的属性上使用 @Inject() 注入。那么请在类的属性名前加上 _例如:
* @Inject()
* private readonly _Net!: Http;
*/
IpcParams.forEach((val: { new (): any; } ) => {
Object.getOwnPropertyNames(val.prototype).splice(1)
.filter(f => !f.includes("_"))
.forEach(v => (new val())[v]())
})
}
}
/**
* @CreateApplicationIpc()
* 实现全局IPC的注册
* 能够自动实例化传入的类数组中的所有类,并自动调用类中的所有的方法
* @param IpcParams 类数组,实例:[ classIpc1, classIpc2, classIpc3 ]
* @constructor
*/
export function CreateApplicationIpc(IpcParams: { new (...args: any[]): {}; }[]): any {
return (_constructor: { new (...args: any[]): {}; } ) => {
IpcParams.forEach((val: { new (): any; } ) => {
Object.getOwnPropertyNames(val.prototype).splice(1)
.filter(f => !f.includes("_"))
.forEach(v => (new val())[v]())
})
}
}
/**
* @Render()
* 创建窗口
* @param templateName 要渲染的模板名称
* @constructor
*/
export function Render(templateName?: string) {
return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
/**
* 如果被打上注解的类中某个方法是配置文件中的默认启动窗口,那么调用这个方法来创建窗体
* 其他的方法一律不管由js前端渲染进程触发ipc创建
*/
if (propertyKey.includes((Config.StartPage.split("/"))[1])) {
// 如果没有传参数,那么采用方法名来创建窗体!
templateName == undefined ? Utils.startWindows(target,propertyKey) : Utils.startWindows(target,templateName)
}
}
}

View File

@@ -0,0 +1,40 @@
import Config from "@config/Index.config";
import {Http} from "@net/Http.net";
/**
* @GET()
* 用在service类的方法上。
* 如果不传参数将自动根据方法名获取接口请求的地址
* 如果传参了,那么使用用户传入的地址去发送网络请求
*
* 如果 useHandle 为 true 那么方法将获得ajax请求的数据
* 否则 不会将数据给方法
* @param RequestParams
* @constructor
*/
export function GET (RequestParams?: { url?: string, useHandle?: boolean, header?: { [index: string]: any } }) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
let url: string = Config.ApiUrl.ApiList[propertyKey],
handle: boolean = false,
header: object = {};
(RequestParams && RequestParams.url)
? url = RequestParams.url
: (RequestParams && RequestParams.useHandle)
? handle = RequestParams.useHandle
: (RequestParams && RequestParams.header)
? header = RequestParams.header
: '';
let OldMethods = descriptor.value;
if (handle) {
descriptor.value = async (data: { [key:string]: any }) =>
await OldMethods.apply(target, [ await (new Http).GET({ url: url, data: data, header: header }) ])
return descriptor
} else {
descriptor.value = async (data: { [key:string]: any }) =>
await (new Http).GET({ url: url, data: data, header: header })
return descriptor
}
}
}

View File

@@ -0,0 +1,39 @@
import 'reflect-metadata';
import IocModel from "@model/Ioc.model";
/**
* 收集类依赖
* @constructor
*/
export function Injectable() {
return (_constructor: { new (...args: any[]): {}; }) => {
if(IocModel.classPool.indexOf(_constructor) !== -1) {
throw new Error('无需重复收集类');
} else {
//注册
IocModel.classPool = [_constructor]
}
}
}
/**
* 将类依赖实例化然后注入到被装饰的属性中
* @constructor
*/
export function Inject() {
return function (target: any, propertyName: string) {
/**
* 使用 reflect-metadata 提供的内置 类型元数据键 design:type 通过反射拿到被装饰属性的类型
* 也就是 类属性要实例化 的 service 类
*/
const propertyType: any = Reflect.getMetadata('design:type', target, propertyName);
console.log("类属性要实例化 propertyType: ", propertyType)
if (IocModel.classPool.indexOf(propertyType) == -1) {
throw new Error('被装饰的属性所属的变量类型类,没有被装饰器@Injectable()注入,请检查!');
} else {
// 从存取器的数组中通过下标取出被装饰属性对应的service类然后实例化这个类在放入被装饰的属性中
target[propertyName] = new (IocModel.classPool[IocModel.classPool.indexOf(propertyType)])()
}
}
}

View File

@@ -0,0 +1,80 @@
import Utils from "@utils/Index.utils";
import {ApplicationMenu} from "@interactive/ApplicationMenu.interactive";
import {Touchbar} from "@interactive/Touchbar.interactive";
import {TrayInteractive} from "@interactive/Tray.interactive";
import { Application } from "@ipc/Application.ipc";
export function AutoLoadWindow(): any {
return (_constructor: {new(...args:any[]):{}} ) => {
return class extends _constructor {
constructor() {
// 这里只要动态 require 导入类即可,然后类上的装饰器就会运行
Utils.GetController()
super();
}
}
}
}
export function CreateApplicationMenu(): any {
return (_constructor: {new(...args:any[]):{}}) => {
return class extends _constructor {
constructor() {
// 创建顶部菜单
new ApplicationMenu()
super();
}
}
}
}
export function CreateTouchbar(): any {
return (_constructor: {new(...args:any[]):{}}) => {
return class extends _constructor {
constructor() {
/**
* 创建Touchbar
* 这边做延时300毫秒的原因解释起来有点复杂
* 1因为我设计了 @Inject() 和 @Injectable() 注解,而在 controller 中
* 被注解的属性 VideoImplService 存放的是 请求中间层而请求中间层是调用的Http请求方法GET而这个方法
* 为了拿到返回值所以设计成async异步的这就导致使用请求中间层的controller方法也是async。
* 2而使用的方法如果是 async 那么就会导致 注解 @Render() 内部 也就是 startWindows 方法内,在自动调用方法
* 获取传递给模板的方法返回数值的时候必须 await也就变成了await target[name]()。
* 而这个注解 @CreateTouchbar() 运行时间 和 注解 @AutoLoadWindow() 基本同时间跑,
* 所以会导致 @CreateTouchbar() 运行的时候太快了,尼玛币 await target[name]() 还没跑完,所以导致
* 存取器里面Windows.CurrentBrowserWindow 没有数值,所以 @CreateTouchbar() 所依赖的 Windows.CurrentBrowserWindow
* 为空所以touchbar菜单无法 setTouchBar 上。
* 3这里等300毫秒是等 await target[name]() 完成,窗口也创建完成,然后 Windows.CurrentBrowserWindow
* 再去创建 touchbar菜单。
* 好了,说完了....同学不要睡了!
*/
setTimeout(()=> new Touchbar(),3000)
super();
}
}
}
}
export function CreateTray(): any {
return (_constructor: {new(...args:any[]):{}}) => {
return class extends _constructor {
constructor() {
// 创建Mac系统顶部图标
new TrayInteractive()
super();
}
}
}
}
// export function CreateApplicationIpc(): any {
// return (_constructor: {new(...args:any[]):{}}) => {
// return class extends _constructor {
// constructor() {
// // 开启应用级ipc监听
// new Application()
// super();
// }
// }
// }
// }