@talex-touch/utils 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/base/index.ts CHANGED
@@ -125,7 +125,7 @@ export enum SupportOS {
125
125
  WINDOWS = 'Windows',
126
126
  WINDOWS_11 = 'Windows 10 Pro',
127
127
  WINDOWS_10 = 'Windows 10',
128
-
128
+
129
129
  MACOS = 'macOS',
130
130
  MACOS_SONOMA = 'macOS Sonoma',
131
131
  MACOS_MONTEREY = 'macOS Monterey',
@@ -154,7 +154,7 @@ export enum SupportOS {
154
154
  IPADOS = 'iPadOS',
155
155
  IPADOS_17 = 'iPadOS 17',
156
156
  IPADOS_16 = 'iPadOS 16',
157
-
157
+
158
158
  WEB = 'Web',
159
159
  WEB_CHROME = 'Web Chrome',
160
160
  WEB_FIREFOX = 'Web Firefox',
package/channel/index.ts CHANGED
@@ -10,7 +10,7 @@ export enum DataCode {
10
10
  }
11
11
 
12
12
  export interface ITouchChannel {
13
-
13
+
14
14
  /**
15
15
  * Register a channel
16
16
  * @description Register a channel, and return a function to cancel the registration
@@ -30,7 +30,7 @@ export interface ITouchChannel {
30
30
  }
31
31
 
32
32
  export interface ITouchClientChannel {
33
-
33
+
34
34
  /**
35
35
  * Register a channel
36
36
  * @description Register a channel, and return a function to cancel the registration
@@ -72,9 +72,10 @@ export interface RawChannelSyncData {
72
72
  }
73
73
 
74
74
  export interface RawChannelHeaderData {
75
- status: 'reply' | 'request'
76
- type: ChannelType
77
- _originData?: any
75
+ status: "reply" | "request";
76
+ type: ChannelType;
77
+ _originData?: any;
78
+ event: Electron.IpcMainEvent | Electron.IpcRendererEvent;
78
79
  }
79
80
 
80
81
  export interface RawChannelData {
@@ -85,10 +86,14 @@ export interface RawChannelData {
85
86
 
86
87
  export interface RawStandardChannelData extends RawChannelData {
87
88
  code: DataCode
88
- data?: any
89
+ data?: IChannelData
89
90
  plugin?: string
90
91
  }
91
92
 
92
93
  export interface StandardChannelData extends RawStandardChannelData {
93
- reply: (code: DataCode, data: any) => void
94
+ reply: (code: DataCode, data: IChannelData) => void
95
+ }
96
+
97
+ export interface IChannelData {
98
+ [prop: string]: any
94
99
  }
@@ -0,0 +1,40 @@
1
+ import { exec, ExecException } from 'child_process';
2
+
3
+ export interface IGlobalPkgResult {
4
+ exist: boolean
5
+ error?: ExecException
6
+ name: string
7
+ version: string
8
+ }
9
+
10
+ export function checkGlobalPackageExist(packageName: string) {
11
+ return new Promise((resolve, reject) => {
12
+ exec(`npm list -g ${packageName}`, (error, stdout, stderr) => {
13
+ if (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (stderr) {
18
+ reject(stderr);
19
+ return;
20
+ }
21
+
22
+ const lines = stdout.split('\n');
23
+ const lastLine = lines[lines.length - 2];
24
+ const match = lastLine.match(/(\S+)@(\S+)/);
25
+ if (match) {
26
+ resolve({
27
+ exist: true,
28
+ name: match[1],
29
+ version: match[2]
30
+ } as IGlobalPkgResult);
31
+ return;
32
+ }
33
+
34
+ resolve({
35
+ exist: false
36
+ }
37
+
38
+ });
39
+ })
40
+ }
package/common/index.ts CHANGED
@@ -11,8 +11,8 @@ export function anyStr2Num(str: string): BigInt {
11
11
 
12
12
  numbers.push(("" + e).padStart(5, "0"))
13
13
 
14
- if ( minium > e ) minium = e
15
-
14
+ if (minium > e) minium = e
15
+
16
16
  }
17
17
 
18
18
  // each number transform
@@ -28,7 +28,7 @@ export function num2anyStr(num: BigInt): string {
28
28
 
29
29
  let text = ''
30
30
 
31
- for ( let i = 0; i < length; i++ ) {
31
+ for (let i = 0; i < length; i++) {
32
32
  const str = strs[1].slice(i * 2, i * 2 + 2)
33
33
 
34
34
  // strs[1] = strs[1].replace(str, (BigInt(+str) + BigInt(baseNum)).toString().padStart(5, "0"))
@@ -36,4 +36,4 @@ export function num2anyStr(num: BigInt): string {
36
36
  }
37
37
 
38
38
  return text
39
- }
39
+ }
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "main": "./index.ts",
3
- "name": "@talex-touch/utils",
4
- "author": "TalexDreamSoul",
5
- "module": "./index.ts",
6
- "license": "MPL-2.0",
7
- "private": false,
8
- "version": "1.0.10",
9
- "scripts": {
10
- "publish": "npm publish --access public"
11
- },
12
- "keywords": [
13
- "vue",
14
- "electron",
15
- "talex-touch"
16
- ],
17
- "repository": {
18
- "url": "https://github.com/talex-touch/talex-touch.git",
19
- "type": "git"
20
- },
21
- "description": "TalexTouch series utils",
22
- "dependencies": {
23
- "path-browserify": "^1.0.1",
24
- "vue": "^3.3.4"
25
- },
26
- "peerDependencies": {
27
- "electron": "^24.4.0",
28
- "vue": "^3.2.47"
29
- }
30
- }
1
+ {
2
+ "main": "./index.ts",
3
+ "name": "@talex-touch/utils",
4
+ "author": "TalexDreamSoul",
5
+ "module": "./index.ts",
6
+ "license": "MPL-2.0",
7
+ "private": false,
8
+ "version": "1.0.11",
9
+ "scripts": {
10
+ "publish": "npm publish --access public"
11
+ },
12
+ "keywords": [
13
+ "vue",
14
+ "electron",
15
+ "talex-touch"
16
+ ],
17
+ "repository": {
18
+ "url": "https://github.com/talex-touch/talex-touch.git",
19
+ "type": "git"
20
+ },
21
+ "description": "TalexTouch series utils",
22
+ "dependencies": {
23
+ "path-browserify": "^1.0.1",
24
+ "vue": "^3.4.19"
25
+ },
26
+ "peerDependencies": {
27
+ "electron": "^24.4.0",
28
+ "vue": "^3.2.47"
29
+ }
30
+ }
package/plugin/channel.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // const { ipcRenderer, IpcMainEvent } = require("electron");
2
- import { ipcRenderer, IpcRendererEvent } from "electron";
2
+ import { ipcRenderer, type IpcRendererEvent } from "electron";
3
3
  import {
4
4
  ChannelType,
5
5
  DataCode,
@@ -22,8 +22,8 @@ class TouchChannel implements ITouchClientChannel {
22
22
  ipcRenderer.on("@plugin-process-message", this.__handle_main.bind(this));
23
23
  }
24
24
 
25
- __parse_raw_data(e: typeof IpcRendererEvent, arg: any): RawStandardChannelData | null {
26
- console.log("Raw data: ", arg, e);
25
+ __parse_raw_data(e: IpcRendererEvent, arg: any): RawStandardChannelData | null {
26
+ console.debug("Raw data: ", arg, e);
27
27
  if (arg) {
28
28
  const { name, header, code, data, sync } = arg;
29
29
 
@@ -33,6 +33,7 @@ class TouchChannel implements ITouchClientChannel {
33
33
  status: header.status || "request",
34
34
  type: ChannelType.PLUGIN,
35
35
  _originData: arg,
36
+ event: e
36
37
  },
37
38
  sync,
38
39
  code,
package/plugin/index.ts CHANGED
@@ -15,6 +15,8 @@ export enum PluginStatus {
15
15
  export interface IPluginIcon {
16
16
  type: string | 'remixicon' | 'class'
17
17
  value: any
18
+
19
+ init(): Promise<void>
18
20
  }
19
21
 
20
22
  export interface IPlatformInfo {
@@ -50,6 +52,12 @@ export interface ITouchPlugin extends IPluginBaseInfo {
50
52
  dev: IPluginDev
51
53
  webViewInit: boolean
52
54
  webview: IPluginWebview
55
+ features: IPluginFeature[]
56
+
57
+ addFeature(feature: IPluginFeature): boolean
58
+ delFeature(featureId: string): boolean
59
+ getFeature(featureId: string): IPluginFeature | null
60
+ getFeatures(): IPluginFeature[]
53
61
 
54
62
  get status(): PluginStatus
55
63
  set status(v: PluginStatus)
@@ -58,6 +66,22 @@ export interface ITouchPlugin extends IPluginBaseInfo {
58
66
  disable(): Promise<boolean>
59
67
  }
60
68
 
69
+ export interface IFeatureCommand {
70
+ type: "match" | "contain" | "regex" | "function" | "over" | "image" | "files" | "directory" | "window"
71
+ value: string | string[] | RegExp | Function
72
+ onTrigger(): void
73
+ }
74
+
75
+ export interface IPluginFeature {
76
+ id: string
77
+ name: string
78
+ desc: string
79
+ icon: IPluginIcon
80
+ push: boolean
81
+ platform: IPlatform
82
+ commands: IFeatureCommand[]
83
+ }
84
+
61
85
  export interface IPluginManager {
62
86
  plugins: Map<string, ITouchPlugin>
63
87
  active: string | null
@@ -1,13 +1,11 @@
1
1
  import { genChannel } from '../channel';
2
- import {
3
- BrowserWindowConstructorOptions
4
- } from "electron";
2
+ import { IPluginFeature } from '../index'
5
3
 
6
4
  export function regShortcut(key: string, func: Function) {
7
5
  const channel = genChannel()
8
6
 
9
7
  const res = channel.sendSync('shortcon:reg', { key })
10
- if ( res instanceof String ) throw new Error(res)
8
+ if ( res instanceof String ) throw new Error(String(res))
11
9
  if ( res === false ) return false;
12
10
 
13
11
  channel.regChannel('shortcon:trigger', ({ data }) => key === data.key && func())
@@ -15,4 +13,16 @@ export function regShortcut(key: string, func: Function) {
15
13
  return true;
16
14
  }
17
15
 
16
+ export function regFeature(feature: IPluginFeature): boolean {
17
+ const channel = genChannel()
18
+
19
+ return channel.sendSync('feature:reg', { feature })
20
+ }
21
+
22
+ export function unRegFeature(id: string): boolean {
23
+ const channel = genChannel()
24
+
25
+ return channel.sendSync('feature:unreg', { feature: id })
26
+ }
27
+
18
28
  export * from './window';
@@ -17,7 +17,7 @@ export function toggleWinVisible(id: number, visible?: boolean): boolean {
17
17
  return res.visible
18
18
  }
19
19
 
20
- export function setWindowProperty<K extends keyof BrowserWindow, V>(id: number, property: {
20
+ export function setWindowProperty(id: number, property: {
21
21
 
22
22
  }): boolean {
23
23
  const res = genChannel().sendSync('window:property', { id, property })