Skip to content

Commit 6b424ff

Browse files
committed
Added ADB blacklist
1 parent 4a3997c commit 6b424ff

File tree

12 files changed

+239
-48
lines changed

12 files changed

+239
-48
lines changed

DeskThingServer/src/main/services/ipc/deviceIpc.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,38 @@ export const deviceHandler: ClientHandlerMap = {
137137
return await thingifyStore.upload(data.payload)
138138
case 'file':
139139
return await thingifyStore.selectStagedFile(data.payload)
140+
case 'latest':
141+
progressBus.startOperation(
142+
ProgressChannel.IPC_DEVICES,
143+
'Downloading Recommneded Firmware',
144+
'Initializing download...',
145+
[
146+
{
147+
channel: ProgressChannel.ST_THINGIFY_RECOMMENDED_DOWNLOAD,
148+
weight: 100
149+
}
150+
]
151+
)
152+
try {
153+
const file = await thingifyStore.downloadRecommendedFirmware()
154+
155+
return {
156+
status: true,
157+
statusText: `Successfully downloaded ${file}`,
158+
operationText: 'Download Success'
159+
}
160+
} catch (error) {
161+
progressBus.error(
162+
ProgressChannel.IPC_DEVICES,
163+
'Error downloading recommended firmware',
164+
handleError(error)
165+
)
166+
return {
167+
status: false,
168+
statusText: `Failed to download the recommended version`,
169+
operationText: handleError(error)
170+
}
171+
}
140172
}
141173
}
142174
}

DeskThingServer/src/main/static/defaultSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const defaultSettings: Settings = {
2424
adb_useGlobal: false,
2525
adb_autoConfig: false,
2626
adb_autoDetect: false,
27+
adb_blacklist: [],
2728

2829
// flags
2930
flag_firstClose: true,

DeskThingServer/src/main/stores/platforms/superbird/adbService.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,34 @@ export class ADBService implements ADBServiceClass {
2626
reject: (error: unknown) => void
2727
}[]
2828
} = {}
29+
private blacklist: string[] = []
30+
31+
constructor() {
32+
this.initialize()
33+
}
34+
35+
private initialize = async (): Promise<void> => {
36+
const settingStore = await storeProvider.getStore('settingsStore')
37+
const blacklist = await settingStore.getSetting('adb_blacklist')
38+
39+
this.blacklist = blacklist || []
40+
41+
settingStore.on('adb_blacklist', (blacklist) => {
42+
this.blacklist = blacklist || []
43+
})
44+
}
2945

