feat: v1.1.0 迭代更新
Server: - 添加房间密码验证 POST /rooms/:id/join - 添加玩家踢出 POST /rooms/:id/kick/:playerId - 添加房间过期自动清理(30分钟无活动) - 添加流量统计 GET /traffic - 添加token认证中间件保护写操作API - 房间详情返回玩家列表 Client: - 添加设置持久化(electron-store) - 添加设置页面(玩家名、本地端口、自动重连、托盘最小化) - 添加系统托盘支持(最小化到托盘、右键菜单) - 添加最近连接服务器记录 - 连接成功自动保存服务器地址 - 加入房间自动填充默认端口
This commit is contained in:
@@ -4,6 +4,15 @@ const $$ = (sel) => document.querySelectorAll(sel);
|
||||
|
||||
let isConnected = false;
|
||||
let currentServerUrl = '';
|
||||
let appSettings = {};
|
||||
|
||||
// Load settings on startup
|
||||
(async () => {
|
||||
appSettings = await window.funmc.getSettings();
|
||||
if (appSettings.serverUrl) $('#server-url').value = appSettings.serverUrl;
|
||||
if (appSettings.localPort) $('#join-local-port').value = appSettings.localPort;
|
||||
showRecentServers();
|
||||
})();
|
||||
|
||||
// ===== Window Controls =====
|
||||
$('#btn-min').addEventListener('click', () => window.funmc.minimize());
|
||||
@@ -42,6 +51,11 @@ $('#btn-connect').addEventListener('click', async () => {
|
||||
updateServerStatus(true);
|
||||
showMsg('#connect-msg', '连接成功!', 'success');
|
||||
showServerInfo(result.data);
|
||||
// Save to recent servers and settings
|
||||
await window.funmc.addRecentServer(url);
|
||||
await window.funmc.setSettings({ serverUrl: url });
|
||||
appSettings.serverUrl = url;
|
||||
showRecentServers();
|
||||
} else {
|
||||
isConnected = false;
|
||||
updateServerStatus(false);
|
||||
@@ -125,13 +139,14 @@ async function loadRooms() {
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function quickJoin(roomId) {
|
||||
async function quickJoin(roomId) {
|
||||
// Navigate to join page and fill in room ID
|
||||
$$('.nav-item').forEach(n => n.classList.remove('active'));
|
||||
document.querySelector('[data-page="join"]').classList.add('active');
|
||||
$$('.page').forEach(p => p.classList.remove('active'));
|
||||
$('#page-join').classList.add('active');
|
||||
$('#join-room-id').value = roomId;
|
||||
if (appSettings.localPort) $('#join-local-port').value = appSettings.localPort;
|
||||
}
|
||||
|
||||
// ===== Host Page =====
|
||||
@@ -255,6 +270,62 @@ document.querySelector('[data-page="rooms"]').addEventListener('click', () => {
|
||||
if (isConnected) loadRooms();
|
||||
});
|
||||
|
||||
// ===== Settings Page =====
|
||||
document.querySelector('[data-page="settings"]').addEventListener('click', loadSettings);
|
||||
|
||||
async function loadSettings() {
|
||||
appSettings = await window.funmc.getSettings();
|
||||
$('#settings-name').value = appSettings.playerName || '';
|
||||
$('#settings-port').value = appSettings.localPort || 25566;
|
||||
$('#settings-autoreconnect').checked = appSettings.autoReconnect !== false;
|
||||
$('#settings-tray').checked = appSettings.minimizeToTray !== false;
|
||||
|
||||
const list = $('#settings-recent-list');
|
||||
const recent = appSettings.recentServers || [];
|
||||
if (recent.length === 0) {
|
||||
list.innerHTML = '<div class="recent-list-empty">暂无记录</div>';
|
||||
} else {
|
||||
list.innerHTML = recent.map(url => `
|
||||
<div class="recent-list-item">
|
||||
<span class="url">${escapeHtml(url)}</span>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
}
|
||||
|
||||
$('#btn-save-settings').addEventListener('click', async () => {
|
||||
const settings = {
|
||||
playerName: $('#settings-name').value.trim() || 'Player',
|
||||
localPort: parseInt($('#settings-port').value) || 25566,
|
||||
autoReconnect: $('#settings-autoreconnect').checked,
|
||||
minimizeToTray: $('#settings-tray').checked,
|
||||
};
|
||||
await window.funmc.setSettings(settings);
|
||||
Object.assign(appSettings, settings);
|
||||
$('#join-local-port').value = settings.localPort;
|
||||
showMsg('#settings-msg', '设置已保存', 'success');
|
||||
setTimeout(() => showMsg('#settings-msg', '', ''), 2000);
|
||||
});
|
||||
|
||||
async function showRecentServers() {
|
||||
const settings = await window.funmc.getSettings();
|
||||
const recent = settings.recentServers || [];
|
||||
const container = $('#recent-servers');
|
||||
if (recent.length === 0) {
|
||||
container.classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
container.classList.remove('hidden');
|
||||
container.innerHTML = recent.map(url => `
|
||||
<div class="recent-item" data-url="${escapeHtml(url)}">${escapeHtml(url)}</div>
|
||||
`).join('');
|
||||
container.querySelectorAll('.recent-item').forEach(item => {
|
||||
item.addEventListener('click', () => {
|
||||
$('#server-url').value = item.dataset.url;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ===== Utilities =====
|
||||
function showMsg(selector, text, type) {
|
||||
const el = $(selector);
|
||||
|
||||
Reference in New Issue
Block a user