Skip to content

Commit

Permalink
🎨 Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
FurryR committed Nov 5, 2023
1 parent f475591 commit 153483c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
36 changes: 18 additions & 18 deletions src/injector/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const MAX_LISTENING_MS = 30 * 1000;
* @param {!string} opcode The opcode to examine for extension.
* @return {?string} The extension ID, if it exists and is not a core extension.
*/
function getExtensionIdForOpcode(opcode: string) {
function getExtensionIdForOpcode (opcode: string) {
// Allowed ID characters are those matching the regular expression [\w-]: A-Z, a-z, 0-9, and hyphen ("-").
const index = opcode.indexOf('_');
const forbiddenSymbols = /[^\w-]/g;
Expand All @@ -49,9 +49,9 @@ function getExtensionIdForOpcode(opcode: string) {
* @param vm Virtual machine instance. For some reasons we cannot use VM here.
* @returns Blockly instance.
*/
function getBlocklyInstance(vm: ChibiCompatibleVM): any | null {
function getBlocklyInstance (vm: ChibiCompatibleVM): any | null {
// Hijack Function.prototype.apply to get React element instance.
function hijack(fn: (...args: unknown[]) => unknown) {
function hijack (fn: (...args: unknown[]) => unknown) {
const _orig = Function.prototype.apply;
Function.prototype.apply = function (thisArg: any) {
return thisArg;
Expand Down Expand Up @@ -88,7 +88,7 @@ function getBlocklyInstance(vm: ChibiCompatibleVM): any | null {
* @param open window.open function (compatible with ccw).
* @return Callback promise. After that you could use window.chibi.vm to get the virtual machine.
*/
export function trap(open: typeof window.open): Promise<void> {
export function trap (open: typeof window.open): Promise<void> {
window.chibi = {
// @ts-expect-error defined in webpack define plugin
version: __CHIBI_VERSION__,
Expand Down Expand Up @@ -130,7 +130,7 @@ export function trap(open: typeof window.open): Promise<void> {
* Inject into the original virtual machine.
* @param vm {ChibiCompatibleVM} Original virtual machine instance.
*/
export function inject(vm: ChibiCompatibleVM) {
export function inject (vm: ChibiCompatibleVM) {
const loader = (window.chibi.loader = new ChibiLoader(vm));
const originalLoadFunc = vm.extensionManager.loadExtensionURL;
const getLocale = vm.getLocale;
Expand All @@ -154,27 +154,27 @@ export function inject(vm: ChibiCompatibleVM) {
} else {
whetherSideload = env
? confirm(
format('chibi.tryLoadInEnv', {
extensionURL,
url,
env
})
)
format('chibi.tryLoadInEnv', {
extensionURL,
url,
env
})
)
: confirm(
format('chibi.tryLoadInEnv', {
extensionURL,
url
})
);
format('chibi.tryLoadInEnv', {
extensionURL,
url
})
);
}
if (whetherSideload) {
await loader.load(
url,
(env
? env
: confirm(format('chibi.loadInSandbox'))
? 'sandboxed'
: 'unsandboxed') as 'unsandboxed' | 'sandboxed'
? 'sandboxed'
: 'unsandboxed') as 'unsandboxed' | 'sandboxed'
);
const extensionId = loader.getIdByUrl(url);
// @ts-expect-error internal hack
Expand Down
34 changes: 17 additions & 17 deletions src/loader/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class UnsandboxedLoader {
*/
loading: Promise<void> = Promise.resolve();

async load(extensionURL: string, ctx: Context) {
async load (extensionURL: string, ctx: Context) {
return (this.loading = this.loading.then(() => {
return (async () => {
try {
Expand Down Expand Up @@ -122,7 +122,7 @@ class ChibiLoader {
*/
loadedScratchExtension = new Map<string, ScratchExtension>();

constructor(vm: VM) {
constructor (vm: VM) {
this.vm = vm;
dispatch.setService('loader', this).catch((e: Error) => {
error(`ChibiLoader was unable to register extension service: ${JSON.stringify(e)}`);
Expand All @@ -134,7 +134,7 @@ class ChibiLoader {
* @param {ExtensionClass | string} ext - Extension's data.
* @param {'sandboxed' | 'unsandboxed'} env - Extension's running environment.
*/
async load(ext: string | ExtensionClass, env: 'sandboxed' | 'unsandboxed' = 'sandboxed') {
async load (ext: string | ExtensionClass, env: 'sandboxed' | 'unsandboxed' = 'sandboxed') {
if (typeof ext === 'string') {
switch (env) {
case 'sandboxed':
Expand Down Expand Up @@ -182,7 +182,7 @@ class ChibiLoader {
* Reload a scratch-standard extension.
* @param {string} extensionId - Extension's ID
*/
async reload(extensionId: string) {
async reload (extensionId: string) {
const targetExt = this.loadedScratchExtension.get(extensionId);
if (!targetExt) {
throw new Error(`Cannot locate extension ${extensionId}.`);
Expand All @@ -202,7 +202,7 @@ class ChibiLoader {
return info;
}

getIdByUrl(url: string) {
getIdByUrl (url: string) {
for (const [extId, ext] of this.loadedScratchExtension.entries()) {
if (ext.url === url) {
return extId;
Expand All @@ -216,7 +216,7 @@ class ChibiLoader {
* original extension manager to reload locales. It should
* be replaced when there's a better solution.
*/
reloadAll() {
reloadAll () {
const allPromises: Promise<ExtensionMetadata | void>[] = [];
for (const [extId] of this.loadedScratchExtension.entries()) {
allPromises.push(this.reload(extId));
Expand All @@ -231,7 +231,7 @@ class ChibiLoader {
* @param {string} serviceName - the name of the service hosting the extension
* @private
*/
private _registerExtensionInfo(
private _registerExtensionInfo (
extensionObject: ExtensionClass | null,
extensionInfo: ExtensionMetadata,
extensionURL: string,
Expand Down Expand Up @@ -263,7 +263,7 @@ class ChibiLoader {
* @returns {string} - the sanitized text
* @private
*/
private _sanitizeID(text: string) {
private _sanitizeID (text: string) {
return text.toString().replace(/[<"&]/, '_');
}

Expand All @@ -276,7 +276,7 @@ class ChibiLoader {
* @returns {ExtensionInfo} - a new extension info object with cleaned-up values
* @private
*/
private _prepareExtensionInfo(
private _prepareExtensionInfo (
extensionObject: ExtensionClass | null,
extensionInfo: ExtensionMetadata,
serviceName?: string
Expand Down Expand Up @@ -334,7 +334,7 @@ class ChibiLoader {
* @returns {Array.<MenuInfo>} - a menuInfo object with all preprocessing done.
* @private
*/
private _prepareMenuInfo(
private _prepareMenuInfo (
extensionObject: ExtensionClass | null,
menus: Record<string, ExtensionMenu>,
serviceName?: string
Expand Down Expand Up @@ -381,7 +381,7 @@ class ChibiLoader {
* @returns {Array} menu items ready for scratch-blocks.
* @private
*/
private _getExtensionMenuItems(
private _getExtensionMenuItems (
extensionObject: ExtensionClass,
menuItemFunctionName: string,
serviceName?: string
Expand Down Expand Up @@ -427,7 +427,7 @@ class ChibiLoader {
* @returns {ExtensionBlockMetadata} - a new block info object which has values for all relevant optional fields.
* @private
*/
private _prepareBlockInfo(
private _prepareBlockInfo (
extensionObject: ExtensionClass | null,
blockInfo: ExtensionBlockMetadata,
serviceName?: string
Expand Down Expand Up @@ -512,19 +512,19 @@ class ChibiLoader {
return blockInfo;
}

async updateLocales() {
async updateLocales () {
await this.reloadAll();
}

/**
* Regenerate blockinfo for any loaded extensions
* @returns {Promise} resolved once all the extensions have been reinitialized
*/
async refreshBlocks() {
async refreshBlocks () {
await this.reloadAll();
}

allocateWorker() {
allocateWorker () {
const workerInfo = this.pendingExtensions.shift();
if (!workerInfo) {
warn('pending extension queue is empty');
Expand All @@ -539,7 +539,7 @@ class ChibiLoader {
* Collect extension metadata from the specified service and begin the extension registration process.
* @param {string} serviceName - the name of the service hosting the extension.
*/
async registerExtensionService(extensionURL: string, serviceName: string) {
async registerExtensionService (extensionURL: string, serviceName: string) {
const info = await dispatch.call(serviceName, 'getInfo');
this._registerExtensionInfo(null, info, extensionURL, serviceName);
}
Expand All @@ -549,7 +549,7 @@ class ChibiLoader {
* @param {int} id - the worker ID.
* @param {*?} e - the error encountered during initialization, if any.
*/
onWorkerInit(id: number, e?: Error) {
onWorkerInit (id: number, e?: Error) {
const workerInfo = this.pendingWorkers[id];
delete this.pendingWorkers[id];
if (e) {
Expand Down

0 comments on commit 153483c

Please sign in to comment.