3046
public async sendCommand(command: string, deviceId?: string): Promise<string> {
3147
const queueKey = deviceId || 'default'
3248

49+
if (deviceId && this.blacklist.includes(deviceId)) {
50+
logger.warn(`Blocked ADB command for blacklisted device: ${deviceId}`, {
51+
function: 'sendCommand',
52+
source: 'ADBService'
53+
})
54+
return Promise.reject(new Error(`Device ${deviceId} is blacklisted`))
55+
}
56+
3357
return new Promise((resolve, reject) => {
3458
const queueItem = { command, resolve, reject }
3559

@@ -126,7 +150,9 @@ export class ADBService implements ADBServiceClass {
126150
}
127151
}, [] as string[])
128152

129-
return adbDevices
153+
const filteredDevices = adbDevices.filter((deviceId) => !this.blacklist.includes(deviceId))
154+
155+
return filteredDevices
130156
} catch (error) {
131157
logger.error('Failed to get ADB devices', {
132158
error: error as Error,

DeskThingServer/src/main/stores/updateStore.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import electronUpdater, { type AppUpdater } from 'electron-updater'
55
import Logger from '@server/utils/logger'
66
import { LOGGING_LEVELS } from '@deskthing/types'
77
import { handleError } from '@server/utils/errorHandler'
8+
import { app } from 'electron'
9+
import { satisfies } from 'semver'
810

911
export class UpdateStore
1012
extends EventEmitter<UpdateStoreEvents>
@@ -102,11 +104,13 @@ export class UpdateStore
102104
checkForUpdates = async (): Promise<string> => {
103105
if (!this._autoUpdater) return 'AutoUpdater not initialized'
104106

107+
const appVersion = app.getVersion()
108+
105109
try {
106110
const downloadNotification = await this._autoUpdater.checkForUpdatesAndNotify()
107111
if (
108112
downloadNotification &&
109-
process.env.PACKAGE_VERSION != downloadNotification.updateInfo.version
113+
satisfies(appVersion, `<${downloadNotification.updateInfo.version}`)
110114
) {
111115
const updateInfo: UpdateInfoType = {
112116
updateAvailable: true,

DeskThingServer/src/preload/api/ipcDevice.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ export const device = {
135135
type: IPC_DEVICE_TYPES.THINGIFY_SET,
136136
request: 'file',
137137
payload: fileName
138+
}),
139+
downloadLatestFirmware: async (): Promise<ThingifyArchiveDownloadResult> =>
140+
await sendCommand({
141+
kind: IPC_HANDLERS.DEVICE,
142+
type: IPC_DEVICE_TYPES.THINGIFY_SET,
143+
request: 'latest'
138144
})
139145
}
140146

DeskThingServer/src/renderer/src/overlays/modals/DeviceDetails/ADBDetails.tsx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import {
66
IconPower,
77
IconRefresh,
88
IconReload,
9+
IconStop,
910
IconUpload,
10-
IconWrench
11+
IconWrench,
12+
IconX
1113
} from '@renderer/assets/icons'
1214
import Button from '@renderer/components/Button'
1315
import React, { useState, useRef, useMemo } from 'react'
@@ -30,6 +32,8 @@ const ADBDeviceDetails: React.FC<ClientDetailsOverlayProps> = ({ client }) => {
3032
const pushStaged = usePlatformStore((state) => state.pushStaged)
3133
const pushScript = usePlatformStore((state) => state.pushScript)
3234
const progress = useChannelProgress(ProgressChannel.IPC_PLATFORM)
35+
const initialSettings = useSettingsStore((settings) => settings.settings)
36+
const saveSettings = useSettingsStore((settings) => settings.saveSettings)
3337

3438
// ADB commands
3539
const [command, setCommand] = useState('')
@@ -151,6 +155,23 @@ const ADBDeviceDetails: React.FC<ClientDetailsOverlayProps> = ({ client }) => {
151155
await sendCommand(adbId, 'shell poweroff')
152156
}
153157

158+
const handleAddToSettings = async (): Promise<void> => {
159+
if (!adbId) return
160+
161+
setLoading(true)
162+
const currentBlacklist = initialSettings.adb_blacklist || []
163+
if (!currentBlacklist.includes(adbId)) {
164+
const updatedBlacklist = [...currentBlacklist, adbId]
165+
await saveSettings({ ...initialSettings, adb_blacklist: updatedBlacklist })
166+
console.log('ADB ID added to blacklist:', adbId)
167+
} else {
168+
const updatedBlacklist = currentBlacklist.filter((id) => id !== adbId)
169+
await saveSettings({ ...initialSettings, adb_blacklist: updatedBlacklist })
170+
console.warn('ADB ID removed from blacklist:', adbId)
171+
}
172+
setLoading(false)
173+
}
174+
154175
return (
155176
<div className="h-full p-4 overflow-y-auto bg-zinc-950">
156177
{client.identifiers.adb && (
@@ -230,6 +251,32 @@ const ADBDeviceDetails: React.FC<ClientDetailsOverlayProps> = ({ client }) => {
230251
)}
231252
<p className="sm:block text-ellipsis hidden text-nowrap">Setup Restart Script</p>
232253
</Button>
254+
<Button
255+
title="Add this device to the blacklist"
256+
className="bg-zinc-900 hover:bg-zinc-800 transition-colors duration-200 gap-2 rounded-lg p-3"
257+
onClick={handleAddToSettings}
258+
disabled={loading}
259+
>
260+
{initialSettings.adb_blacklist?.includes(adbId!) ? (
261+
<>
262+
{loading ? (
263+
<IconLoading className="animate-spin-smooth flex-shrink-0" />
264+
) : (
265+
<IconX className="flex-shrink-0" />
266+
)}
267+
<p className="sm:block text-ellipsis hidden text-nowrap">Remove From BlackList</p>
268+
</>
269+
) : (
270+
<>
271+
{loading ? (
272+
<IconLoading className="animate-spin-smooth flex-shrink-0" />
273+
) : (
274+
<IconStop className="flex-shrink-0" />
275+
)}
276+
<p className="sm:block text-ellipsis hidden text-nowrap">Add to BlackList</p>
277+
</>
278+
)}
279+
</Button>
233280
</div>
234281

235282
{progress.progress && (

DeskThingServer/src/renderer/src/overlays/settings/ServerSettings.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,21 @@ const ServerSettings: React.FC = () => {
194194
</Button>
195195
</div>
196196

197+
<div className="w-full p-4 flex justify-between items-center">
198+
<h2 className="text-xl">ADB Blacklist</h2>
199+
<input
200+
type="text"
201+
value={settings.adb_blacklist?.join(', ')}
202+
onChange={(e) =>
203+
handleSettingChange(
204+
'adb_blacklist',
205+
e.target.value.split(',').map((s) => s.trim())
206+
)
207+
}
208+
className="border border-gray-300 focus:text-black text-gray-500 rounded px-2 py-1 w-1/2"
209+
/>
210+
</div>
211+
197212
<div className="w-full px-4 flex justify-between items-center">
198213
<h2 className="text-xl">Auto Config</h2>
199214
<Button

0 commit comments

Comments
 (0)