Skip to content
Merged
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
11 changes: 11 additions & 0 deletions .vscode/Discloud.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
// ],
// "description": "Log output to console"
// }
"event" :{
"body": [
"import type ExtensionCore from \"../core/extension\";",
"",
"export default async function (core: ExtensionCore) {",
"\t$0",
"}"
],
"prefix": "event",
"scope": "typescript"
},
"extcmd": {
"body": [
"import { TaskData } from \"../@types\";",
Expand Down
4 changes: 4 additions & 0 deletions src/@types/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IEventModule<E extends Record<keyof E, unknown[]>, K extends keyof E, V extends E[K] = E[K]> {
readonly once?: boolean
default(...args: V): void
}
1 change: 1 addition & 0 deletions src/@types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./api";
export * from "./event";
export * from "./rest";
export * from "./structures";
export * from "./vscode";
25 changes: 13 additions & 12 deletions src/@types/structures.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { CancellationToken, ExtensionContext, LogOutputChannel, ProgressOptions, TreeItem, Uri } from "vscode";
import type ExtensionCore from "../core/extension";
import type BaseChildTreeItem from "../structures/BaseChildTreeItem";
import type TeamAppTreeItem from "../structures/TeamAppTreeItem";
import type UserAppTreeItem from "../structures/UserAppTreeItem";
import type VSUser from "../structures/VSUser";
import type { RateLimitData } from "./rest";
import { type ProgressTaskParameters, type VscodeProgressReporter } from "./vscode";
import type { ProgressTaskParameters, VscodeProgressReporter } from "./vscode";

export interface GetWorkspaceFolderOptions {
/** @default true */
Expand Down Expand Up @@ -89,15 +90,15 @@ export interface UserTreeItemData extends BaseTreeItemData {
}

export interface Events {
activate: [context: ExtensionContext]
appUpdate: [oldApp: UserAppTreeItem, newApp: UserAppTreeItem]
authorized: []
debug: Parameters<LogOutputChannel["debug"]>
error: [error: Error | unknown]
missingConnection: []
missingToken: []
rateLimited: [rateLimitData: RateLimitData]
teamAppUpdate: [oldTeamApp: TeamAppTreeItem, newTeamApp: TeamAppTreeItem]
unauthorized: []
vscode: [user: VSUser]
activate: [core: ExtensionCore, context: ExtensionContext]
appUpdate: [core: ExtensionCore, oldApp: UserAppTreeItem, newApp: UserAppTreeItem]
authorized: [core: ExtensionCore]
debug: [core: ExtensionCore, ...Parameters<LogOutputChannel["debug"]>]
error: [core: ExtensionCore, error: Error | unknown]
missingConnection: [core: ExtensionCore]
missingToken: [core: ExtensionCore]
rateLimited: [core: ExtensionCore, rateLimitData: RateLimitData]
teamAppUpdate: [core: ExtensionCore, oldTeamApp: TeamAppTreeItem, newTeamApp: TeamAppTreeItem]
unauthorized: [core: ExtensionCore]
vscode: [core: ExtensionCore, user: VSUser]
}
2 changes: 1 addition & 1 deletion src/authentication/pat/provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type RESTGetApiUserResult, RouteBases, Routes } from "@discloudapp/api-types/v2";
import { t } from "@vscode/l10n";
import { authentication, type AuthenticationProvider, type AuthenticationProviderAuthenticationSessionsChangeEvent, type AuthenticationProviderSessionOptions, type AuthenticationSession, type AuthenticationSessionAccountInformation, type EventEmitter, type SecretStorage, window } from "vscode";
import { type IGlobalStateStorage } from "../../@types";
import type { IGlobalStateStorage } from "../../@types";
import { tokenIsDiscloudJwt } from "../../services/discloud/utils";
import { GlobalStorageKeys } from "../../utils/constants";
import { AuthenticationProviderId } from "../enum/providers";
Expand Down
2 changes: 1 addition & 1 deletion src/authentication/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { authentication, type AuthenticationProvider, type AuthenticationProvide
import type ExtensionCore from "../core/extension";
import { GlobalStorageKeys } from "../utils/constants";
import { AuthenticationProviderId } from "./enum/providers";
import { type IPatAuthenticationProvider } from "./interfaces/pat";
import type { IPatAuthenticationProvider } from "./interfaces/pat";
import DiscloudPatAuthenticationProvider from "./pat/provider";

export default class AuthenticationProviderContainer implements AuthenticationProvider {
Expand Down
2 changes: 1 addition & 1 deletion src/authentication/session.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type AuthenticationSession, type AuthenticationSessionAccountInformation } from "vscode";
import type { AuthenticationSession, AuthenticationSessionAccountInformation } from "vscode";

export default class DiscloudAuthenticationSession implements AuthenticationSession {
constructor(
Expand Down
6 changes: 3 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-duplicate-imports */
import { t } from "@vscode/l10n";
import { commands, window } from "vscode";
import type ExtensionCore from "./core/extension";
import type Command from "./structures/Command";
import { type CommandConstructor } from "./structures/Command";
import type { CommandConstructor } from "./structures/Command";

export async function commandsRegister(core: ExtensionCore) {
// root
Expand Down Expand Up @@ -147,7 +147,7 @@ function commandRegister(

return await command.run(null, ...args);
} catch (error) {
core.emit("error", error);
core.emit("error", core, error);
} finally {
core.statusBar.reset();
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { t } from "@vscode/l10n";
import { existsSync } from "fs";
import { basename } from "path";
import { ProgressLocation, Uri, window, workspace } from "vscode";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import Command from "../../structures/Command";
import type UserAppTreeItem from "../../structures/UserAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/commit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type RESTPutApiAppCommitResult, Routes } from "@discloudapp/api-types/v2";
import { t } from "@vscode/l10n";
import { CancellationError, ProgressLocation } from "vscode";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import { socketCommit } from "../../services/discloud/socket/actions/commit";
import Command from "../../structures/Command";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/copy.id.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { t } from "@vscode/l10n";
import { env, window } from "vscode";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import Command from "../../structures/Command";
import type UserAppTreeItem from "../../structures/UserAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/delete.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type RESTDeleteApiAppDeleteResult, Routes } from "@discloudapp/api-types/v2";
import { t } from "@vscode/l10n";
import { CancellationError, ProgressLocation } from "vscode";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import Command from "../../structures/Command";
import type UserAppTreeItem from "../../structures/UserAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { t } from "@vscode/l10n";
import AdmZip from "adm-zip";
import { existsSync } from "fs";
import { ProgressLocation, Uri, commands, window, workspace } from "vscode";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import Command from "../../structures/Command";
import type UserAppTreeItem from "../../structures/UserAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/logs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type RESTGetApiAppLogResult, Routes } from "@discloudapp/api-types/v2";
import { t } from "@vscode/l10n";
import { ProgressLocation } from "vscode";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import Command from "../../structures/Command";
import type UserAppTreeItem from "../../structures/UserAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/mods/edit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type RESTPutApiAppTeamResult, Routes } from "@discloudapp/api-types/v2";
import { ModPermissionsBF } from "@discloudapp/util";
import { t } from "@vscode/l10n";
import { CancellationError, ProgressLocation, type QuickPickItem, window } from "vscode";
import { type QuickPickItem, CancellationError, ProgressLocation, window } from "vscode";
import { type TaskData } from "../../../@types";
import type ExtensionCore from "../../../core/extension";
import Command from "../../../structures/Command";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/ram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type RESTPutApiAppRamResult, Routes } from "@discloudapp/api-types/v2";
import { t } from "@vscode/l10n";
import { CancellationError, ProgressLocation } from "vscode";
import { AppType } from "../../@enum";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import Command from "../../structures/Command";
import type UserAppTreeItem from "../../structures/UserAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/restart.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type RESTPutApiAppRestartResult, Routes } from "@discloudapp/api-types/v2";
import { t } from "@vscode/l10n";
import { CancellationError, ProgressLocation } from "vscode";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import Command from "../../structures/Command";
import type UserAppTreeItem from "../../structures/UserAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/start.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type RESTPutApiAppStartResult, Routes } from "@discloudapp/api-types/v2";
import { t } from "@vscode/l10n";
import { ProgressLocation } from "vscode";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import Command from "../../structures/Command";
import type UserAppTreeItem from "../../structures/UserAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { t } from "@vscode/l10n";
import { ProgressLocation } from "vscode";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import Command from "../../structures/Command";
import type UserAppTreeItem from "../../structures/UserAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/stop.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type RESTPutApiAppStartResult, Routes } from "@discloudapp/api-types/v2";
import { t } from "@vscode/l10n";
import { CancellationError, ProgressLocation } from "vscode";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import Command from "../../structures/Command";
import type UserAppTreeItem from "../../structures/UserAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/terminal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Uri, window } from "vscode";
import { type TaskData } from "../../@types";
import type { TaskData } from "../../@types";
import type ExtensionCore from "../../core/extension";
import Command from "../../structures/Command";
import type UserAppTreeItem from "../../structures/UserAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/commit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type RESTPutApiAppCommitResult, Routes } from "@discloudapp/api-types/v2";
import { t } from "@vscode/l10n";
import { CancellationError, ProgressLocation } from "vscode";
import { type TaskData } from "../@types";
import type { TaskData } from "../@types";
import type ExtensionCore from "../core/extension";
import { socketCommit } from "../services/discloud/socket/actions/commit";
import Command from "../structures/Command";
Expand Down
4 changes: 2 additions & 2 deletions src/commands/login.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { t } from "@vscode/l10n";
import { setTimeout as sleep } from "timers/promises";
import { authentication, window, type AuthenticationSession } from "vscode";
import { type TaskData } from "../@types";
import type { TaskData } from "../@types";
import UnauthorizedError from "../authentication/errors/unauthorized";
import { pickAuthenticationProviderId } from "../authentication/pick/AuthenticationProviderPicker";
import type ExtensionCore from "../core/extension";
Expand Down Expand Up @@ -31,7 +31,7 @@ export default class extends Command {
void window.showInformationMessage(t("valid.token"));
}

this.core.emit("authorized");
this.core.emit("authorized", this.core);

await sleep();

Expand Down
2 changes: 1 addition & 1 deletion src/commands/logout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type AuthenticationSessionAccountInformation } from "vscode";
import type { AuthenticationSessionAccountInformation } from "vscode";
import type ExtensionCore from "../core/extension";
import Command from "../structures/Command";
import type UserTreeItem from "../structures/UserTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DiscloudConfigScopes, type RESTGetApiAppLogResult, Routes } from "@disc
import { DiscloudConfig } from "@discloudapp/util";
import { t } from "@vscode/l10n";
import { ProgressLocation } from "vscode";
import { type TaskData } from "../@types";
import type { TaskData } from "../@types";
import type ExtensionCore from "../core/extension";
import Command from "../structures/Command";
import type TeamAppTreeItem from "../structures/TeamAppTreeItem";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type RESTPostApiUploadResult, Routes } from "@discloudapp/api-types/v2"
import { DiscloudConfig } from "@discloudapp/util";
import { t } from "@vscode/l10n";
import { CancellationError, ProgressLocation, Uri } from "vscode";
import { type TaskData } from "../@types";
import type { TaskData } from "../@types";
import type ExtensionCore from "../core/extension";
import { socketUpload } from "../services/discloud/socket/actions/upload";
import Command from "../structures/Command";
Expand Down
4 changes: 2 additions & 2 deletions src/core/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class ExtensionCore extends EventEmitter<Events> implements Dispo
}

debug(...args: Parameters<LogOutputChannel["debug"]>) {
this.emit("debug", ...args);
this.emit("debug", this, ...args);
}

dispose() {
Expand Down Expand Up @@ -207,6 +207,6 @@ export default class ExtensionCore extends EventEmitter<Events> implements Dispo
userTree: { value: userTree },
});

this.emit("activate", context);
this.emit("activate", this, context);
}
}
35 changes: 24 additions & 11 deletions src/events.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import type { Events, IEventModule } from "./@types";
import type ExtensionCore from "./core/extension";

