Plugin ํด๋์ค๋ ํ๋ฌ๊ทธ์ธ์ ์๋ช ์ฃผ๊ธฐ(lifecycle)๋ฅผ ์ ์ํ๊ณ ๋ชจ๋ ํ๋ฌ๊ทธ์ธ์์ ์ฌ์ฉํ ์ ์๋ ์์ ๋ค์ ๋ ธ์ถํฉ๋๋ค:
import { Plugin } from 'obsidian';
export default class ExamplePlugin extends Plugin {
async onload() {
// ํ๋ฌ๊ทธ์ธ์ ํ์ํ ๋ฆฌ์์ค๋ฅผ ์ค์ ํฉ๋๋ค.
}
async onunload() {
// ํ๋ฌ๊ทธ์ธ์์ ์ค์ ํ ๋ชจ๋ ๋ฆฌ์์ค๋ฅผ ํด์ ํฉ๋๋ค.
}
}
ํ๋ฌ๊ทธ์ธ ์๋ช ์ฃผ๊ธฐ
onload()๋ ์ฌ์ฉ์๊ฐ Obsidian์์ ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๊ธฐ ์์ํ ๋๋ง๋ค ์คํ๋ฉ๋๋ค. ์ด๊ณณ์์ ํ๋ฌ๊ทธ์ธ์ ๋๋ถ๋ถ์ ๊ธฐ๋ฅ์ ์ค์ ํ๊ฒ ๋ฉ๋๋ค.
onunload()๋ ํ๋ฌ๊ทธ์ธ์ด ๋นํ์ฑํ๋ ๋ ์คํ๋ฉ๋๋ค. ํ๋ฌ๊ทธ์ธ์ด ๋นํ์ฑํ๋ ํ Obsidian์ ์ฑ๋ฅ์ ์ํฅ์ ์ฃผ์ง ์์ผ๋ ค๋ฉด ํ๋ฌ๊ทธ์ธ์์ ์ฌ์ฉํ๋ ๋ชจ๋ ๋ฆฌ์์ค๋ฅผ ์ฌ๊ธฐ์ ํด์ ํด์ผ ํฉ๋๋ค.
์ด ๋ฉ์๋๋ค์ด ์ธ์ ํธ์ถ๋๋์ง ๋ ์ ์ดํดํ๊ธฐ ์ํด, ํ๋ฌ๊ทธ์ธ์ด ๋ก๋๋๊ฑฐ๋ ์ธ๋ก๋๋ ๋๋ง๋ค ์ฝ์์ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ ์ ์์ต๋๋ค. ์ฝ์์ ๊ฐ๋ฐ์๊ฐ ์ฝ๋ ์ํ๋ฅผ ๋ชจ๋ํฐ๋งํ ์ ์๊ฒ ํด์ฃผ๋ ์ ์ฉํ ๋๊ตฌ์ ๋๋ค.
์ฝ์์ ๋ณด๋ ค๋ฉด:
- Windows ๋ฐ Linux์์๋
Ctrl+Shift+I
๋ฅผ, macOS์์๋Cmd-Option-I
๋ฅผ ๋๋ฌ ๊ฐ๋ฐ์ ๋๊ตฌ๋ฅผ ํ ๊ธํฉ๋๋ค. - ๊ฐ๋ฐ์ ๋๊ตฌ ์ฐฝ์์ ์ฝ์ ํญ์ ํด๋ฆญํฉ๋๋ค.
import { Plugin } from 'obsidian';
export default class ExamplePlugin extends Plugin {
async onload() {
console.log('loading plugin')
}
async onunload() {
console.log('unloading plugin')
}
}