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
26 changes: 26 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def get_auto_stop_time():
except (ValueError, TypeError):
return 15

def get_demo_mode():
"""
从 data/.env 文件中读取演示模式配置
如果未设置,返回默认值False
"""
config = dotenv_values(ENV_FILE_PATH)
demo_mode = config.get('DEMO_MODE', 'False')
return demo_mode.lower() in ('true')

def save_devices(devices):
"""
将所有已连接的设备 ADB 地址保存到 data/.env 文件中
Expand Down Expand Up @@ -198,6 +207,9 @@ def handle_connect():
# 发送自动停止时间
auto_stop_time = get_auto_stop_time()
emit('auto_stop_time', {'minutes': auto_stop_time})
# 发送演示模式状态
demo_mode = get_demo_mode()
emit('demo_mode', {'enabled': demo_mode})
return True

def get_current_mirroring_device_id():
Expand All @@ -220,6 +232,15 @@ def handle_device_connect(data):
emit('connection_error', f'设备 {device_id} 已连接')
return

# 演示模式验证
if get_demo_mode():
# 获取保存的设备列表(包含预设IP)
saved_devices = get_saved_devices()
# 检查设备ID是否在预设列表中
if not any(device['address'] == device_id for device in saved_devices):
emit('connection_error', '演示模式下只允许连接预设的设备')
return

# 尝试连接设备
print(f'Trying to connect to device: {device_id}')
success, output = device_manager.adb_manager.connect_to_device(ip, port)
Expand Down Expand Up @@ -287,6 +308,11 @@ def handle_delete_saved_device(data):
"""
处理删除保存设备的请求
"""
# 演示模式验证
if get_demo_mode():
emit('error', {'message': '演示模式下不允许删除设备'})
return

device_address = data.get('device_id')
try:
# 从保存的设备列表中移除该设备(通过address字段)
Expand Down
56 changes: 53 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,45 @@ <h3>已保存的设备</h3>
}

let currentDeviceId = null;
let demoMode = false; // 演示模式状态

// 接收演示模式状态
socket.on('demo_mode', (data) => {
demoMode = data.enabled;
updateUIForDemoMode();
});

function updateUIForDemoMode() {
const deviceIpInput = document.getElementById('device-ip');
const devicePortInput = document.getElementById('device-port');
const connectBtn = document.getElementById('connect-btn');

if (demoMode) {
// 禁止"链接新设备"框的输入
deviceIpInput.disabled = true;
devicePortInput.disabled = true;
// 连接按钮在演示模式下也保持启用,以便通过已保存的设备进行链接
connectBtn.disabled = false;
} else {
// 启用"链接新设备"框的输入
deviceIpInput.disabled = false;
devicePortInput.disabled = false;
connectBtn.disabled = false;
}

// 更新设备列表,隐藏或显示相关按钮
const savedDevices = document.querySelectorAll('#saved-devices-container .list-group-item');
savedDevices.forEach(item => {
const deleteBtn = item.querySelector('.delete-saved-device-btn');
if (demoMode) {
// 前端不显示"已保存的设备"的"删除选项"
if (deleteBtn) deleteBtn.style.display = 'none';
} else {
// 显示"已保存的设备"的"删除选项"
if (deleteBtn) deleteBtn.style.display = 'inline-block';
}
});
}

function updateDeviceList(devices) {
if (!devices || devices.length === 0) {
Expand All @@ -832,6 +871,9 @@ <h3>已保存的设备</h3>
? `<button class="stop-mirror-btn btn btn-danger btn-sm" data-device="${device.id}">停止镜像</button>`
: `<button class="start-mirror-btn btn btn-success btn-sm" data-device="${device.id}">开始镜像</button>`;

// 始终显示重命名选项
const renameButton = `<button class="rename-device-btn btn btn-info btn-sm" data-device="${device.id}" data-name="${deviceName}">重命名</button>`;

return `
<div class="list-group-item">
<div class="d-flex w-100 justify-content-between align-items-center">
Expand All @@ -842,7 +884,7 @@ <h3>已保存的设备</h3>
<div class="mt-2 d-flex gap-2">
${actionButtons}
<button class="disconnect-btn btn btn-secondary btn-sm" data-device="${device.id}">断开连接</button>
<button class="rename-device-btn btn btn-info btn-sm" data-device="${device.id}" data-name="${deviceName}">重命名</button>
${renameButton}
</div>
</div>
`;
Expand Down Expand Up @@ -913,6 +955,14 @@ <h3>已保存的设备</h3>

savedDevicesContainer.innerHTML = devices.map(device => {
const [ip, port] = device.address.split(':');

// 始终显示重命名选项,演示模式下不显示删除选项
const renameButton = `<button class="rename-saved-device-btn btn btn-secondary btn-sm" data-address="${device.address}" data-name="${device.name}">重命名</button>`;

const deleteButton = demoMode
? ''
: `<button class="delete-saved-device-btn btn btn-danger btn-sm" data-device="${device.address}">删除</button>`;

return `
<div class="list-group-item">
<div class="d-flex w-100 justify-content-between align-items-center">
Expand All @@ -921,8 +971,8 @@ <h3>已保存的设备</h3>
<div class="small text-muted">地址:${device.address}</div>
<div class="mt-2 d-flex gap-2">
<button class="connect-saved-device-btn btn btn-success btn-sm" data-ip="${ip}" data-port="${port}" data-address="${device.address}">连接</button>
<button class="rename-saved-device-btn btn btn-secondary btn-sm" data-address="${device.address}" data-name="${device.name}">重命名</button>
<button class="delete-saved-device-btn btn btn-danger btn-sm" data-device="${device.address}">删除</button>
${renameButton}
${deleteButton}
</div>
</div>
`;
Expand Down
Loading