Skip to content
This repository was archived by the owner on Nov 17, 2022. It is now read-only.

Commit f1f8f4e

Browse files
committed
feat: implementation of some Transaction methods
1 parent eb3e532 commit f1f8f4e

4 files changed

Lines changed: 87 additions & 7 deletions

File tree

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import { InterfaceProvider } from './interface.provider';
21
import { PackageKit } from './packagekit';
2+
import { container } from 'tsyringe';
3+
import { TransactionProvider } from './transaction.provider';
4+
import { SearchFilter } from './search-filter.enum';
35

46
async function teste() {
57
try {
68
console.log('getting interface');
79
const packageKit = await PackageKit.create();
8-
const transaction = await packageKit.createTransaction();
9-
console.log('received', transaction);
10+
const transactionPath = await packageKit.createTransaction();
11+
const transactionProvider = container.resolve(TransactionProvider);
12+
const transaction = await transactionProvider.getTransaction(
13+
transactionPath
14+
);
15+
await transaction.cancel();
1016
} catch (e) {
1117
console.error(e);
1218
}
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
export interface TransactionDbus {
2-
on(eventName: string, callback: (...args: any) => void): void;
2+
SearchNames(
3+
filter: number,
4+
values: string[],
5+
callback: (err: unknown, args: unknown) => void
6+
): void;
7+
8+
SearchDetails(
9+
filter: number,
10+
values: string[],
11+
callback: (err: unknown, args: unknown) => void
12+
): void;
13+
14+
Cancel(callback: (err: unknown) => void): void;
15+
16+
on(eventName: string, callback: (args: unknown) => void): void;
317
}

src/search-filter.enum.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum SearchFilter {
2+
NONE = 0,
3+
INSTALLED = 1
4+
}

src/transaction.ts

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,88 @@
11
import { TransactionDbus } from './interface/transaction-dbus.interface';
22
import { Subject } from 'rxjs';
3+
import { SearchFilter } from './search-filter.enum';
34

45
export class Transaction {
56
readonly onDestroy = new Subject<Transaction>();
7+
68
private active = true;
79

810
constructor(private transactionDbus: TransactionDbus, public path: string) {
911
this.initSignalListeners();
1012
}
1113

1214
private initSignalListeners(): void {
13-
this.initOnDestroyListener();
15+
this.registerDestroyListener();
16+
}
17+
18+
// #region Methods
19+
searchNames(filter: SearchFilter, packages: string[]): Promise<void> {
20+
return new Promise<void>((resolve, reject) => {
21+
this.transactionDbus.SearchNames(
22+
filter.valueOf(),
23+
packages,
24+
function (err) {
25+
if (err) {
26+
reject();
27+
} else {
28+
resolve();
29+
}
30+
}
31+
);
32+
});
33+
}
34+
35+
cancel(): Promise<void> {
36+
return new Promise((resolve, reject) => {
37+
this.transactionDbus.Cancel((err) => {
38+
if (err) {
39+
console.error('Cancel', err);
40+
reject();
41+
} else {
42+
console.log('cancel success');
43+
resolve();
44+
}
45+
});
46+
});
1447
}
1548

16-
private initOnDestroyListener(): void {
49+
// #endregion
50+
51+
// #region Signals
52+
/**
53+
* This signal is sent when the transaction has been destroyed and is no longer available for use.
54+
*/
55+
private registerDestroyListener(): void {
1756
this.transactionDbus.on('Destroy', () => {
1857
this.active = false;
1958
this.onDestroy.next(this);
2059
this.clearSubscriptions();
2160
});
2261
}
2362

24-
private clearSubscriptions() {
63+
/**
64+
* This signal allows the backend to communicate packages to the session.
65+
*
66+
* If updating, as packages are updated then emit them to the screen. This allows a summary to be presented after the transaction.
67+
*
68+
* When returning results from a search always return installed before available for the same package name.
69+
*/
70+
private registerPackageListener(): void {
71+
this.transactionDbus.on('Package', function () {
72+
console.log('packages', arguments);
73+
});
74+
}
75+
76+
// #endregion
2577

78+
// #region auxiliary methods
79+
private clearSubscriptions(): void {
2680
const observables = [this.onDestroy];
2781

2882
observables.forEach((obs) => {
2983
obs.unsubscribe();
3084
});
3185
}
86+
87+
// #endregion
3288
}

0 commit comments

Comments
 (0)