Skip to content

Commit

Permalink
feat: set Devel manifest as default manifest if any
Browse files Browse the repository at this point in the history
Closes #224
  • Loading branch information
SeaDve authored and bilelmoussaoui committed Nov 9, 2023
1 parent 92c7acc commit 1535b98
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
33 changes: 26 additions & 7 deletions src/manifestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,16 @@ export class ManifestManager implements vscode.Disposable {
lastActiveManifestUri = undefined
}

const manifests = await this.getManifests()

if (lastActiveManifestUri === undefined) {
// If there is only one manifest to select, select it automatically.
const firstManifest = manifests.getFirstItem()
if (manifests.size() === 1 && firstManifest) {
console.log(`Found only one valid manifest. Setting active manifest to ${firstManifest.uri.fsPath}`)
await this.setActiveManifest(firstManifest, true)
const defaultManifest = await this.findDefaultManifest()
if (defaultManifest !== undefined) {
console.log(`Manifest set as default at ${defaultManifest.uri.fsPath}`)
await this.setActiveManifest(defaultManifest, true)
}
return
}

const manifests = await this.getManifests()
const lastActiveManifest = manifests.get(lastActiveManifestUri)
if (lastActiveManifest === undefined) {
return
Expand All @@ -108,6 +106,27 @@ export class ManifestManager implements vscode.Disposable {
await this.setActiveManifest(lastActiveManifest, true)
}

async findDefaultManifest(): Promise<Manifest | undefined> {
const manifests = await this.getManifests()

// If there is only one manifest to select, select it automatically.
const firstManifest = manifests.getFirstItem()
if (manifests.size() === 1 && firstManifest) {
console.log('Found only one valid manifest')
return firstManifest
}

// If some manifest contains '.Devel.' in its filename, select it automatically.
for (const manifest of manifests) {
if (manifest.uri.fsPath.includes('.Devel.')) {
console.log('Found a manifest that contains ".Devel." in its filename')
return manifest
}
}

return undefined
}

async getManifests(): Promise<ManifestMap> {
if (this.manifests === undefined) {
console.log('Looking for potential Flatpak manifests')
Expand Down
6 changes: 5 additions & 1 deletion src/manifestMap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Manifest } from './manifest'
import * as vscode from 'vscode'

export class ManifestMap {
export class ManifestMap implements Iterable<Manifest> {
private readonly inner: Map<string, Manifest>

private readonly _onDidItemsChanged = new vscode.EventEmitter<void>()
Expand All @@ -11,6 +11,10 @@ export class ManifestMap {
this.inner = new Map()
}

[Symbol.iterator](): IterableIterator<Manifest> {
return this.inner.values()
}

add(manifest: Manifest): void {
this.inner.set(manifest.uri.fsPath, manifest)
this._onDidItemsChanged.fire()
Expand Down

0 comments on commit 1535b98

Please sign in to comment.