修复注册的事件未被清理的问题

pull/1853/head
lyswhut 2024-04-02 11:07:50 +08:00
parent 274f71615f
commit e60c2f5f19
12 changed files with 36 additions and 47 deletions

View File

@ -2,7 +2,7 @@
- 主题编辑器添加“深色字体”选项,启用后将减少字体颜色梯度,各类字体(正文、标签字体等)颜色将更接近,这有助于解决创建全透明主题时可能出现的字体配色问题(#1799 - 主题编辑器添加“深色字体”选项,启用后将减少字体颜色梯度,各类字体(正文、标签字体等)颜色将更接近,这有助于解决创建全透明主题时可能出现的字体配色问题(#1799
- 新增在线自定义源导入功能允许通过http/https链接导入自定义源 - 新增在线自定义源导入功能允许通过http/https链接导入自定义源
- 新增HTTP开放API服务默认关闭该服务可以为第三方软件提供调用LX的能力可用API看说明文档#1824 - 新增HTTP开放API服务默认关闭该服务可以为第三方软件提供调用LX的能力可用API看[说明文档](https://lyswhut.github.io/lx-music-doc/desktop/open-api)#1824
- 托盘菜单新增播放、切歌、收藏控制 - 托盘菜单新增播放、切歌、收藏控制
### 优化 ### 优化

View File

@ -231,7 +231,7 @@ export default class LinePlayer {
timeoutTools.cancelNextTick = window.cancelAnimationFrame.bind(window) timeoutTools.cancelNextTick = window.cancelAnimationFrame.bind(window)
} else { } else {
timeoutTools.nextTick = (handler) => { timeoutTools.nextTick = (handler) => {
return setTimeout(handler, 80) return setTimeout(handler, 20)
} }
timeoutTools.cancelNextTick = clearTimeout.bind(global) timeoutTools.cancelNextTick = clearTimeout.bind(global)
} }

View File

