Skip to content

Commit

Permalink
Global ADB fix + linux icon
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsRiprod committed Aug 24, 2024
1 parent 09ebb2f commit 02a93c4
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 29 deletions.
4 changes: 2 additions & 2 deletions DeskThingServer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion DeskThingServer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deskthing",
"version": "0.8.0",
"version": "0.8.1",
"description": "A DeskThing server UI to interface with the DeskThing car thing app",
"main": "./out/main/index.js",
"author": "Riprod",
Expand Down
Binary file added DeskThingServer/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions DeskThingServer/src/main/handlers/adbHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ const splitArgs = (str: string): string[] => {
}

export const handleAdbCommands = async (command: string, event?): Promise<string> => {
const useGlobalADB = (await settingsStore.getSettings()).payload.globalADB || true
const settings = await settingsStore.getSettings()
const useGlobalADB = settings.payload.globalADB === true
dataListener.emit(MESSAGE_TYPES.LOGGING, useGlobalADB ? 'Using Global ADB' : 'Using Local ADB')
return new Promise((resolve, reject) => {
execFile(
useGlobalADB ? adbPath : 'adb',
useGlobalADB ? 'adb' : adbPath,
splitArgs(command),
{ cwd: execPath },
(error, stdout, stderr) => {
Expand Down
47 changes: 25 additions & 22 deletions DeskThingServer/src/main/handlers/appHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,16 +540,19 @@ async function purgeApp(appName: string): Promise<void> {
if (appInstance && typeof appInstance.purge === 'function') {
await appInstance.purge()
}
runningApps.delete(appName)
const isDeleted = runningApps.delete(appName)
console.log('stopped ', appName)
dataListener.emit(
MESSAGE_TYPES.LOGGING,
isDeleted
? `Deleted ${appName} from runningApps map`
: `Unable to find or delete ${appName} from runningApps map`
)
// Load existing apps config
const appConfig = await getAppByName(appName)

if (!appConfig) {
console.log('App not found in config, adding it')
// App not found in config, add it
const newAppConfig = { name: appName, enabled: false, running: false, prefIndex: 5 } // 5 is the default index
await setAppData(newAppConfig)
console.log('App not found in config, nothing to set!')
} else if (appConfig.enabled) {
// App found but not enabled, enable it
appConfig.enabled = false
Expand All @@ -560,10 +563,6 @@ async function purgeApp(appName: string): Promise<void> {
console.log(`App ${appName} is already disabled`)
}

// Remove the app from memory cache
const appDirectory = getAppFilePath(appName)
clearCache(appDirectory)

sendPrefData()
} catch (error) {
console.error('Error disabling app:', error)
Expand All @@ -580,20 +579,24 @@ async function clearCache(dir: string): Promise<void> {

if (stats.isDirectory()) {
// Recursively clear directories
//clearCache(itemPath)
clearCache(itemPath)
} else if (stats.isFile()) {
// Resolve and clear file from cache
const resolvedPath = require.resolve(itemPath)
if (require.cache[resolvedPath]) {
delete require.cache[resolvedPath]
console.log(`Removed ${resolvedPath} from cache`)
dataListener.asyncEmit(
MESSAGE_TYPES.LOGGING,
`SERVER: Removed ${resolvedPath} from cache`
)
} else {
console.log(`${resolvedPath} not in cache`)
dataListener.asyncEmit(MESSAGE_TYPES.LOGGING, `SERVER: ${resolvedPath} not in cache!`)
try {
// Resolve and clear file from cache
const resolvedPath = require.resolve(itemPath)
if (require.cache[resolvedPath]) {
delete require.cache[resolvedPath]
console.log(`Removed ${resolvedPath} from cache`)
dataListener.asyncEmit(
MESSAGE_TYPES.LOGGING,
`SERVER: Removed ${resolvedPath} from cache`
)
} else {
console.log(`${resolvedPath} not in cache`)
dataListener.asyncEmit(MESSAGE_TYPES.LOGGING, `SERVER: ${resolvedPath} not in cache!`)
}
} catch (e) {
console.log(e)
}
}
})
Expand Down
4 changes: 4 additions & 0 deletions DeskThingServer/src/main/handlers/keyMapHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,10 @@ const removeAction = (actionId: string): void => {
saveMappings(mappings)
}

/**
* Removes all keys and mappings relating to the App
* @param appId The ID of the app to remove
*/
const removeAppData = (appId: string): void => {
const mappings = loadMappings()

Expand Down
3 changes: 2 additions & 1 deletion DeskThingServer/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { join } from 'path'
import path from 'path'
import icon from '../../resources/icon.ico?asset'
import linuxIcon from '../../resources/icon.png?asset'
import { GithubRelease } from './types/types'
import { ServerManifest } from './handlers/deviceHandler'
import { Settings } from './stores/settingsStore'
Expand Down Expand Up @@ -65,7 +66,7 @@ function createMainWindow(): BrowserWindow {
icon: icon,
show: false,
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon: icon } : {}),
...(process.platform === 'linux' ? { icon: linuxIcon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
sandbox: false
Expand Down
2 changes: 1 addition & 1 deletion DeskThingServer/src/renderer/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const Sidebar: React.FC<SidebarProps> = ({ setCurrentView, currentView }) => {
className="group sm:flex-col items-center flex-row-reverse flex sm:border p-2 rounded-xl border-zinc-500 hover:bg-zinc-900 hover:text-red-500"
onClick={() => window.electron.ipcRenderer.send('shutdown')}
>
<p className="group-hover:block hidden">Close</p>
<p className="group-hover:block hidden">Shutdown</p>
<IconPower iconSize={24} />
</button>
<a
Expand Down

0 comments on commit 02a93c4

Please sign in to comment.