export async function loadEvents(core: ExtensionCore) {
await import("./events/activate");
await import("./events/appUpdate");
await import("./events/authorized");
await import("./events/debug");
await import("./events/error");
await import("./events/missingConnection");
await import("./events/missingToken");
await import("./events/rateLimited");
await import("./events/teamAppUpdate");
await import("./events/unauthorized");
await import("./events/vscode");
await Promise.all([
loadEvent(core, "activate", import("./events/activate")),
loadEvent(core, "appUpdate", import("./events/appUpdate")),
loadEvent(core, "authorized", import("./events/authorized")),
loadEvent(core, "debug", import("./events/debug")),
loadEvent(core, "error", import("./events/error")),
loadEvent(core, "missingConnection", import("./events/missingConnection")),
loadEvent(core, "missingToken", import("./events/missingToken")),
loadEvent(core, "rateLimited", import("./events/rateLimited")),
loadEvent(core, "teamAppUpdate", import("./events/teamAppUpdate")),
loadEvent(core, "unauthorized", import("./events/unauthorized")),
loadEvent(core, "vscode", import("./events/vscode")),
]);

core.debug("Events loaded");
}

async function loadEvent<K extends keyof Events>(
core: ExtensionCore,
name: K,
eventPromise: Promise<IEventModule<Events, K, Events[K]>>,
) {
const event = await eventPromise;
const invoker = event.once ? "once" : "on";
core[invoker](name, event.default as any);
}
9 changes: 4 additions & 5 deletions src/events/activate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { type AuthenticationSessionAccountInformation, commands, workspace } from "vscode";
import { type AuthenticationSessionAccountInformation, commands, type ExtensionContext, workspace } from "vscode";
import { AuthenticationProviderId } from "../authentication/enum/providers";
import type ExtensionCore from "../core/extension";
import core from "../extension";
import BaseLanguageProvider from "../language/BaseLanguageProvider";
import CompletionItemProvider from "../language/CompletionItemProvider";
import LanguageConfigurationProvider from "../language/LanguageConfigurationProvider";
import { DISCLOUD_CONFIG_SCHEMA_FILE_NAME, GlobalStorageKeys } from "../utils/constants";

