mirror of
https://github.com/ahmetildirim/obsidian-inscribe.git
synced 2026-07-22 05:44:10 +00:00
Refactor ProfileService to enhance event handling and improve code clarity
This commit is contained in:
parent
58136cee32
commit
0febf73535
3 changed files with 15 additions and 14 deletions
|
|
@ -27,10 +27,6 @@ export default class Inscribe extends Plugin {
|
|||
await this.setupExtension();
|
||||
}
|
||||
|
||||
async onunload() {
|
||||
this.profileService.onunload();
|
||||
}
|
||||
|
||||
async setupExtension() {
|
||||
const extension = inlineSuggestions({
|
||||
fetchFunc: () => this.completionService.fetchCompletion(),
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ export class ProfileService {
|
|||
private activePath: string;
|
||||
private app: App;
|
||||
private settings: Settings;
|
||||
private inlineSuggestionOptions: InlineCompletionOptions = { delayMs: 300, splitStrategy: "sentence" };
|
||||
private profileChangeCallbacks: ((profile: Profile) => void)[] = [];
|
||||
|
||||
constructor(plugin: Inscribe) {
|
||||
|
|
@ -19,10 +18,20 @@ export class ProfileService {
|
|||
this.settings = this.plugin.settings;
|
||||
this.update(this.getActiveFilePath());
|
||||
|
||||
this.app.workspace.on('file-open', (file) => {
|
||||
if (!file) return;
|
||||
this.update(file.path);
|
||||
});
|
||||
// Add listener for file open events
|
||||
this.plugin.registerEvent(
|
||||
this.app.workspace.on('file-open', (file) => {
|
||||
if (!file) return;
|
||||
this.update(file.path);
|
||||
})
|
||||
);
|
||||
|
||||
// Add listener for file rename events
|
||||
this.plugin.registerEvent(
|
||||
this.app.vault.on('rename', (file) => {
|
||||
this.update(file.path);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getActiveProfile(): Profile {
|
||||
|
|
@ -83,8 +92,4 @@ export class ProfileService {
|
|||
|
||||
return [pathMapping, this.settings.profiles[matchedProfile]];
|
||||
}
|
||||
|
||||
onunload() {
|
||||
this.app.workspace.off('file-open', this.update);
|
||||
}
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ export default class StatusBarItem {
|
|||
item.setTitle(`Profile: ${profile.name}`).setIsLabel(true);
|
||||
});
|
||||
menu.addItem((item) => {
|
||||
item.setTitle(`Completion is ${pathCompletionEnabled ? 'On' : 'Off'} for: {${path}]}`)
|
||||
item.setTitle(`Completion is ${pathCompletionEnabled ? 'On' : 'Off'} for: {${path}}`)
|
||||
.setChecked(pathCompletionEnabled)
|
||||
.onClick(() => {
|
||||
const pathConfig = findPathConfig(this.plugin.settings, path);
|
||||
|
|
|
|||
Loading…
Reference in a new issue