Skip to content

Commit

Permalink
Доработка вотчера в лаунчсервере (closes #71)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoCat committed Nov 27, 2024
1 parent b155f0f commit 3054878
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/launcher
Submodule launcher updated 58 files
+5 −1 .github/workflows/release.yml
+0 −1 .gitignore
+1 −1 LICENSE
+0 −0 config.d.ts
+12 −42 config.ts
+12 −59 electron.vite.config.ts
+0 −34 eslint.config.mjs
+73 −36 package.json
+12 −12 public.pem
+2 −12 src/common/channels.ts
+0 −9 src/common/types.ts
+2 −2 src/main/api/APIManager.ts
+2 −2 src/main/api/AuthorizationService.ts
+2 −2 src/main/api/VerifyService.ts
+39 −113 src/main/core/DiscordRPC.ts
+14 −27 src/main/core/Launcher.ts
+4 −39 src/main/core/LauncherWindow.ts
+2 −2 src/main/game/AuthlibInjector.ts
+7 −16 src/main/game/GameService.ts
+2 −2 src/main/game/GameWindow.ts
+11 −8 src/main/game/JavaManager.ts
+27 −98 src/main/game/Starter.ts
+26 −81 src/main/game/Updater.ts
+79 −142 src/main/game/Watcher/Watcher.ts
+0 −57 src/main/helpers/SettingsHelper.ts
+10 −37 src/main/helpers/StorageHelper.ts
+5 −1 src/main/index.ts
+2 −24 src/main/scenes/Login.ts
+2 −2 src/main/scenes/ServerPanel.ts
+2 −2 src/main/scenes/ServersList.ts
+0 −26 src/main/scenes/Settings.ts
+0 −11 src/main/utils/retry.ts
+0 −4 src/preload/components/LoginScene.ts
+4 −4 src/preload/components/RPC.ts
+0 −25 src/preload/components/SettingsScene.ts
+0 −21 src/preload/components/Window.ts
+0 −11 src/preload/index.ts
+0 −2 src/renderer/App.tsx
+1 −4 src/renderer/runtime/assets/sass/index.sass
+0 −67 src/renderer/runtime/components/MemoryRange/index.module.sass
+0 −39 src/renderer/runtime/components/MemoryRange/index.tsx
+9 −4 src/renderer/runtime/components/SkinView.tsx
+0 −38 src/renderer/runtime/components/SkinView2d/index.tsx
+15 −38 src/renderer/runtime/components/TitleBar/hooks.ts
+0 −8 src/renderer/runtime/components/TitleBar/index.module.sass
+31 −47 src/renderer/runtime/components/TitleBar/index.tsx
+5 −19 src/renderer/runtime/components/TitleBar/states.ts
+0 −21 src/renderer/runtime/libs/skinview2d/model.ts
+0 −87 src/renderer/runtime/libs/skinview2d/viewer.ts
+0 −9 src/renderer/runtime/scenes/Login/index.module.sass
+28 −41 src/renderer/runtime/scenes/Login/index.tsx
+3 −19 src/renderer/runtime/scenes/ServerPanel/index.tsx
+1 −10 src/renderer/runtime/scenes/ServersList/index.tsx
+0 −130 src/renderer/runtime/scenes/Settings/index.module.sass
+0 −223 src/renderer/runtime/scenes/Settings/index.tsx
+0 −11 src/renderer/utils.ts
+1 −0 tsconfig.json
+0 −160 upload-release.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
ClientsManager,
CommandsManager,
ConfigManager,
FabricManager,
ForgeManager,
LangManager,
MirrorManager,
MojangManager,
NeoForgeManager,
ProfilesManager,
ClientsManager,
QuiltManager,
ForgeManager,
NeoForgeManager,
} from "@root/components";
import { Watcher } from "@root/components/watcher/Watcher"
import { Watcher } from "@root/components/watcher/Watcher";
import { AbstractCommand, Category, LogHelper } from "@root/utils";
import { Service } from "typedi";

Expand Down
22 changes: 22 additions & 0 deletions packages/server/src/components/watcher/WatchService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { LogHelper } from "@root/utils";
import { FSWatcher, watch } from "chokidar";

export class WatchService {
#watcherInstance: FSWatcher;
#timer: NodeJS.Timeout;

subscribe(dir: string, cwd: string, reload: (path: string) => void) {
this.#watcherInstance = watch(dir, { ignoreInitial: true, cwd }).on(
"all",
(event, path) => {
if (this.#timer) clearTimeout(this.#timer);
this.#timer = setTimeout(() => reload(path), 3000);
LogHelper.debug(event, path);
},
);
}

async unsubscribe() {
await this.#watcherInstance.close();
}
}
52 changes: 24 additions & 28 deletions packages/server/src/components/watcher/Watcher.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
import { sep } from "path";

import { StorageHelper } from "@root/utils";
import { Service } from "typedi";
import { FSWatcher, watch } from 'chokidar';
import { LogHelper, StorageHelper } from "@root/utils";
import { ProfilesManager } from "../profiles/ProfilesManager";

import { ClientsManager } from "../clients/ClientsManager";
import { ProfilesManager } from "../profiles/ProfilesManager";
import { WatchService } from "./WatchService";

@Service()
export class Watcher {
#prcess1:FSWatcher
#prcess2:FSWatcher
#clientsWatcher = new WatchService();
#profilesWatcher = new WatchService();

constructor(
private readonly profilesManager:ProfilesManager,
private readonly clientsManager:ClientsManager
private readonly profilesManager: ProfilesManager,
private readonly clientsManager: ClientsManager,
) {
this.subscription();
}

async subscription() {

this.#prcess1 = watch(StorageHelper.clientsDir, {ignoreInitial: true, cwd: StorageHelper.clientsDir})
.on('all', (event, path) => this.reloadClient(event, path));

this.#prcess2 = watch(StorageHelper.profilesDir, {ignoreInitial: true, cwd: '.'})
.on('all', (event, path) => this.reloadProfile(event, path));
subscription() {
this.#clientsWatcher.subscribe(
StorageHelper.clientsDir,
StorageHelper.clientsDir,
(path) => {
const dir = path.split(sep);
this.clientsManager.hashClients(dir[0]);
},
);
this.#profilesWatcher.subscribe(StorageHelper.profilesDir, ".", () =>
this.profilesManager.reloadProfiles(),
);
}

async closeWatcher() {
await this.#prcess1.close()
await this.#prcess2.close()
}

private reloadClient(event:string, path:string) {
LogHelper.debug(event, path);
const dir = path.split(sep);
this.clientsManager.hashClients(dir[0]);
}

private reloadProfile(event:string, path:string) {
LogHelper.debug(event, path);
this.profilesManager.reloadProfiles();
await this.#clientsWatcher.unsubscribe();
await this.#profilesWatcher.unsubscribe();
}
}
}

0 comments on commit 3054878

Please sign in to comment.