Skip to content

Commit

Permalink
feat(desktop): support enable ignore qos 0 messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream committed Aug 28, 2024
1 parent 5632e97 commit 93e32f0
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ async function createWindow() {
openAIAPIKey: setting.openAIAPIKey,
model: setting.model,
logLevel: setting.logLevel,
ignoreQoS0Message: setting.ignoreQoS0Message,
}
}
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions src/database/database.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { enableCopilot1703659148195 } from './migration/1703659148195-enableCopi
import { logLevel1704941582350 } from './migration/1704941582350-logLevel'
import { updatePayloadTypeToVarchar1630403733965 } from './migration/1705478422620-updatePayloadTypeToVarchar'
import { supportOpenAIAPIHost1716044120271 } from './migration/1716044120271-supportOpenAIAPIHost'
import { ignoreQoS0Message1724839386732 } from './migration/1724839386732-ignoreQoS0Message'

const STORE_PATH = getAppDataPath('MQTTX')
try {
Expand Down Expand Up @@ -96,6 +97,7 @@ const ORMConfig = {
logLevel1704941582350,
updatePayloadTypeToVarchar1630403733965,
supportOpenAIAPIHost1716044120271,
ignoreQoS0Message1724839386732,
],
migrationsTableName: 'temp_migration_table',
entities: [
Expand Down
140 changes: 140 additions & 0 deletions src/database/migration/1724839386732-ignoreQoS0Message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { MigrationInterface, QueryRunner } from 'typeorm'

export class ignoreQoS0Message1724839386732 implements MigrationInterface {
name = 'ignoreQoS0Message1724839386732'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE "temporary_SettingEntity" (
"id" varchar PRIMARY KEY NOT NULL,
"width" integer NOT NULL DEFAULT (1025),
"height" integer NOT NULL DEFAULT (749),
"autoCheck" boolean NOT NULL DEFAULT (1),
"currentLang" varchar CHECK(currentLang IN ('zh', 'en', 'ja', 'tr', 'hu')) NOT NULL DEFAULT ('en'),
"currentTheme" varchar CHECK(currentTheme IN ('light', 'dark', 'night')) NOT NULL DEFAULT ('light'),
"maxReconnectTimes" integer NOT NULL DEFAULT (10),
"autoResub" boolean NOT NULL DEFAULT (1),
"syncOsTheme" boolean NOT NULL DEFAULT (0),
"multiTopics" boolean NOT NULL DEFAULT (1),
"jsonHighlight" boolean NOT NULL DEFAULT (1),
"openAIAPIKey" varchar NOT NULL DEFAULT (''),
"model" varchar NOT NULL DEFAULT ('gpt-3.5-turbo'),
"enableCopilot" boolean NOT NULL DEFAULT (1),
"logLevel" varchar CHECK(logLevel IN ('debug', 'info', 'warn', 'error')) NOT NULL DEFAULT ('info'),
"openAIAPIHost" varchar NOT NULL DEFAULT ('https://api.openai.com/v1'),
"ignoreQoS0Message" boolean NOT NULL DEFAULT (0)
)
`)
await queryRunner.query(`
INSERT INTO "temporary_SettingEntity"(
"id",
"width",
"height",
"autoCheck",
"currentLang",
"currentTheme",
"maxReconnectTimes",
"autoResub",
"syncOsTheme",
"multiTopics",
"jsonHighlight",
"openAIAPIKey",
"model",
"enableCopilot",
"logLevel",
"openAIAPIHost"
)
SELECT "id",
"width",
"height",
"autoCheck",
"currentLang",
"currentTheme",
"maxReconnectTimes",
"autoResub",
"syncOsTheme",
"multiTopics",
"jsonHighlight",
"openAIAPIKey",
"model",
"enableCopilot",
"logLevel",
"openAIAPIHost"
FROM "SettingEntity"
`)
await queryRunner.query(`
DROP TABLE "SettingEntity"
`)
await queryRunner.query(`
ALTER TABLE "temporary_SettingEntity"
RENAME TO "SettingEntity"
`)
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "SettingEntity"
RENAME TO "temporary_SettingEntity"
`)
await queryRunner.query(`
CREATE TABLE "SettingEntity" (
"id" varchar PRIMARY KEY NOT NULL,
"width" integer NOT NULL DEFAULT (1025),
"height" integer NOT NULL DEFAULT (749),
"autoCheck" boolean NOT NULL DEFAULT (1),
"currentLang" varchar CHECK(currentLang IN ('zh', 'en', 'ja', 'tr', 'hu')) NOT NULL DEFAULT ('en'),
"currentTheme" varchar CHECK(currentTheme IN ('light', 'dark', 'night')) NOT NULL DEFAULT ('light'),
"maxReconnectTimes" integer NOT NULL DEFAULT (10),
"autoResub" boolean NOT NULL DEFAULT (1),
"syncOsTheme" boolean NOT NULL DEFAULT (0),
"multiTopics" boolean NOT NULL DEFAULT (1),
"jsonHighlight" boolean NOT NULL DEFAULT (1),
"openAIAPIKey" varchar NOT NULL DEFAULT (''),
"model" varchar NOT NULL DEFAULT ('gpt-3.5-turbo'),
"enableCopilot" boolean NOT NULL DEFAULT (1),
"logLevel" varchar CHECK(logLevel IN ('debug', 'info', 'warn', 'error')) NOT NULL DEFAULT ('info'),
"openAIAPIHost" varchar NOT NULL DEFAULT ('https://api.openai.com/v1')
)
`)
await queryRunner.query(`
INSERT INTO "SettingEntity"(
"id",
"width",
"height",
"autoCheck",
"currentLang",
"currentTheme",
"maxReconnectTimes",
"autoResub",
"syncOsTheme",
"multiTopics",
"jsonHighlight",
"openAIAPIKey",
"model",
"enableCopilot",
"logLevel",
"openAIAPIHost"
)
SELECT "id",
"width",
"height",
"autoCheck",
"currentLang",
"currentTheme",
"maxReconnectTimes",
"autoResub",
"syncOsTheme",
"multiTopics",
"jsonHighlight",
"openAIAPIKey",
"model",
"enableCopilot",
"logLevel",
"openAIAPIHost"
FROM "temporary_SettingEntity"
`)
await queryRunner.query(`
DROP TABLE "temporary_SettingEntity"
`)
}
}
3 changes: 3 additions & 0 deletions src/database/models/SettingEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ export default class SettingEntity {

@Column({ type: 'simple-enum', enum: ['debug', 'info', 'warn', 'error'], default: 'info' })
logLevel!: 'debug' | 'info' | 'warn' | 'error'

@Column({ type: 'boolean', default: false })
ignoreQoS0Message!: boolean
}
14 changes: 14 additions & 0 deletions src/lang/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,18 @@ export default {
ja: 'MQTTX CLIをワンクリックでインストールします。インストール中に管理者アクセスのプロンプトが表示されます。インストール後、ターミナルでMQTTXを実行できます。',
hu: 'Egy kattintással telepítheti az MQTTX CLI-t. Telepítés közben rendszergazdai hozzáférésre vonatkozó kérést fog kapni. Telepítés után a terminálban futtathatja az MQTTX-et.',
},
ignoreQoS0Message: {
zh: '忽略 QoS 0 消息',
en: 'Ignore QoS 0 Message',
tr: 'QoS 0 Mesajını Yakalamayın',
ja: 'QoS 0 メッセージを無視する',
hu: 'QoS 0 üzeneteket figyelmen kívül hagyás',
},
ignoreQoS0MessageDesc: {
zh: '开启后,MQTTX 将忽略 QoS 0 的消息,不会将其存储到本地,已保存的消息不会被自动清除,从而提高性能',
en: 'Once enabled, MQTTX will ignore QoS 0 messages and will not store them locally. Already saved messages will not be automatically cleared, improving performance',
tr: 'Etkinleştirdiğinizde, MQTTX QoS 0 mesajlarını yok sayacak ve bunları yerel olarak depolamayacaktır. Zaten kaydedilmiş olan mesajlar otomatik olarak temizlenmeyecektir, performansı artıracaktır.',
ja: 'この機能を有効にすると、MQTTX は QoS 0 メッセージを無視し、それらをローカルに保存しません。すでに保存されたメッセージは自動的にクリアされません。これにより、パフォーマンスが向上します。',
hu: 'Ha engedélyezve van, az MQTTX figyelmen kívül hagyja a QoS 0 üzeneteket, és nem tárolja őket helyben. Már mentett üzeneteket nem fog automatikusan törölni, ami teljesítmény javítását eredményezi.',
},
}
1 change: 1 addition & 0 deletions src/store/getter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const getters = {
logLevel: (state: State) => state.app.logLevel,
showConnectionList: (state: State) => state.app.showConnectionList,
connectDatabaseFailMessage: (state: State) => state.app.connectDatabaseFailMessage,
ignoreQoS0Message: (state: State) => state.app.ignoreQoS0Message,
}

