Skip to content

Commit f32efda

Browse files
authored
Merge pull request #57 from jamiefdhurst/add-loaded-event
feat: add loaded event
2 parents 6a2e55c + fde5ed3 commit f32efda

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
"author": "Jamie Hurst <jamie@jamiehurst.co.uk>",
2121
"license": "MIT",
2222
"bugs": {
23-
"url": "https://github.com/jamiefdhurst/obsidian-inbox-organiser/issues"
23+
"url": "https://github.com/jamiefdhurst/obsidian-auto-tasks/issues"
2424
},
25-
"homepage": "https://github.com/jamiefdhurst/obsidian-inbox-organiser#readme",
25+
"homepage": "https://github.com/jamiefdhurst/obsidian-auto-tasks#readme",
2626
"dependencies": {
2727
"obsidian-periodic-notes-provider": "^0.1.1"
2828
},

src/events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export const LOADED = 'auto-tasks:loaded';
12
export const SETTINGS_UPDATED = 'auto-tasks:settings-updated';

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
PERIODIC_NOTES_EVENT_SETTING_UPDATED,
55
PeriodicNotesPluginAdapter,
66
} from 'obsidian-periodic-notes-provider';
7-
import { SETTINGS_UPDATED } from './events';
7+
import { LOADED, SETTINGS_UPDATED } from './events';
88
import { KanbanProvider } from './kanban/provider';
99
import { KanbanPluginAdapter } from './plugins/kanban';
1010
import { TasksPluginAdapter } from './plugins/tasks';
@@ -13,6 +13,7 @@ import { AutoTasksSettingsTab } from './settings/tab';
1313
import { TasksProvider } from './tasks/provider';
1414
import type { ObsidianApp, ObsidianVault, ObsidianWorkspace } from './types';
1515
import { TaskFactory } from './tasks/factory';
16+
import debug from './log';
1617

1718
export default class AutoTasks extends Plugin {
1819
private settings: ISettings = DEFAULT_SETTINGS;
@@ -50,10 +51,10 @@ export default class AutoTasks extends Plugin {
5051

5152
await this.loadSettings();
5253

53-
this.app.workspace.onLayoutReady(this.onLayoutReady.bind(this));
54+
this.app.workspace.onLayoutReady(await this.onLayoutReady.bind(this));
5455
}
5556

56-
onLayoutReady(): void {
57+
async onLayoutReady(): Promise<void> {
5758
if (!this.periodicNotesPlugin.isEnabled()) {
5859
new Notice(
5960
'The Periodic Notes plugin must be installed and available for Auto Tasks to work.',
@@ -62,6 +63,8 @@ export default class AutoTasks extends Plugin {
6263
return;
6364
}
6465

66+
debug('Starting initial layout and load');
67+
6568
this.settings.tasksAvailable = this.tasksPlugin.isEnabled();
6669

6770
// Convert and setup settings from plugins
@@ -111,6 +114,9 @@ export default class AutoTasks extends Plugin {
111114

112115
// Add the settings tab
113116
this.addSettingTab(new AutoTasksSettingsTab(this.app, this, this.kanbanPlugin, this.kanban));
117+
118+
this.app.workspace.trigger(LOADED);
119+
debug('Initial layout and load complete');
114120
}
115121

116122
getSettings(): ISettings {

src/log.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function debug(msg: string): void {
2+
console.debug(`[JH:AT] ${msg}`);
3+
}

src/plugins/tasks.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export class TasksPluginAdapter {
3535
}
3636

3737
private async loadSettings(): Promise<ITasksPluginSettings> {
38+
if (!this.getPlugin()) {
39+
return { taskFormat: 'tasksEmojiFormat' };
40+
}
3841
return this.getPlugin().loadData();
3942
}
4043
}

src/tasks/factory.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ export class TaskFactory {
1616
}
1717

1818
private async checkDataViewStatus() {
19-
console.log('CHECKING DATAVIEW');
2019
this.dataView = await this.pluginAdapter.isDataViewFormat();
21-
console.log('Dataview is ' + (this.dataView ? 'YES' : 'NO'));
2220
}
2321

2422
newCollection(contents: string, addBoardHeaders?: boolean): TaskCollection {
25-
console.log('About to check dataview...');
2623
this.checkDataViewStatus();
27-
console.log('Checked dataview, returning collection');
2824
return this.dataView
2925
? new DataViewTaskCollection(contents, addBoardHeaders)
3026
: new EmojiTaskCollection(contents, addBoardHeaders);

0 commit comments

Comments
 (0)