Skip to content

Commit

Permalink
:fix: bug: charlotte xiaomawang error
Browse files Browse the repository at this point in the history
  • Loading branch information
FurryR committed May 17, 2024
1 parent ba5f29f commit 91bd257
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# [👾 Hyren](https://furryr.github.io/hyren/hyren.release.user.js)

> 在任何地方使用 Turbowarp 特性。
>
>
> (温馨提示) 点击标题即可安装!
[![Visitors](https://hits.dwyl.com/FurryR/hyren.svg?style=flat-square)](http://github.com/FurryR/hyren)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# [👾 Hyren](https://furryr.github.io/hyren/hyren.release.user.js)

> A tampermonkey script to use Turbowarp features anywhere.
>
>
> (Hint) Click title to install!
[![Visitors](https://hits.dwyl.com/FurryR/hyren.svg?style=flat-square)](http://github.com/FurryR/hyren)
Expand Down
75 changes: 37 additions & 38 deletions src/compiler/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,46 +328,45 @@ export default function patchRenderer(vm: VM) {
}
if (vm.runtime.renderer) {
onReady()
} else {
const _attachRenderer = vm.runtime.constructor.prototype.attachRenderer
vm.runtime.constructor.prototype.attachRenderer = function (
renderer: RenderWebGL
) {
const originalRenderer = this.renderer
// vm.runtime.constructor.prototype.attachRenderer = _attachRenderer
_attachRenderer.call(this, renderer)
// Xiaomawang attaches renderer twice.
if (originalRenderer !== renderer && !(renderer instanceof RenderWebGL)) {
if ((renderer as any).clearAllSkins) {
// Patch Xiaomawang private APIs
const { clearAllSkins } = renderer as any
onReady()
// clearAllSkins() is used to dispose all skins. This API exists because Xiaomawang's developers have skill issue.
renderer.constructor.prototype.clearAllSkins = clearAllSkins
// extractDrawable() is used to extract the drawable (for dragging or something else). It slows down the renderer for a lot, so replace it with a no-op function would be fine.
renderer.constructor.prototype.extractDrawable = function () {
return {
data: '',
x: 0,
y: 0,
width: 0,
height: 0,
scratchOffset: [0, 0]
}
}
const _attachRenderer = vm.runtime.constructor.prototype.attachRenderer
vm.runtime.constructor.prototype.attachRenderer = function (
renderer: RenderWebGL
) {
const originalRenderer = this.renderer
// vm.runtime.constructor.prototype.attachRenderer = _attachRenderer
_attachRenderer.call(this, renderer)
// Xiaomawang attaches renderer twice.
if (originalRenderer !== renderer && !(renderer instanceof RenderWebGL)) {
if ((renderer as any).clearAllSkins) {
// Patch Xiaomawang private APIs
const { clearAllSkins } = renderer as any
onReady()
// clearAllSkins() is used to dispose all skins. This API exists because Xiaomawang's developers have skill issue.
renderer.constructor.prototype.clearAllSkins = clearAllSkins
// extractDrawable() is used to extract the drawable (for dragging or something else). It slows down the renderer for a lot, so replace it with a no-op function would be fine.
renderer.constructor.prototype.extractDrawable = function () {
return {
data: '',
x: 0,
y: 0,
width: 0,
height: 0,
scratchOffset: [0, 0]
}
new ResizeObserver(() => {
renderer.resize(
renderer.canvas.clientWidth,
renderer.canvas.clientHeight
)
requestAnimationFrame(() => {
;(renderer as any).dirty = true
renderer.draw()
})
}).observe(renderer.canvas)
} else {
onReady()
}
new ResizeObserver(() => {
renderer.resize(
renderer.canvas.clientWidth,
renderer.canvas.clientHeight
)
requestAnimationFrame(() => {
;(renderer as any).dirty = true
renderer.draw()
})
}).observe(renderer.canvas)
} else {
onReady()
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,13 @@ export default function patchRuntime(vm: VM) {
) {
// ClipCC has a bug about vm.installTargets -- it didn't return a Promise.
// TODO: remove this when clipcc new version is released.
return Promise.resolve(_installTargets
.call(this, targets, extensions, wholeProject))
.then(() => {
if (wholeProject) {
this.runtime.parseProjectOptions()
}
})
return Promise.resolve(
_installTargets.call(this, targets, extensions, wholeProject)
).then(() => {
if (wholeProject) {
this.runtime.parseProjectOptions()
}
})
}
vm.runtime.constructor.prototype.findProjectOptionsComment = function () {
const target = this.getTargetForStage()
Expand Down
3 changes: 3 additions & 0 deletions src/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { MainLog } from './log'
import patchRuntime from './compiler/runtime'

export function loadHyren(vm: VM) {
if (Reflect.has(window, 'Hyren')) {
return
}
vm.on('LOCALE_CHANGED' as any, () => {
locale.value = (vm as any).getLocale()
})
Expand Down

0 comments on commit 91bd257

Please sign in to comment.