mirror of
https://git.bits.team/Bits/mod-manager.git
synced 2024-12-22 04:18:21 -05:00
Use spinners when installing mod
This commit is contained in:
parent
2b5d2a3643
commit
32c2f99a31
@ -19,16 +19,18 @@ export default class Mods {
|
||||
for (const source of this.MOD_SOURCES) {
|
||||
// If we have not yet successfully installed the queried mod
|
||||
if (!success) {
|
||||
PrintUtils.info(`Searching for ${mod}...`);
|
||||
const spinner = new PrintUtils.Spinner(`Searching for ${mod}...`);
|
||||
spinner.start();
|
||||
|
||||
// Search for the mod
|
||||
let id;
|
||||
try {
|
||||
id = await source.search(mod);
|
||||
} catch (e) {
|
||||
if (e instanceof ModNotFoundError) {
|
||||
PrintUtils.info(`Mod not found on ${source.getName()}`);
|
||||
spinner.updateText(`Mod not found on ${source.getName()}`)
|
||||
} else {
|
||||
PrintUtils.error(`An error occurred searching for ${mod} on ${source.getName()}. Skipping ${source.getName()}`, e)
|
||||
spinner.error(`An error occurred searching for ${mod} on ${source.getName()}. Skipping ${source.getName()}`)
|
||||
// Try the next source
|
||||
continue;
|
||||
}
|
||||
@ -36,13 +38,13 @@ export default class Mods {
|
||||
|
||||
// If a mod is found, install it
|
||||
if (id != undefined) {
|
||||
PrintUtils.info(`Installing ${mod}...`);
|
||||
spinner.updateText(`Installing ${mod}...`)
|
||||
try {
|
||||
await source.install(id);
|
||||
PrintUtils.success(`Successfully installed ${mod}`);
|
||||
spinner.succeed(`Successfully installed ${mod}`);
|
||||
} catch (e) {
|
||||
// Log the error, and continue to next source
|
||||
PrintUtils.error(e);
|
||||
spinner.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ export default class ModrinthSource implements ModSource {
|
||||
* @throws ModNotFoundError if the query returns no results.
|
||||
* @returns The mod id of the found mod
|
||||
*/
|
||||
async search(query: string): Promise<string> | never {
|
||||
async search(query: string): Promise<string> {
|
||||
const mcVersion = await MinecraftUtils.getCurrentMinecraftVersion();
|
||||
|
||||
const params = {
|
||||
|
@ -23,16 +23,23 @@ export default class PrintUtils {
|
||||
this.spinner.stop();
|
||||
}
|
||||
|
||||
public error() {
|
||||
this.spinner.fail();
|
||||
public error(print: string | Error) {
|
||||
if (print instanceof Error) {
|
||||
this.spinner.fail(print.message)
|
||||
if (ModManager.logger != null) {
|
||||
ModManager.logger.error(print)
|
||||
}
|
||||
} else {
|
||||
this.spinner.fail(print);
|
||||
}
|
||||
}
|
||||
|
||||
public succeed() {
|
||||
this.spinner.succeed();
|
||||
public succeed(print: string) {
|
||||
this.spinner.succeed(print);
|
||||
}
|
||||
|
||||
public updateText(text: string) {
|
||||
this.spinner.info(text);
|
||||
this.spinner.start(text);
|
||||
}
|
||||
|
||||
public clear() {
|
||||
|
Loading…
Reference in New Issue
Block a user