Initial commit

This commit is contained in:
Index 2025-04-12 06:17:42 -05:00
commit 9fd43a0b5c
20 changed files with 5162 additions and 0 deletions

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

48
.github/workflows/buildwindows.yml vendored Normal file
View file

@ -0,0 +1,48 @@
name: Build Windows Release
on:
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies
run: npm install
- name: Build for Windows
run: npm run buildwindows
- name: Find Artifact (Installer or .exe/.zip)
id: find_artifact
run: |
$artifact = Get-ChildItem -Recurse -Path dist -Include *.exe, *.msi, *.zip | Select-Object -First 1
echo "artifact_path=$($artifact.FullName)" >> $env:GITHUB_OUTPUT
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: build-${{ github.run_number }}
name: Build ${{ github.run_number }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifact to release
uses: softprops/action-gh-release@v2
with:
tag_name: build-${{ github.run_number }}
files: ${{ steps.find_artifact.outputs.artifact_path }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

7
.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
node_modules
accounts.json
.DS_Store
/public
/dist
Localbox
Localbox.exe

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Index
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

23
README.md Normal file
View file

@ -0,0 +1,23 @@
# Desktop
Reopen the dusty box of the world of Box Critters with this app. This repository features all of the perks of [Localbox](https://github.com/Box-Critters-Localbox/Localbox) packaged into an Electron app for ease-of-use, with added Discord RPC support!
## Assets
For information on assets and how to get them, read [here](https://github.com/Box-Critters-Localbox/Localbox?tab=readme-ov-file#assets).
## Server
To build the server, first setup [Localbox](https://github.com/Box-Critters-Localbox/Localbox) and run `deno run build`. Once the server is done building, clone this repository as well. Finally, move the build of the server to the root of this repository and name it "Localbox", if it isn't already named that.
## Building
> Windows:
```
npm run buildwindows
```
> Mac:
```
npm run buildmac
```

BIN
icons/256x256.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

BIN
icons/default.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

BIN
icons/mac/1024x1024.icns Normal file

Binary file not shown.

BIN
icons/mac/128x128.icns Normal file

Binary file not shown.

BIN
icons/mac/16x16.icns Normal file

Binary file not shown.

BIN
icons/mac/256x256.icns Normal file

Binary file not shown.

BIN
icons/mac/32x32.icns Normal file

Binary file not shown.

BIN
icons/mac/512x512.icns Normal file

Binary file not shown.

BIN
icons/mac/64x64.icns Normal file

Binary file not shown.

4748
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

57
package.json Normal file
View file

@ -0,0 +1,57 @@
{
"name": "localbox-desktop",
"version": "1.0.0",
"description": "Reopen the dusty box of the world of Box Critters with this app.",
"main": "src/index.js",
"scripts": {
"start": "electron .",
"test": "echo \"Error: no test specified\" && exit 1",
"buildmac": "npx electron-builder build --mac --publish never",
"buildwindows": "npx electron-builder build --windows --x64 --publish never"
},
"author": {
"name": "Index",
"url": "https://github.com/indexxing/"
},
"license": "MIT",
"devDependencies": {
"electron": "^35.1.4",
"electron-builder": "^26.0.12"
},
"dependencies": {
"discord-rpc": "^4.0.1",
"fs": "^0.0.1-security",
"net": "^1.0.2",
"path": "^0.12.7",
"register-scheme": "^0.0.2"
},
"build": {
"productName": "Localbox",
"appId": "com.localbox.desktop",
"icon": "./icons/mac/512x512.icns",
"executableName": "Localbox",
"extraResources": [
{
"from": "Localbox",
"to": "Localbox",
"filter": [
"**/*"
]
},
{
"from": "Localbox.exe",
"to": "Localbox.exe",
"filter": [
"**/*"
]
},
{
"from": "public",
"to": "public",
"filter": [
"**/*"
]
}
]
}
}

39
src/discord.js Normal file
View file

@ -0,0 +1,39 @@
const discordRPC = require("discord-rpc");
const CLIENT_ID = "1345580676149280840";
let RPC = null;
let STATE = null;
function displayString(string) {
return string
.split(" ")
.map(segment => segment.charAt(0).toUpperCase() + segment.slice(1))
.join("");
};
function login(nickname, room) {
RPC = new discordRPC.Client({
transport: "ipc",
});
const start = new Date();
RPC.on("ready", () => {
STATE = {
details: "Exploring the " + displayString(room),
state: "Playing as " + nickname,
startTimestamp: start,
largeImageKey: "main",
};
RPC.setActivity(STATE);
});
RPC.login({ clientId: CLIENT_ID }).catch(console.error);
};
function changeState(state) {
if (!STATE) return;
STATE.details = state;
RPC.setActivity(STATE);
};
module.exports = { login, changeState };

110
src/index.js Normal file
View file

@ -0,0 +1,110 @@
const { app, BrowserWindow, ipcMain, Notification } = require("electron");
const path = require("node:path");
const fs = require("fs");
const { login, changeState } = require("./discord");
const { startServer, stopServer } = require("./server");
const IS_DEV = !app.isPackaged;
let PORT = null;
const getResourcePath = (relativePath) => {
const basePath = IS_DEV ? app.getAppPath() : process.resourcesPath;
return path.join(basePath, relativePath);
};
const setupApp = () => {
app.setName("Localbox");
app.setAboutPanelOptions({
iconPath: "../icons/default.jpg",
applicationName: "Localbox",
applicationVersion: "1.0.0",
website: "https://github.com/Box-Critters-Localbox/Desktop",
});
};
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
},
});
win.setTitle("Localbox");
win.loadFile(getResourcePath("public/index.html"));
win.maximize();
win.on("page-title-updated", function (e) {
e.preventDefault();
});
win.on("closed", () => {
stopServer();
});
};
app.whenReady().then(() => {
let executableName = "Localbox";
if (process.platform === "win32") executableName += ".exe";
startServer(getResourcePath(executableName)).then((port) => {
PORT = port;
});
setupApp();
createWindow();
/*
const menu = Menu.buildFromTemplate([
{
label: "Localbox",
submenu: [
{
role: "about",
label: "About"
},
{
label: "GitHub Repository",
click: () => shell.openExternal('https://github.com/Box-Critters-Localbox/Desktop')
},
{
type: "separator"
},
{
role: "quit",
label: "Quit"
}
]
},
{
label: "Party Switcher",
submenu: []
}
]);
//Menu.setApplicationMenu(menu);
*/
});
app.on("will-quit", () => {
stopServer();
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
/*
IPC Handlers
*/
ipcMain.handle("get-port", () => PORT);
ipcMain.handle("start-rpc", (event, nickname, room) => {
login(nickname, room);
});
ipcMain.handle("update-rpc", (event, state) => {
changeState(state);
});

7
src/preload.js Normal file
View file

@ -0,0 +1,7 @@
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld('localbox', {
getPort: () => ipcRenderer.invoke('get-port'),
startRPC: (nickname, room) => ipcRenderer.invoke('start-rpc', nickname, room),
updateRPC: (state) => ipcRenderer.invoke('update-rpc', state)
});

100
src/server.js Normal file
View file

@ -0,0 +1,100 @@
const { spawn } = require("child_process");
const fs = require("fs");
const net = require("net");
const os = require("os");
let serverProcess = null;
function getAvailablePort(start = 3000, end = 65535) {
return new Promise((resolve, reject) => {
const port = Math.floor(Math.random() * (end - start + 1)) + start;
const server = net.createServer();
server.listen(port, () => {
server.once("close", () => {
resolve(port);
});
server.close();
});
server.on("error", () => {
getAvailablePort(start, end).then(resolve).catch(reject);
});
});
}
async function startServer(executablePath) {
if (!fs.existsSync(executablePath)) {
throw new Error("Localbox executable not found at:", executablePath);
}
const PORT = await getAvailablePort(3000, 65535); // Avoid ports below 1024
console.log(`Starting server on port ${PORT}...`);
serverProcess = spawn(executablePath, [`--port=${PORT}`], {
stdio: ["ignore", "pipe", "pipe"],
});
serverProcess.stdout.on("data", (data) => {
const output = data.toString();
console.log("Server output:", output);
});
serverProcess.stderr.on("data", (data) => {
console.error("Server error:", data.toString());
});
serverProcess.on("close", (code) => {
console.log(
`Server process exited ${code != null ? "with code " + code : ""}`
);
serverProcess = null;
});
return PORT;
}
function stopServer() {
if (serverProcess) {
console.log("Killing server process...");
if (process.platform === "win32") {
// Windows
const taskkill = spawn("taskkill", [
"/pid",
serverProcess.pid,
"/f",
"/t",
]);
taskkill.on("close", (code) => {
if (code !== 0) {
console.error(
`taskkill exited with code ${code}. The server process may ` +
`not have been terminated.`
);
} else {
console.log("Server process terminated successfully on Windows.");
}
});
} else {
// macOS and Linux
serverProcess.kill("SIGTERM");
setTimeout(() => {
if (serverProcess && !serverProcess.killed) {
console.log(
"Server termination with SIGTERM failed, attempting SIGKILL"
);
serverProcess.kill("SIGKILL");
}
}, 2000);
}
}
}
module.exports = {
startServer,
stopServer,
};