Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Refactor searchByKeyword and change @types/react to a more correct version #15

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@babel/plugin-transform-classes": "^7.16.7",
"@rollup/plugin-babel": "^5.3.1",
"@types/node": "^17.0.24",
"@types/react": "^17.0.39",
"@types/react": "17.0.2",
"@types/react-native": "^0.67.4",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
Expand Down
11 changes: 9 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default defineConfig({
format: "iife",
inlineDynamicImports: true,
sourcemap: true,
sourcemapFile: "Aliucord.js.map"
sourcemapFile: "Aliucord.js.map",
name: "aliu"
}],
plugins: [
esbuild({
Expand Down Expand Up @@ -59,20 +60,20 @@ function aliucordVersion(): Plugin {
name: "aliucord-version",
resolveId(id) {
if (id === "aliucord-version") {
return id
return id;
}
return null
return null;
},
load(id) {
if (id === "aliucord-version") {
try {
const hash = execSync("git rev-parse --short HEAD").toString().replace(/\s*/g, "")
return `export const sha = "${hash || 'unknown'}";`
const hash = execSync("git rev-parse --short HEAD").toString().replace(/\s*/g, "");
return `export const sha = "${hash || "unknown"}";`;
} catch (ex) {
console.warn("Failed to fetch git hash")
console.warn("Failed to fetch git hash");
}
return 'export const sha = "unknown";'
return "export const sha = \"unknown\";";
}
}
}
};
}
98 changes: 43 additions & 55 deletions src/Aliucord.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { checkPermissions, requestPermissions } from "./AliucordNative";
import { Commands } from "./api/Commands";
import { Settings } from "./api/SettingsAPI";
import { Settings } from "./api/Settings";
import * as CorePlugins from "./core-plugins/index";
import * as Metro from "./metro";
import { checkPermissions, requestPermissions } from "./native";
import patchSettings from "./ui/patchSettings";
import * as AliuConstants from "./utils/constants";
import { DebugWS } from "./utils/debug/DebugWS";
import { startDebugWs } from "./utils/debug/DebugWS";
import { Logger } from "./utils/Logger";
import * as Patcher from "./utils/Patcher";

function initWithPerms() {
// TODO
Expand All @@ -17,63 +14,54 @@ interface SettingsSchema {
autoUpdateAliucord: boolean;
autoUpdatePlugins: boolean;
disablePluginsOnCrash: boolean;
debugWS: boolean;
plugins: Record<string, boolean>;
}
export class Aliucord {
settings!: Settings<SettingsSchema>;
logger = new Logger("Aliucord");
debugWS = new DebugWS();

Constants = AliuConstants;
export let settings: Settings<SettingsSchema>;
export const logger = new Logger("AliucordMain");
export async function load() {
settings = await Settings.make("Aliucord");

Commands = Commands;
/**
* Metro. Module Store
*/
Metro = Metro;
Patcher = Patcher;
try {
logger.info("Loading...");

async load() {
this.settings = await Settings.make("Aliucord");

try {
this.logger.info("Loading...");

checkPermissions().then(granted => {
if (granted) initWithPerms();
else {
Metro.ReactNative.Alert.alert(
"Storage Access",
"Aliucord needs access to your storage to load plugins and themes.",
[{
text: "OK",
onPress: () => requestPermissions().then(permissionGranted => {
if (permissionGranted) initWithPerms();
else alert("Aliucord needs access to your storage to load plugins and themes.");
})
}]
);
}
});

CorePlugins.startAll();
checkPermissions().then(granted => {
if (granted) initWithPerms();
else {
Metro.ReactNative.Alert.alert(
"Storage Access",
"Aliucord needs access to your storage to load plugins and themes.",
[{
text: "OK",
onPress: () => requestPermissions().then(permissionGranted => {
if (permissionGranted) initWithPerms();
else alert("Aliucord needs access to your storage to load plugins and themes.");
})
}]
);
}
});

this.debugWS.start();
CorePlugins.startAll();

// Needs to be hardcoded instead of variable so this code is correcty
// detected as unreachable and not included in build.
// if (variable) still crashes
// eslint-disable-next-line no-constant-condition
if (false) {
// CAUSES CRASHES
// "lateinit property audioManager has not been initialized"
const { ReactDevTools } = await import("./utils/debug/ReactDevTools");
new ReactDevTools().connect();
}
if (settings.get("debugWS", false)) {
startDebugWs();
}

patchSettings();
} catch (error) {
this.logger.error(error as string | Error);
// Needs to be hardcoded instead of variable so this code is correcty
// detected as unreachable and not included in build.
// if (variable) still crashes
// eslint-disable-next-line no-constant-condition
if (false) {
// CAUSES CRASHES
// "lateinit property audioManager has not been initialized"
const { startReactDevTools } = await import("./utils/debug/ReactDevTools");
startReactDevTools();
}

patchSettings();
} catch (error) {
logger.error(error as string | Error);
}
}
12 changes: 2 additions & 10 deletions src/api/PatcherApi.ts → src/api/Patcher.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {
Unpatch,
before,
PatchPriority,
BeforePatchFn,
InsteadFn,
instead,
AfterPatchFn,
after,
insteadDoNothing
} from "../utils/Patcher";
after, AfterPatchFn, before, BeforePatchFn, instead, insteadDoNothing, InsteadFn, PatchPriority, Unpatch
} from "../utils/patcher";

export class Patcher {
private readonly _unpatches = [] as Unpatch[];
Expand Down
9 changes: 4 additions & 5 deletions src/PluginManager.ts → src/api/PluginManager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Settings } from "./api/SettingsAPI";
import Plugin from "./entities/Plugin";
import { Logger } from "./utils/Logger";
import Plugin from "../entities/Plugin";
import { Logger } from "../utils/Logger";
import { Settings } from "./Settings";

const logger = new Logger("PluginManager");

// TODO
export default class PluginManager {
export class PluginManager {
public static readonly plugins = {} as Record<string, Plugin>;

public static isEnabled(plugin: string) {
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./Commands";
export * from "./Patcher";
export * from "./PluginManager";
export * from "./Settings";

2 changes: 1 addition & 1 deletion src/core-plugins/CommandHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApplicationCommand, Commands, CommandSection } from "../api/Commands";
import Plugin from "../entities/Plugin";
import { getByProps } from "../metro";
import { after } from "../utils/Patcher";
import { after } from "../utils/patcher";

export default class CommandHandler extends Plugin {
start() {
Expand Down
10 changes: 5 additions & 5 deletions src/core-plugins/CoreCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { sha } from "aliucord-version";
import { ApplicationCommandOptionType } from "../api/Commands";
import Plugin from "../entities/Plugin";
import { getByProps, i18n, MessageActions } from "../metro";
import DebugInfo from "../utils/debug/DebugInfo";
import DebugInfo from "../utils/DebugInfo";
import { makeAsyncEval } from "../utils/misc";

export default class CoreCommands extends Plugin {
Expand Down Expand Up @@ -60,11 +60,11 @@ export default class CoreCommands extends Plugin {
execute: async (args, ctx) => {
MessageActions.sendMessage(ctx.channel.id, {
content: `**Debug Info:**
> Discord: ${DebugInfo.getDiscordVersion()}
> Discord: ${DebugInfo.discordVersion}
> Aliucord: ${sha}
> System: ${DebugInfo.getSystem()}
> React: ${DebugInfo.getReactNativeVersion()}
> Hermes: ${DebugInfo.getHermesVersion()}
> System: ${DebugInfo.system}
> React: ${DebugInfo.reactNativeVersion}
> Hermes: ${DebugInfo.hermesVersion}
`.replace(/^\s+/gm, "")
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/core-plugins/NoTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import Plugin from "../entities/Plugin";
import { getByProps } from "../metro/index";
import { insteadDoNothing } from "../utils/Patcher";
import { insteadDoNothing } from "../utils/patcher";

export default class NoTrack extends Plugin {
public start() {
Expand Down
1 change: 1 addition & 0 deletions src/core-plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function startAll() {
const { name } = pluginClass;
try {
window.Aliucord.logger.info("Loading CorePlugin " + name);
// TODO - Does this need a settings instance?
new pluginClass().start();
} catch (e) {
window.Aliucord.logger.error("Failed to start CorePlugin " + name, e);
Expand Down
4 changes: 2 additions & 2 deletions src/entities/Plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Commands } from "../api/Commands";
import { Patcher } from "../api/PatcherApi";
import { Settings } from "../api/SettingsAPI";
import { Patcher } from "../api/Patcher";
import { Settings } from "../api/Settings";
import { Logger } from "../utils/Logger";

/**
Expand Down
1 change: 1 addition & 0 deletions src/entities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Plugin } from "./Plugin";
4 changes: 2 additions & 2 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Aliucord } from "./Aliucord";
import * as Aliucord from "./Aliucord";

declare global {
interface Window {
Aliucord: Aliucord;
Aliucord: typeof Aliucord;
[key: PropertyKey]: any;
}
}
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Aliucord } from "./Aliucord";
import * as Aliucord from "./Aliucord";

export const aliucord = window.Aliucord = new Aliucord();
aliucord.load();
export * as api from "./api";
export * as entities from "./entities";
export * as metro from "./metro";
export * as native from "./native";
export * as utils from "./utils";

window.Aliucord = Aliucord;
Aliucord.load();
Loading