@vnejs/compatibility.platform.electron-with-views.achievement 0.1.9
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/dist/index.d.ts +13 -0
- package/dist/index.js +24 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +1 -0
- package/package.json +40 -0
- package/src/index.ts +38 -0
- package/src/types.ts +10 -0
- package/tsconfig.json +9 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
|
|
3
|
+
type AchievementIdPayload = {
|
|
4
|
+
id?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare class CompatibilityElectronAchievement extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
7
|
+
name: string;
|
|
8
|
+
subscribe: () => void;
|
|
9
|
+
onAchievementLocked: ({ id }?: AchievementIdPayload) => void;
|
|
10
|
+
onAchievementUnlocked: ({ id }?: AchievementIdPayload) => void;
|
|
11
|
+
fetch: (url: string, body: Record<string, unknown>) => Promise<Response>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import { regModule } from "@vnejs/shared";
|
|
3
|
+
const HEADERS = { "Content-Type": "application/json;charset=utf-8" };
|
|
4
|
+
export class CompatibilityElectronAchievement extends ModuleCore {
|
|
5
|
+
name = "compatibility.platform.electron-with-views.achievement";
|
|
6
|
+
subscribe = () => {
|
|
7
|
+
if (this.PARAMS.PLATFORMS.CURRENT_PLATFORM !== this.CONST.PLATFORMS.ELECTRON)
|
|
8
|
+
return;
|
|
9
|
+
this.on(this.EVENTS.ACHIEVEMENT.LOCKED, this.onAchievementLocked);
|
|
10
|
+
this.on(this.EVENTS.ACHIEVEMENT.UNLOCKED, this.onAchievementUnlocked);
|
|
11
|
+
};
|
|
12
|
+
onAchievementLocked = ({ id = "" } = {}) => {
|
|
13
|
+
const data = this.PARAMS.ACHIEVEMENT.INFO[id];
|
|
14
|
+
if (data)
|
|
15
|
+
this.fetch("achievement/lock", { id, data });
|
|
16
|
+
};
|
|
17
|
+
onAchievementUnlocked = ({ id = "" } = {}) => {
|
|
18
|
+
const data = this.PARAMS.ACHIEVEMENT.INFO[id];
|
|
19
|
+
if (data)
|
|
20
|
+
this.fetch("achievement/unlock", { id, data });
|
|
21
|
+
};
|
|
22
|
+
fetch = (url, body) => fetch(`${this.CONST.SYSTEM.HOST}/${url}`, { method: "POST", headers: HEADERS, body: JSON.stringify(body) });
|
|
23
|
+
}
|
|
24
|
+
regModule(CompatibilityElectronAchievement);
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
|
|
2
|
+
import type { Params as AchievementParams, PluginName as AchievementPluginName, SubscribeEvents as AchievementSubscribeEvents } from "@vnejs/contracts.views.achievement";
|
|
3
|
+
export type PluginEvents = ModuleCoreEvents & Record<AchievementPluginName, AchievementSubscribeEvents>;
|
|
4
|
+
export type PluginConstants = ModuleCoreConstants;
|
|
5
|
+
export type PluginSettings = ModuleCoreSettings;
|
|
6
|
+
export type PluginParams = ModuleCoreParams & Record<AchievementPluginName, AchievementParams>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/compatibility.platform.electron-with-views.achievement",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
23
|
+
"publish:major:plugin": "npm run publish:major",
|
|
24
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
25
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
26
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
27
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
28
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
29
|
+
},
|
|
30
|
+
"author": "",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@vnejs/module.core": "~0.1.0",
|
|
34
|
+
"@vnejs/contracts.views.achievement": "~0.1.0",
|
|
35
|
+
"@vnejs/shared": "~0.1.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@vnejs/configs.ts-common": "~0.1.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import { regModule } from "@vnejs/shared";
|
|
3
|
+
|
|
4
|
+
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
|
|
5
|
+
|
|
6
|
+
const HEADERS = { "Content-Type": "application/json;charset=utf-8" };
|
|
7
|
+
|
|
8
|
+
type AchievementIdPayload = {
|
|
9
|
+
id?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export class CompatibilityElectronAchievement extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
13
|
+
name = "compatibility.platform.electron-with-views.achievement";
|
|
14
|
+
|
|
15
|
+
subscribe = () => {
|
|
16
|
+
if (this.PARAMS.PLATFORMS.CURRENT_PLATFORM !== this.CONST.PLATFORMS.ELECTRON) return;
|
|
17
|
+
|
|
18
|
+
this.on(this.EVENTS.ACHIEVEMENT.LOCKED, this.onAchievementLocked);
|
|
19
|
+
this.on(this.EVENTS.ACHIEVEMENT.UNLOCKED, this.onAchievementUnlocked);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
onAchievementLocked = ({ id = "" }: AchievementIdPayload = {}) => {
|
|
23
|
+
const data = this.PARAMS.ACHIEVEMENT.INFO[id as keyof typeof this.PARAMS.ACHIEVEMENT.INFO];
|
|
24
|
+
|
|
25
|
+
if (data) this.fetch("achievement/lock", { id, data });
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
onAchievementUnlocked = ({ id = "" }: AchievementIdPayload = {}) => {
|
|
29
|
+
const data = this.PARAMS.ACHIEVEMENT.INFO[id as keyof typeof this.PARAMS.ACHIEVEMENT.INFO];
|
|
30
|
+
|
|
31
|
+
if (data) this.fetch("achievement/unlock", { id, data });
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
fetch = (url: string, body: Record<string, unknown>) =>
|
|
35
|
+
fetch(`${this.CONST.SYSTEM.HOST}/${url}`, { method: "POST", headers: HEADERS, body: JSON.stringify(body) });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
regModule(CompatibilityElectronAchievement);
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
|
|
2
|
+
import type { Params as AchievementParams, PluginName as AchievementPluginName, SubscribeEvents as AchievementSubscribeEvents } from "@vnejs/contracts.views.achievement";
|
|
3
|
+
|
|
4
|
+
export type PluginEvents = ModuleCoreEvents & Record<AchievementPluginName, AchievementSubscribeEvents>;
|
|
5
|
+
|
|
6
|
+
export type PluginConstants = ModuleCoreConstants;
|
|
7
|
+
|
|
8
|
+
export type PluginSettings = ModuleCoreSettings;
|
|
9
|
+
|
|
10
|
+
export type PluginParams = ModuleCoreParams & Record<AchievementPluginName, AchievementParams>;
|