Compare commits

...

9 commits

Author SHA1 Message Date
semantic-release-bot
e05272a1af release(version): Release 1.1.2 [skip ci]
## [1.1.2](https://github.com/cdloh/obsidian-cron/compare/1.1.1...1.1.2) (2023-08-24)

### Bug Fixes

* Fix cleaning up running jobs when deleting crons ([e505695](e505695003)), closes [#4](https://github.com/cdloh/obsidian-cron/issues/4)
2023-08-24 10:26:12 +00:00
Callum Loh
add69d0df3
Merge pull request #6 from cdloh/fix/cleanup-running-jobs-on-delete
fix: Fix cleaning up running jobs when deleting crons
2023-08-24 11:25:04 +01:00
Callum Loh
e505695003 fix: Fix cleaning up running jobs when deleting crons
Fixes #4
2023-08-24 11:23:14 +01:00
semantic-release-bot
e548b24a72 release(version): Release 1.1.1 [skip ci]
## [1.1.1](https://github.com/cdloh/obsidian-cron/compare/1.1.0...1.1.1) (2023-04-23)

### Bug Fixes

* Fix the lock feature for cronjob ([70cb4a8](70cb4a8686))
2023-04-23 19:16:45 +00:00
Callum Loh
05caef22b9
Merge pull request #2 from cdloh/fix-lock-settings
fix: Fix the lock feature for cronjob
2023-04-24 05:15:17 +10:00
Callum Loh
70cb4a8686 fix: Fix the lock feature for cronjob 2023-04-23 20:13:36 +01:00
Callum Loh
4ec092a421
Add License 2023-03-27 01:34:57 +11:00
semantic-release-bot
517ac93d56 release(version): Release 1.1.0 [skip ci]
# [1.1.0](https://github.com/cdloh/obsidian-cron/compare/1.0.0...1.1.0) (2023-03-26)

### Features

* Add option to disable on Mobile ([996c4fd](996c4fdddb))
2023-03-26 14:27:33 +00:00
Callum Loh
996c4fdddb feat: Add option to disable on Mobile 2023-03-26 15:25:40 +01:00
7 changed files with 83 additions and 43 deletions

21
LICENSE.md Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Callum Loh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,7 +1,7 @@
{
"id": "cron",
"name": "Cron",
"version": "1.0.0",
"version": "1.1.2",
"minAppVersion": "0.15.0",
"description": "Simple CRON / schedular plugin to regularly run user scripts or Obsidian commands.",
"author": "Callum Loh",

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "obsidian-cron-plugin",
"version": "1.0.0",
"version": "1.1.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "obsidian-cron-plugin",
"version": "1.0.0",
"version": "1.1.2",
"license": "MIT",
"dependencies": {
"@popperjs/core": "^2.11.6",

View file

@ -1,6 +1,6 @@
{
"name": "obsidian-cron-plugin",
"version": "1.0.0",
"version": "1.1.2",
"description": "Simple CRON / Schedular plugin to regularly run user scripts or Obsidian commands for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {

View file

@ -9,6 +9,7 @@ import CronAPI from './api';
export interface CronSettings {
cronInterval: number;
runOnStartup: boolean
enableMobile: boolean
watchObsidianSync: boolean
crons: Array<CRONJob>,
locks: { [key: string]: CronLock }
@ -25,6 +26,7 @@ export interface CRONJob {
const DEFAULT_SETTINGS: CronSettings = {
cronInterval: 15,
runOnStartup: true,
enableMobile: true,
watchObsidianSync: true,
crons: [],
locks: {}
@ -55,6 +57,7 @@ export default class Cron extends Plugin {
this.api = CronAPI.get(this)
this.app.workspace.onLayoutReady(() => {
if(this.settings.runOnStartup) {
if(this.app.isMobile && !this.settings.enableMobile) { return }
this.runCron()
}
})
@ -120,6 +123,7 @@ export default class Cron extends Plugin {
public loadInterval() {
clearInterval(this.interval)
if(this.app.isMobile && !this.settings.enableMobile) { return }
this.interval = window.setInterval(async () => { await this.runCron() }, this.settings.cronInterval * 60 * 1000)
this.registerInterval(this.interval)
}

View file

@ -12,10 +12,10 @@ export default class CronSettingTab extends PluginSettingTab {
}
display(): void {
const {containerEl} = this;
const { containerEl } = this;
containerEl.empty();
containerEl.createEl('h2', {text: 'Settings for Cron.'});
containerEl.createEl('h2', { text: 'Settings for Cron.' });
new Setting(containerEl)
.setName('Cron Interval')
@ -23,7 +23,7 @@ export default class CronSettingTab extends PluginSettingTab {
.addText(text => text
.setValue(this.plugin.settings.cronInterval.toString())
.onChange(async (value) => {
if(value == "") {return}
if (value == "") { return }
this.plugin.settings.cronInterval = parseInt(value);
await this.plugin.saveSettings();
this.plugin.loadInterval();
@ -52,14 +52,25 @@ export default class CronSettingTab extends PluginSettingTab {
})
);
new Setting(containerEl)
.setName('Enable Obsidian on Mobile')
.setDesc('Whether or not to load jobs at all on Mobile devices. If disabled even jobs with mobile enabled will not run.')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.enableMobile)
.onChange(async (value) => {
this.plugin.settings.enableMobile = value;
await this.plugin.saveSettings();
})
);
const desc = document.createDocumentFragment();
desc.append(
"List of CRON Jobs to run. Jobs will not be ran until all 3 fields have been filled",
desc.createEl("br"),
"Cron Frequency is a cron schedule expression. Use ",
desc.createEl("a", {
href: "https://crontab.guru/",
text: "crontab guru",
href: "https://crontab.guru/",
text: "crontab guru",
}),
" for help with creating cron schedule expressions."
);
@ -71,7 +82,7 @@ export default class CronSettingTab extends PluginSettingTab {
this.addCommandSearch()
}
addCommandSearch (): void {
addCommandSearch(): void {
this.plugin.settings.crons.forEach((cronjob, index) => {
const jobSetting = new Setting(this.containerEl)
@ -86,17 +97,17 @@ export default class CronSettingTab extends PluginSettingTab {
.inputEl.addClass('cron-plugin-text-input')
)
.addSearch((cb) => {
new CommandSuggest(cb.inputEl);
cb.setPlaceholder("Command")
.setValue(cronjob.job)
.onChange(async (command) => {
if(!command) { return }
new CommandSuggest(cb.inputEl);
cb.setPlaceholder("Command")
.setValue(cronjob.job)
.onChange(async (command) => {
if (!command) { return }
this.plugin.settings.crons[index].job = command;
await this.plugin.saveSettings();
this.plugin.loadCrons();
})
.inputEl.addClass('cron-plugin-text-input')
this.plugin.settings.crons[index].job = command;
await this.plugin.saveSettings();
this.plugin.loadCrons();
})
.inputEl.addClass('cron-plugin-text-input')
})
.addText(text => text
.setPlaceholder("CronJob frequency")
@ -119,33 +130,34 @@ export default class CronSettingTab extends PluginSettingTab {
})
})
const jobLocked = this.plugin.settings.locks[cronjob.name] && this.plugin.settings.locks[cronjob.name].locked
jobSetting.addExtraButton((button) => {
button.setIcon(jobLocked ? "lucide-lock" : "lucide-unlock")
.setTooltip("Toggle job lock (clear lock if accidentally left locked)")
.onClick(() => {
this.plugin.settings.locks[cronjob.id].locked = !jobLocked;
this.plugin.saveSettings();
// refresh
this.display()
})
})
const jobLocked = this.plugin.settings.locks[cronjob.id] && this.plugin.settings.locks[cronjob.id].locked
jobSetting.addExtraButton((button) => {
button.setIcon(jobLocked ? "lucide-lock" : "lucide-unlock")
.setTooltip("Toggle job lock (clear lock if accidentally left locked)")
.onClick(() => {
this.plugin.settings.locks[cronjob.id].locked = !jobLocked;
this.plugin.saveSettings();
// refresh
this.display()
})
})
jobSetting.addExtraButton((button) => {
button.setIcon(cronjob.settings.disableSyncCheck ? "paused" : "lucide-check-circle-2")
.setTooltip("Toggle Sync check for this job. Presently: " + (cronjob.settings.disableSyncCheck ? "disabled" : "enabled"))
.onClick(() => {
this.plugin.settings.crons[index].settings.disableSyncCheck = !cronjob.settings.disableSyncCheck;
this.plugin.saveSettings();
// Force refresh
this.display();
});
})
jobSetting.addExtraButton((button) => {
button.setIcon(cronjob.settings.disableSyncCheck ? "paused" : "lucide-check-circle-2")
.setTooltip("Toggle Sync check for this job. Presently: " + (cronjob.settings.disableSyncCheck ? "disabled" : "enabled"))
.onClick(() => {
this.plugin.settings.crons[index].settings.disableSyncCheck = !cronjob.settings.disableSyncCheck;
this.plugin.saveSettings();
// Force refresh
this.display();
});
})
.addExtraButton((button) => {
button.setIcon("cross")
.setTooltip("Delete Job")
.onClick(() => {
this.plugin.settings.crons.splice(index, 1)
delete this.plugin.jobs[cronjob.id]
delete this.plugin.settings.locks[cronjob.id]
this.plugin.saveSettings();
// Force refresh
@ -153,7 +165,7 @@ export default class CronSettingTab extends PluginSettingTab {
});
});
jobSetting.controlEl.addClass("cron-plugin-job")
jobSetting.controlEl.addClass("cron-plugin-job")
});
new Setting(this.containerEl).addButton((cb) => {

View file

@ -1,4 +1,7 @@
{
"0.0.1": "0.15.0",
"1.0.0": "0.15.0"
"1.0.0": "0.15.0",
"1.1.0": "0.15.0",
"1.1.1": "0.15.0",
"1.1.2": "0.15.0"
}