core.on("activate", async function (context) {
export default async function (core: ExtensionCore, context: ExtensionContext) {
queueMicrotask(async function () {
try {
const path = context.asAbsolutePath(DISCLOUD_CONFIG_SCHEMA_FILE_NAME);
Expand Down Expand Up @@ -43,7 +42,7 @@ core.on("activate", async function (context) {
const disposableAuthenticationEvent = core.auth.onDidChangeSessions(async (event) => {
if (event.removed?.length) {
const session = await core.auth.getSession();
if (!session) core.emit("missingToken");
if (!session) core.emit("missingToken", core);
return;
}
});
Expand All @@ -63,7 +62,7 @@ core.on("activate", async function (context) {
}

await commands.executeCommand("setContext", "discloudInitialized", true);
});
}

async function migrateAuthenticationProvider(core: ExtensionCore) {
const oldSessionIdList = core.globalStorage.get<string[]>("sessionIdList", []);
Expand Down
7 changes: 4 additions & 3 deletions src/events/appUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { t } from "@vscode/l10n";
import { window } from "vscode";
import core from "../extension";
import type ExtensionCore from "../core/extension";
import type UserAppTreeItem from "../structures/UserAppTreeItem";
import { ConfigKeys } from "../utils/constants";

core.on("appUpdate", async function (oldApp, newApp) {
export default async function (core: ExtensionCore, oldApp: UserAppTreeItem, newApp: UserAppTreeItem) {
if (!core.config.get<boolean>(ConfigKeys.appNotificationStatus)) return;

const messageList: string[] = [];
Expand All @@ -19,4 +20,4 @@ core.on("appUpdate", async function (oldApp, newApp) {

if (messageList.length)
void window.showInformationMessage(messageList.join("\n"));
});
}
Loading
Loading