Skip to content

Commit fc8ed14

Browse files
committed
Add Skins and CurseForge plugin
1 parent dfdeacc commit fc8ed14

22 files changed

+2087
-475
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@typescript-eslint"
2929
],
3030
"rules": {
31+
"no-void": "off",
3132
"@typescript-eslint/no-explicit-any": "off",
3233
"@typescript-eslint/explicit-function-return-type": "off",
3334
"@typescript-eslint/member-delimiter-style": ["error", { "multiline": { "delimiter": "none", "requireLast": false }, "singleline": { "delimiter": "comma" } }]

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ELECRON_SKIP_BINARY_DOWNOAD=1

package-lock.json

Lines changed: 1588 additions & 401 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"build:ai": "pl-plugin-dev build -e packages/AuthlibInjector/index.ts",
1313
"dev:bot": "pl-plugin-dev -e packages/MCBot/index.tsx",
1414
"build:bot": "pl-plugin-dev build -e packages/MCBot/index.tsx",
15+
"dev:cf": "pl-plugin-dev -e packages/CurseForge/index.tsx",
16+
"build:cf": "pl-plugin-dev build -e packages/CurseForge/index.tsx",
17+
"dev:skins": "pl-plugin-dev -e packages/Skins/index.tsx",
18+
"build:skins": "pl-plugin-dev build -e packages/Skins/index.tsx",
1519
"test": "npm run lint"
1620
},
1721
"repository": {
@@ -31,22 +35,22 @@
3135
},
3236
"homepage": "https://github.com/Apisium/PureLauncherOfficialPlugins#readme",
3337
"dependencies": {
34-
"@types/fs-extra": "^8.1.0",
35-
"@types/node": "^13.7.1",
36-
"@types/react": "^16.9.19",
37-
"@types/react-router-dom": "^5.1.3",
38-
"@xmcl/core": "^2.0.1-alpha.1",
39-
"@xmcl/text-component": "^2.0.1-alpha.1",
38+
"@xmcl/task": "^2.1.2",
39+
"@xmcl/text-component": "^2.1.0",
40+
"cloudscraper": "^4.6.0",
4041
"commander": "^4.1.1",
4142
"crc": "^3.8.0",
4243
"crc32-stream": "^3.0.1",
44+
"filenamify": "^4.1.0",
4345
"fs-extra": "^8.1.0",
4446
"history": "^4.10.1",
4547
"minecraft-data": "^2.41.0",
4648
"minecraft-protocol": "^1.11.0",
4749
"pure-launcher": "git+https://github.com/Apisium/PureLauncher.git",
4850
"react-router-cache-route": "^1.8.4",
51+
"request": "^2.88.2",
4952
"reqwq": "^0.2.4",
53+
"semver": "^7.1.3",
5054
"yazl": "^2.5.1"
5155
},
5256
"husky": {
@@ -55,19 +59,27 @@
5559
}
5660
},
5761
"devDependencies": {
58-
"@babel/core": "^7.8.4",
62+
"@babel/core": "^7.8.7",
5963
"@babel/plugin-proposal-optional-chaining": "^7.8.3",
60-
"@typescript-eslint/eslint-plugin": "^2.19.0",
61-
"@typescript-eslint/parser": "^2.19.0",
64+
"@types/fs-extra": "^8.1.0",
65+
"@types/node": "^13.9.0",
66+
"@types/react": "^16.9.23",
67+
"@types/react-router-dom": "^5.1.3",
68+
"@typescript-eslint/eslint-plugin": "^2.23.0",
69+
"@typescript-eslint/parser": "^2.23.0",
70+
"@xmcl/core": "^2.0.4",
71+
"@xmcl/installer": "^2.4.0",
72+
"@xmcl/unzip": "^1.1.1",
6273
"babel-plugin-module-resolver": "^4.0.0",
74+
"electron": "^8.1.0",
6375
"eslint": "^6.8.0",
6476
"eslint-config-standard": "^14.1.0",
6577
"eslint-plugin-import": "^2.20.1",
6678
"eslint-plugin-node": "^11.0.0",
6779
"eslint-plugin-promise": "^4.2.1",
68-
"eslint-plugin-react": "^7.18.3",
80+
"eslint-plugin-react": "^7.19.0",
6981
"eslint-plugin-standard": "^4.0.1",
70-
"husky": "^4.2.1",
71-
"typescript": "^3.7.5"
82+
"husky": "^4.2.3",
83+
"typescript": "^3.8.3"
7284
}
7385
}

packages/AuthlibInjector/AuthlibInjectorAuthenticator.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Authenticator, $ as $0, constants, fs, profilesStore, fetchJson, getJson } from '@plugin'
1+
import { Authenticator, $ as $0, constants, fs, profilesStore, fetchJson, getJson, notice } from '@plugin'
22
import { join } from 'path'
33
import $ from './langs'
44

