-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
72 changed files
with
3,528 additions
and
3,154 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,19 +6,23 @@ | |
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc -b --verbose", | ||
"clean": "rm -rf dist", | ||
"lint": "eslint .", | ||
"start": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"@opentelemetry/instrumentation/hook.mjs\", pathToFileURL(\"./\"));' --import ./instrument.mjs server.js", | ||
"start": "node --openssl-legacy-provider --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"@opentelemetry/instrumentation/hook.mjs\", pathToFileURL(\"./\"));' --import ./instrument.js server.js", | ||
"test": "vitest run" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "LGPL-3.0-or-later", | ||
"devDependencies": { | ||
"@eslint/js": "^9.3.0", | ||
"@types/express": "^4.17.21", | ||
"@types/node": "^20.12.12", | ||
"@vitest/coverage-v8": "^1.6.0", | ||
"eslint": "^9.3.0", | ||
"globals": "^15.3.0", | ||
"typescript": "^5.4.5", | ||
"vitest": "^1.6.0" | ||
}, | ||
"packageManager": "[email protected]+sha256.30a1801ac4e723779efed13a21f4c39f9eb6c9fbb4ced101bce06b422593d7c9", | ||
|
@@ -27,6 +31,7 @@ | |
"@sentry/node": "^8.7.0", | ||
"@sentry/profiling-node": "^8.7.0", | ||
"express": "^4.19.2", | ||
"obsidian-main": "link:packages/main" | ||
"obsidian-main": "link:packages/main", | ||
"tsx": "^4.11.0" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { KeypressEvent, TTask } from "./types.js"; | ||
export declare class MainLoop { | ||
/** @type {NodeJS.Timeout | undefined} */ | ||
_timer: NodeJS.Timeout | undefined; | ||
/** @type {Array<import("obsidian-main").Task>} */ | ||
_startTasks: Array<TTask>; | ||
/** @type {Array<import("obsidian-main").Task>} */ | ||
_stopTasks: Array<TTask>; | ||
/** @type {Array<import("obsidian-main").Task>} */ | ||
_loopTasks: Array<TTask>; | ||
/** | ||
* | ||
* @param {import("obsidian-main").KeypressEvent} key | ||
*/ | ||
handleKeypressEvent(key: KeypressEvent): void; | ||
/** | ||
* | ||
* @param {"start" | "loop" | "stop"} type | ||
* @param {import("obsidian-main").Task} task | ||
*/ | ||
addTask(type: "start" | "loop" | "stop", task: TTask): void; | ||
/** | ||
* @param {Array<import("obsidian-main").Task>} tasks | ||
*/ | ||
_callTasks(tasks: Array<TTask>): Promise<void>; | ||
/** | ||
* Starts the main loop. | ||
* | ||
*/ | ||
start(): Promise<void>; | ||
/** | ||
* Stops the main loop. | ||
*/ | ||
stop(): Promise<void>; | ||
/** | ||
* Body of the main loop. | ||
*/ | ||
loop(): Promise<void>; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// obsidian-spoon is a game server | ||
// Copyright (C) 2024 Molly Crendraven | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
import { emitKeypressEvents } from "node:readline"; | ||
import { _atExit } from "obsidian-main"; | ||
import { KeypressEvent, TTask } from "./types.js"; | ||
|
||
export class MainLoop { | ||
/** @type {NodeJS.Timeout | undefined} */ | ||
_timer: NodeJS.Timeout | undefined = undefined; | ||
|
||
/** @type {Array<import("obsidian-main").Task>} */ | ||
_startTasks: Array<TTask> = []; | ||
|
||
/** @type {Array<import("obsidian-main").Task>} */ | ||
_stopTasks: Array<TTask> = []; | ||
|
||
/** @type {Array<import("obsidian-main").Task>} */ | ||
_loopTasks: Array<TTask> = []; | ||
|
||
/** | ||
* | ||
* @param {import("obsidian-main").KeypressEvent} key | ||
*/ | ||
handleKeypressEvent(key: KeypressEvent) { | ||
const keyString = key.sequence; | ||
|
||
if (keyString === "x") { | ||
this.stop(); | ||
} | ||
} | ||
/** | ||
* | ||
* @param {"start" | "loop" | "stop"} type | ||
* @param {import("obsidian-main").Task} task | ||
*/ | ||
addTask(type: "start" | "loop" | "stop", task: TTask) { | ||
if (type === "start") { | ||
this._startTasks.push(task); | ||
} else if (type === "stop") { | ||
this._stopTasks.push(task); | ||
} else if (type === "loop") { | ||
this._loopTasks.push(task); | ||
} | ||
} | ||
|
||
/** | ||
* @param {Array<import("obsidian-main").Task>} tasks | ||
*/ | ||
async _callTasks(tasks: Array<TTask>) { | ||
tasks.forEach(async (task) => { | ||
await task(); | ||
}); | ||
} | ||
|
||
/** | ||
* Starts the main loop. | ||
* | ||
*/ | ||
async start() { | ||
this._timer = setTimeout(this.loop.bind(this), 1000); | ||
if (process.stdin.isTTY !== true) { | ||
return; | ||
} | ||
emitKeypressEvents(process.stdin); | ||
process.stdin.setRawMode(true); | ||
process.stdin.resume(); | ||
console.log("Press X to exit"); | ||
process.stdin.on("keypress", (str, key) => { | ||
if (key !== undefined) { | ||
this.handleKeypressEvent(key); | ||
} | ||
}); | ||
await this._callTasks(this._startTasks); | ||
} | ||
|
||
/** | ||
* Stops the main loop. | ||
*/ | ||
async stop() { | ||
if (this._timer !== undefined) { | ||
clearInterval(this._timer); | ||
process.stdin.setRawMode(false); | ||
console.log("Exiting..."); | ||
await this._callTasks(this._stopTasks); | ||
_atExit(); | ||
} | ||
} | ||
|
||
/** | ||
* Body of the main loop. | ||
*/ | ||
async loop() { | ||
await this._callTasks(this._loopTasks); | ||
this._timer = setTimeout(this.loop.bind(this), 1000); | ||
} | ||
} |
Oops, something went wrong.