@ -2,6 +2,7 @@ import fs from 'node:fs'
import crypto from 'node:crypto' import crypto from 'node:crypto'
import { gzip, gunzip } from 'node:zlib' import { gzip, gunzip } from 'node:zlib'
import path from 'node:path' import path from 'node:path'
import { networkInterfaces } from 'node:os'
import { log } from '@common/utils' import { log } from '@common/utils'
export const joinPath = (...paths: string[]): string => path.join(...paths) export const joinPath = (...paths: string[]): string => path.join(...paths)
@ -185,3 +186,20 @@ export const copyFile = async(sourcePath: string, distPath: string) => {
export const moveFile = async(sourcePath: string, distPath: string) => { export const moveFile = async(sourcePath: string, distPath: string) => {
return fs.promises.rename(sourcePath, distPath) return fs.promises.rename(sourcePath, distPath)
} }
export const getAddress = (): string[] => {
const nets = networkInterfaces()
const results: string[] = []
// console.log(nets)
for (const interfaceInfos of Object.values(nets)) {
if (!interfaceInfos) continue
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
for (const interfaceInfo of interfaceInfos) {
if (interfaceInfo.family === 'IPv4' && !interfaceInfo.internal) {
results.push(interfaceInfo.address)
}
}
}
return results
}

View File

@ -461,7 +461,7 @@
"setting__odc_clear_search_input": "Clear the search box when you are not searching", "setting__odc_clear_search_input": "Clear the search box when you are not searching",
"setting__odc_clear_search_list": "Clear the search list when you are not searching", "setting__odc_clear_search_list": "Clear the search list when you are not searching",
"setting__open_api": "Open API", "setting__open_api": "Open API",
"setting__open_api_address": "Service address: {address}", "setting__open_api_address": "Service address:",
"setting__open_api_bind_lan": "Allow access from LAN", "setting__open_api_bind_lan": "Allow access from LAN",
"setting__open_api_enable": "Enable open API service", "setting__open_api_enable": "Enable open API service",
"setting__open_api_port": "Service port", "setting__open_api_port": "Service port",

View File

@ -461,7 +461,7 @@
"setting__odc_clear_search_input": "离开搜索界面时清空搜索框", "setting__odc_clear_search_input": "离开搜索界面时清空搜索框",
"setting__odc_clear_search_list": "离开搜索界面时清空搜索列表", "setting__odc_clear_search_list": "离开搜索界面时清空搜索列表",
"setting__open_api": "开放API", "setting__open_api": "开放API",
"setting__open_api_address": "服务地址:{address}", "setting__open_api_address": "服务地址:",
"setting__open_api_bind_lan": "允许来自局域网的访问", "setting__open_api_bind_lan": "允许来自局域网的访问",
"setting__open_api_enable": "启用开放API服务", "setting__open_api_enable": "启用开放API服务",
"setting__open_api_port": "服务端口", "setting__open_api_port": "服务端口",

View File

@ -461,7 +461,7 @@
"setting__odc_clear_search_input": "離開搜尋介面時清空搜尋框", "setting__odc_clear_search_input": "離開搜尋介面時清空搜尋框",
"setting__odc_clear_search_list": "離開搜尋介面時清空搜尋列表", "setting__odc_clear_search_list": "離開搜尋介面時清空搜尋列表",
"setting__open_api": "開放API", "setting__open_api": "開放API",
"setting__open_api_address": "服務地址:{address}", "setting__open_api_address": "服務地址:",
"setting__open_api_bind_lan": "允許來自區域網路的訪問", "setting__open_api_bind_lan": "允許來自區域網路的訪問",
"setting__open_api_enable": "啟用開放API服務", "setting__open_api_enable": "啟用開放API服務",
"setting__open_api_port": "服務連接埠", "setting__open_api_port": "服務連接埠",

View File

@ -1,6 +1,7 @@
import http from 'node:http' import http from 'node:http'
import querystring from 'node:querystring' import querystring from 'node:querystring'
import type { Socket } from 'node:net' import type { Socket } from 'node:net'
import { getAddress } from '@common/utils/nodejs'
let status: LX.OpenAPI.Status = { let status: LX.OpenAPI.Status = {
status: false, status: false,
@ -198,11 +199,13 @@ export const stopServer = async() => {
return status return status
} }
export const startServer = async(port: number, bindLan: boolean) => { export const startServer = async(port: number, bindLan: boolean) => {
if (status.status) await handleStopServer() if (status.status) await stopServer()
await handleStartServer(port, bindLan ? '0.0.0.0' : '127.0.0.1').then(() => { await handleStartServer(port, bindLan ? '0.0.0.0' : '127.0.0.1').then(() => {
status.status = true status.status = true
status.message = '' status.message = ''
status.address = `http://localhost${port == 80 ? '' : ':' + port}` let address = ['127.0.0.1']
if (bindLan) address = [...address, ...getAddress()]
status.address = address.join(', ')
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
status.status = false status.status = false

View File

@ -6,10 +6,11 @@ import { callObj } from './sync'
// import registerSyncListHandler from './syncList' // import registerSyncListHandler from './syncList'
import log from '../log' import log from '../log'
import { dateFormat } from '@common/utils/common' import { dateFormat } from '@common/utils/common'
import { aesEncrypt, getAddress } from '../utils' import { aesEncrypt } from '../utils'
import { sendClientStatus } from '@main/modules/winMain' import { sendClientStatus } from '@main/modules/winMain'
import { createMsg2call } from 'message2call' import { createMsg2call } from 'message2call'
import { SYNC_CLOSE_CODE, SYNC_CODE } from '@common/constants_sync' import { SYNC_CLOSE_CODE, SYNC_CODE } from '@common/constants_sync'
import { getAddress } from '@common/utils/nodejs'
let status: LX.Sync.ClientStatus = { let status: LX.Sync.ClientStatus = {
status: false, status: false,

View File

@ -2,7 +2,6 @@ import http, { type IncomingMessage } from 'node:http'
import { WebSocketServer } from 'ws' import { WebSocketServer } from 'ws'
import { registerLocalSyncEvent, callObj, sync, unregisterLocalSyncEvent } from './sync' import { registerLocalSyncEvent, callObj, sync, unregisterLocalSyncEvent } from './sync'
import { authCode, authConnect } from './auth' import { authCode, authConnect } from './auth'
import { getAddress } from '../../utils'
import { SYNC_CLOSE_CODE, SYNC_CODE } from '@common/constants_sync' import { SYNC_CLOSE_CODE, SYNC_CODE } from '@common/constants_sync'
import { getUserSpace, releaseUserSpace, getServerId, initServerInfo } from '../user' import { getUserSpace, releaseUserSpace, getServerId, initServerInfo } from '../user'
import { createMsg2call } from 'message2call' import { createMsg2call } from 'message2call'
@ -11,6 +10,7 @@ import { sendServerStatus } from '@main/modules/winMain'
import { decryptMsg, encryptMsg, generateCode as handleGenerateCode } from '../utils/tools' import { decryptMsg, encryptMsg, generateCode as handleGenerateCode } from '../utils/tools'
import migrateData from '../../migrate' import migrateData from '../../migrate'
import type { Socket } from 'node:net' import type { Socket } from 'node:net'
import { getAddress } from '@common/utils/nodejs'
let status: LX.Sync.ServerStatus = { let status: LX.Sync.ServerStatus = {

View File

@ -1,4 +1,3 @@
import { networkInterfaces } from 'node:os'
import { createCipheriv, createDecipheriv, publicEncrypt, privateDecrypt, constants } from 'node:crypto' import { createCipheriv, createDecipheriv, publicEncrypt, privateDecrypt, constants } from 'node:crypto'
// import { join } from 'node:path' // import { join } from 'node:path'
import zlib from 'node:zlib' import zlib from 'node:zlib'
@ -8,23 +7,6 @@ import type http from 'node:http'
// import { getUserName } from '../user/data' // import { getUserName } from '../user/data'
// import { saveClientKeyInfo } from './data' // import { saveClientKeyInfo } from './data'
export const getAddress = (): string[] => {
const nets = networkInterfaces()
const results: string[] = []
// console.log(nets)
for (const interfaceInfos of Object.values(nets)) {
if (!interfaceInfos) continue
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
for (const interfaceInfo of interfaceInfos) {
if (interfaceInfo.family === 'IPv4' && !interfaceInfo.internal) {
results.push(interfaceInfo.address)
}
}
}
return results
}
export const generateCode = (): string => { export const generateCode = (): string => {
return Math.random().toString().substring(2, 8) return Math.random().toString().substring(2, 8)
} }

View File

@ -1,28 +1,10 @@
import { createCipheriv, createDecipheriv, publicEncrypt, privateDecrypt, constants } from 'node:crypto' import { createCipheriv, createDecipheriv, publicEncrypt, privateDecrypt, constants } from 'node:crypto'
import os, { networkInterfaces } from 'node:os' import os from 'node:os'
import fs from 'node:fs' import fs from 'node:fs'
import zlib from 'node:zlib' import zlib from 'node:zlib'
import cp from 'node:child_process' import cp from 'node:child_process'
export const getAddress = (): string[] => {
const nets = networkInterfaces()
const results: string[] = []
// console.log(nets)
for (const interfaceInfos of Object.values(nets)) {
if (!interfaceInfos) continue
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
for (const interfaceInfo of interfaceInfos) {
if (interfaceInfo.family === 'IPv4' && !interfaceInfo.internal) {
results.push(interfaceInfo.address)
}
}
}
return results
}
// https://stackoverflow.com/a/75309339 // https://stackoverflow.com/a/75309339
export const getComputerName = () => { export const getComputerName = () => {
let name: string | undefined let name: string | undefined
@ -40,6 +22,7 @@ export const getComputerName = () => {
try { try {
name = cp.execSync('hostnamectl --pretty').toString().trim() name = cp.execSync('hostnamectl --pretty').toString().trim()
} catch {} } catch {}
break
} }
if (!name) name = os.hostname() if (!name) name = os.hostname()
return name return name

View File

@ -6,7 +6,9 @@ dd.gap-top
base-checkbox(id="setting_open_api_enable" :model-value="appSetting['openAPI.enable']" :label="$t('setting__open_api_enable')" @update:model-value="updateSetting({ 'openAPI.enable': $event })") base-checkbox(id="setting_open_api_enable" :model-value="appSetting['openAPI.enable']" :label="$t('setting__open_api_enable')" @update:model-value="updateSetting({ 'openAPI.enable': $event })")
.p.gap-top .p.gap-top
base-checkbox(id="setting_open_api_bind_lan" :model-value="appSetting['openAPI.bindLan']" :label="$t('setting__open_api_bind_lan')" @update:model-value="updateSetting({ 'openAPI.bindLan': $event })") base-checkbox(id="setting_open_api_bind_lan" :model-value="appSetting['openAPI.bindLan']" :label="$t('setting__open_api_bind_lan')" @update:model-value="updateSetting({ 'openAPI.bindLan': $event })")
.p.gap-top.small {{ $t('setting__open_api_address', { address: openAPI.address || '' }) }} .p.gap-top.small
| {{ $t('setting__open_api_address') }}
span.select {{ openAPI.address }}
.p.small(v-if="openAPI.message") {{ openAPI.message }} .p.small(v-if="openAPI.message") {{ openAPI.message }}
.p .p
.p.small {{ $t('setting__open_api_port') }} .p.small {{ $t('setting__open_api_port') }}