@@ -67,13 +67,12 @@ export const AUTHLIB_INJECTOR = 'AuthlibInjector'
6767
}
6868
]
6969
})
70-
export default class AuthlibInjectorAuthenticator extends Auth implements Authenticator.SkinChangeable {
70+
export default class AuthlibInjectorAuthenticator extends Auth {
7171
private db: Record<string, AuthlibInjectorProfile> = { }
7272

7373
constructor () {
7474
super()
7575
try { this.db = fs.readJsonSync(DATABASE_PATH, { throws: false }) || { } } catch (e) { console.error(e) }
76-
console.log(this.db)
7776
}
7877

7978
public async login (options: { url: string, email: string, password: string }) {
@@ -157,20 +156,24 @@ export default class AuthlibInjectorAuthenticator extends Auth implements Authen
157156
await fs.writeJson(DATABASE_PATH, this.db)
158157
}
159158

160-
public async validate (key: string) {
159+
public async validate (key: string, autoRefresh = true) {
161160
await this.checkLogined(key)
162161
const p = this.db[key]
163162
if (!p) return
164163
const json = await fetchJson(join(p.url, 'authserver/validate'), true,
165164
{ accessToken: p.accessToken, clientToken: p.clientToken })
166165
.catch(e => {
167166
console.error(e)
168-
throw new Error($0('Network connection failed!'))
167+
const err: any = new Error($0('Network connection failed!'))
168+
err.connectFailed = true
169+
throw err
169170
})
170-
if (json) {
171-
console.log(json.errorMessage)
172-
return true
173-
} else return false
171+
if (json && (!autoRefresh || !await this.refresh(key).then(() => true, () => false))) {
172+
if (json.errorMessage) notice({ content: json.errorMessage, error: true })
173+
delete this.db[key]
174+
await fs.writeJson(DATABASE_PATH, this.db)
175+
return false
176+
} else return true
174177
}
175178

176179
public getData (key: string) {
@@ -183,10 +186,10 @@ export default class AuthlibInjectorAuthenticator extends Auth implements Authen
183186
return Object.values(this.db)
184187
}
185188

186-
public async changeSkin (key: string, path: string, slim: boolean) {
187-
console.log(key, path, slim)
188-
// TODO:
189-
}
189+
// public async changeSkin (key: string, path: string, slim: boolean) {
190+
// console.log(key, path, slim)
191+
// // TODO:
192+
// }
190193

191194
private async checkLogined (key: string) {
192195
this.db = await fs.readJson(DATABASE_PATH, { throws: false }) || { }

packages/AuthlibInjector/index.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* eslint-disable @typescript-eslint/explicit-function-return-type */
1+
/* eslint-disable object-curly-newline, @typescript-eslint/explicit-function-return-type */
22
import AuthlibInjectorAuthenticator, { AUTHLIB_INJECTOR, AuthlibInjectorProfile } from './AuthlibInjectorAuthenticator'
33
import { join } from 'path'
4-
import { createHash } from 'crypto'
54
import { version } from './package.json'
65
import { LaunchOption } from '@xmcl/core'
7-
import { Plugin, plugin, event, pluginMaster, profilesStore, fs, constants, download, getJson, $ as $0 } from '@plugin'
6+
import { Plugin, plugin, event, pluginMaster, profilesStore, fs, constants,
7+
download, getJson, $ as $0, openLoginDialog } from '@plugin'
88
import $ from './langs'
99

1010
const JAR_PATH = join(constants.APP_PATH, 'authlib-injector/authlib-injector.jar')
@@ -15,7 +15,7 @@ const JSON_URL = 'https://bmclapi2.bangbang93.com/mirrors/authlib-injector/artif
1515
author: 'Shirasawa',
1616
title: () => 'Authlib-Injector',
1717
description: () => $.description,
18-
id: '@Shirasawa/multi-instances'
18+
id: '@PureLauncher/multi-instances'
1919
})
2020
export default class AuthlibInjector extends Plugin {
2121
constructor () {
@@ -34,14 +34,12 @@ export default class AuthlibInjector extends Plugin {
3434
const url = json?.download_url
3535
if (!url) throw new Error($0('Network connection failed!'))
3636
try {
37-
await download({ url, file: JAR_PATH }, 'Authlib Injector')
3837
const hash = json.checksums?.sha256
39-
// eslint-disable-next-line promise/param-names
40-
if (hash && hash !== await new Promise<string>((resolve, e) => {
41-
const s = createHash('sha1').setEncoding('hex')
42-
fs.createReadStream(JAR_PATH).on('error', e).pipe(s).on('error', e)
43-
.on('finish', () => resolve(s.read()))
44-
})) throw new Error($.downloadFailed)
38+
await download({
39+
url,
40+
destination: JAR_PATH,
41+
checksum: hash ? { algorithm: 'sha256', hash } : undefined
42+
}, 'Authlib Injector')
4543
} catch (e) {
4644
await fs.unlink(JAR_PATH).catch(console.error)
4745
throw e
@@ -52,6 +50,15 @@ export default class AuthlibInjector extends Plugin {
5250
public preLaunch (_: string, option: LaunchOption) {
5351
const profile = profilesStore.getCurrentProfile()
5452
if (profile?.type !== AUTHLIB_INJECTOR) return
55-
option.yggdrasilAgent = { jar: JAR_PATH, server: (profile as AuthlibInjectorProfile).url }
53+
const server = (profile as AuthlibInjectorProfile).url
54+
// option.extraJVMArgs.push('-Dauthlibinjector.side=client', '-Dauthlibinjector.yggdrasil.prefetched=' + btoa(server))
55+
option.yggdrasilAgent = { jar: JAR_PATH, server }
56+
}
57+
58+
@event()
59+
public dragIn (t: DataTransfer) {
60+
let data = t.getData('text/plain')
61+
if (!data.startsWith('authlib-injector:yggdrasil-server:') || !(data = data.slice(34))) return
62+
openLoginDialog(AUTHLIB_INJECTOR, { url: decodeURIComponent(data) })
5663
}
5764
}

0 commit comments

Comments
 (0)