mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-01 04:14:45 +03:00
Organise the prompt service code a bit better
Note that instance fields are evaluated during instance creation, at the start of the constructor.
This commit is contained in:
parent
14def6e616
commit
0d5dbc25b7
@ -6,6 +6,7 @@ export type SystemPrompt = {
|
|||||||
id: string;
|
id: string;
|
||||||
prompt: string;
|
prompt: string;
|
||||||
context?: {
|
context?: {
|
||||||
|
// TODO: camelCase this field
|
||||||
branch_id?: string;
|
branch_id?: string;
|
||||||
action?: string;
|
action?: string;
|
||||||
};
|
};
|
||||||
@ -20,19 +21,19 @@ type PromptResponse = {
|
|||||||
export class PromptService {
|
export class PromptService {
|
||||||
prompt$ = new Subject<SystemPrompt>();
|
prompt$ = new Subject<SystemPrompt>();
|
||||||
|
|
||||||
constructor() {
|
private unlisten = listen<SystemPrompt>('git_prompt', async (e) => {
|
||||||
this.subscribe(async (payload) => {
|
// You can send an action token to e.g. `fetch_target_data` and it will be echoed in
|
||||||
if (payload.context?.action == 'auto') {
|
// these events. The action `auto` is used by the `BaseBranchService` so we can not
|
||||||
this.cancel(payload.id).then(() => console.log('cancelled auto askpass', payload));
|
// respond to them.
|
||||||
} else {
|
if (e.payload.context?.action != 'auto') {
|
||||||
this.prompt$.next(payload);
|
this.prompt$.next(e.payload);
|
||||||
}
|
} else {
|
||||||
});
|
// Always cancel actions that are marked "auto", e.g. periodic sync
|
||||||
}
|
await this.cancel(e.payload.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
private subscribe(callback: (params: SystemPrompt) => Promise<void> | void) {
|
constructor() {}
|
||||||
return listen<SystemPrompt>('git_prompt', (e) => callback(e.payload));
|
|
||||||
}
|
|
||||||
|
|
||||||
async respond(payload: PromptResponse) {
|
async respond(payload: PromptResponse) {
|
||||||
return await invoke('submit_prompt_response', payload);
|
return await invoke('submit_prompt_response', payload);
|
||||||
@ -41,4 +42,8 @@ export class PromptService {
|
|||||||
async cancel(id: string) {
|
async cancel(id: string) {
|
||||||
return await invoke('submit_prompt_response', { id: id, response: null });
|
return await invoke('submit_prompt_response', { id: id, response: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this.unlisten();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user