export default getters
11 changes: 11 additions & 0 deletions src/store/modules/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const TOGGLE_ENABLE_COPILOT = 'TOGGLE_ENABLE_COPILOT'
const SET_LOG_LEVEL = 'SET_LOG_LEVEL'
const TOGGLE_SHOW_CONNECTION_LIST = 'TOGGLE_SHOW_CONNECTION_LIST'
const SET_DATABASE_FAIL_MESSAGE = 'SET_DATABASE_FAIL_MESSAGE'
const TOGGLE_IGNORE_QOS0_MESSAGE = 'TOGGLE_IGNORE_QOS0_MESSAGE'

const getShowConnectionList = (): boolean => {
const _showConnectionList: string | null = localStorage.getItem('showConnectionList')
Expand Down Expand Up @@ -65,6 +66,7 @@ const app = {
logLevel: settingData.logLevel || 'info',
showConnectionList: getShowConnectionList(),
connectDatabaseFailMessage: settingData.connectDatabaseFailMessage || '',
ignoreQoS0Message: settingData.ignoreQoS0Message || false,
},
mutations: {
[TOGGLE_THEME](state: App, currentTheme: Theme) {
Expand Down Expand Up @@ -169,6 +171,9 @@ const app = {
[SET_DATABASE_FAIL_MESSAGE](state: App, connectDatabaseFailMessage: string) {
state.connectDatabaseFailMessage = connectDatabaseFailMessage
},
[TOGGLE_IGNORE_QOS0_MESSAGE](state: App, ignoreQoS0Message: boolean) {
state.ignoreQoS0Message = ignoreQoS0Message
},
},
actions: {
async TOGGLE_THEME({ commit }: any, payload: App) {
Expand Down Expand Up @@ -288,6 +293,12 @@ const app = {
SET_DATABASE_FAIL_MESSAGE({ commit }: any, payload: App) {
commit(SET_DATABASE_FAIL_MESSAGE, payload.connectDatabaseFailMessage)
},
async TOGGLE_IGNORE_QOS0_MESSAGE({ commit }: any, payload: App) {
const { settingService } = useServices()
commit(TOGGLE_IGNORE_QOS0_MESSAGE, payload.ignoreQoS0Message)
settingData.ignoreQoS0Message = payload.ignoreQoS0Message
await settingService.update(payload)
},
},
}

Expand Down
1 change: 1 addition & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ declare global {
logLevel: LogLevel
showConnectionList: boolean
connectDatabaseFailMessage: string
ignoreQoS0Message: boolean
}

interface State {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/mqttUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,8 @@ export const getDefaultRecord = (): ConnectionModel => {
}
}

export const ignoreQoS0Message = (qos: QoS): boolean => {
return Store.getters.ignoreQoS0Message && qos === 0
}

export default {}
16 changes: 11 additions & 5 deletions src/views/connections/ConnectionsDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ import cbor from 'cbor'
import time from '@/utils/time'
import matchMultipleSearch from '@/utils/matchMultipleSearch'
import { matchTopicMethod } from '@/utils/topicMatch'
import { createClient } from '@/utils/mqttUtils'
import { createClient, ignoreQoS0Message } from '@/utils/mqttUtils'
import { getBytes, getUptime, getVersion } from '@/utils/SystemTopicUtils'
import validFormatJson from '@/utils/validFormatJson'
import delay from '@/utils/delay'
Expand Down Expand Up @@ -1332,8 +1332,12 @@ export default class ConnectionsDetail extends Vue {
private async saveMessage(id: string, messages: MessageModel[]) {
try {
if (messages.length) {
const { messageService } = useServices()
await messageService.pushMsgsToConnection(messages, id)
const filteredMessages = messages.filter((msg) => !ignoreQoS0Message(msg.qos))
console.log('filteredMessages', filteredMessages)
if (filteredMessages.length) {
const { messageService } = useServices()
await messageService.pushMsgsToConnection(filteredMessages, id)
}
}
} catch (error) {
this.$log.error((error as Error).toString())
Expand Down Expand Up @@ -1673,8 +1677,10 @@ export default class ConnectionsDetail extends Vue {
this.updateMeta(publishMessage, 'schema', 'publish')
if (this.record.id) {
const { messageService } = useServices()
await messageService.pushMsgsToConnection({ ...publishMessage }, this.record.id)
if (!ignoreQoS0Message(qos)) {
const { messageService } = useServices()
await messageService.pushMsgsToConnection({ ...publishMessage }, this.record.id)
}
this.renderMessage(this.curConnectionId, publishMessage, 'publish')
this.logSuccessfulPublish(publishMessage)
}
Expand Down
34 changes: 34 additions & 0 deletions src/views/settings/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,32 @@
</el-row>
<el-divider></el-divider>

<el-row class="settings-item" type="flex" justify="space-between" align="middle">
<el-col :span="20">
<label>{{ $t('settings.ignoreQoS0Message') }}</label>
<el-tooltip
placement="top"
:effect="currentTheme !== 'light' ? 'light' : 'dark'"
:open-delay="500"
:content="$t('settings.ignoreQoS0MessageDesc')"
>
<a href="javascript:;" class="icon-oper">
<i class="el-icon-warning-outline"></i>
</a>
</el-tooltip>
</el-col>
<el-col :span="4">
<el-switch
:value="ignoreQoS0Message"
active-color="#13ce66"
inactive-color="#A2A9B0"
@change="handleIgnoreQoS0MessageSwitchChange"
>
</el-switch>
</el-col>
</el-row>
<el-divider></el-divider>

<ImportData :visible.sync="showImportData" />
<ExportData :visible.sync="showExportData" />
<ClearUpHistoryData :visible.sync="showHistoryData" />
Expand Down Expand Up @@ -423,6 +449,9 @@ export default class Settings extends Vue {
@Action('SET_OPEN_AI_API_KEY') private actionSetOpenAIAPIKey!: (payload: { openAIAPIKey: string }) => void
@Action('SET_MODEL') private actionSetModel!: (payload: { model: AIModel }) => void
@Action('SET_LOG_LEVEL') private actionSetLogLevel!: (payload: { logLevel: LogLevel }) => void
@Action('TOGGLE_IGNORE_QOS0_MESSAGE') private actionToggleIgnoreQoS0Message!: (payload: {
ignoreQoS0Message: boolean
}) => void
@Getter('currentTheme') private currentTheme!: Theme
@Getter('currentLang') private currentLang!: Language
Expand All @@ -437,6 +466,7 @@ export default class Settings extends Vue {
@Getter('openAIAPIKey') private openAIAPIKey!: string
@Getter('model') private model!: AIModel
@Getter('logLevel') private logLevel!: LogLevel
@Getter('ignoreQoS0Message') private ignoreQoS0Message!: boolean
private showAIModelsSelect = false
Expand Down Expand Up @@ -599,6 +629,10 @@ export default class Settings extends Vue {
cb(queryString ? this.AIAPIHostOptions.filter((item) => item.value.includes(queryString)) : this.AIAPIHostOptions)
}
private handleIgnoreQoS0MessageSwitchChange(value: boolean) {
this.actionToggleIgnoreQoS0Message({ ignoreQoS0Message: value })
}
private created() {
this.getAIConfigs()
}
Expand Down

0 comments on commit 93e32f0

Please sign in to comment.