Skip to content

Commit a0f3190

Browse files
committed
tests: update plugins
1 parent 49b1224 commit a0f3190

File tree

9 files changed

+358
-0
lines changed

9 files changed

+358
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"confirmDeletion": true,
3+
"showAddCommand": true,
4+
"debug": false,
5+
"editorMenu": [
6+
{
7+
"id": "plugin-reloader:gistr",
8+
"icon": "github",
9+
"name": "Plugin Reloader: Reload Gistr",
10+
"mode": "any",
11+
"color": "#b1fd0d"
12+
}
13+
],
14+
"fileMenu": [],
15+
"leftRibbon": [
16+
{
17+
"id": "plugin-reloader:gistr",
18+
"icon": "github",
19+
"name": "Plugin Reloader: Reload Gistr",
20+
"mode": "any",
21+
"color": "#f0e033"
22+
}
23+
],
24+
"rightRibbon": [],
25+
"titleBar": [],
26+
"statusBar": [],
27+
"pageHeader": [
28+
{
29+
"id": "plugin-reloader:gistr",
30+
"icon": "github",
31+
"name": "Plugin Reloader: Reload Gistr",
32+
"mode": "any",
33+
"color": "#d8f40b"
34+
}
35+
],
36+
"macros": [],
37+
"explorer": [],
38+
"hide": {
39+
"statusbar": [],
40+
"leftRibbon": []
41+
},
42+
"spacing": 8,
43+
"advancedToolbar": {
44+
"rowHeight": 48,
45+
"rowCount": 1,
46+
"spacing": 0,
47+
"buttonWidth": 48,
48+
"columnLayout": false,
49+
"mappedIcons": [],
50+
"tooltips": false,
51+
"heightOffset": 0
52+
}
53+
}

tests/Gistr Demo/.obsidian/plugins/cmdr/main.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id":"cmdr","name":"Commander","version":"0.5.4","minAppVersion":"1.4.0","description":"Customize your workspace by adding commands everywhere, create Macros and supercharge your mobile toolbar.","author":"jsmorabito & phibr0","authorUrl":"https://github.com/phibr0","fundingUrl":"https://ko-fi.com/phibr0","isDesktopOnly":false}

tests/Gistr Demo/.obsidian/plugins/cmdr/styles.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
var __defProp = Object.defineProperty;
2+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3+
var __getOwnPropNames = Object.getOwnPropertyNames;
4+
var __hasOwnProp = Object.prototype.hasOwnProperty;
5+
var __export = (target, all) => {
6+
for (var name in all)
7+
__defProp(target, name, { get: all[name], enumerable: true });
8+
};
9+
var __copyProps = (to, from, except, desc) => {
10+
if (from && typeof from === "object" || typeof from === "function") {
11+
for (let key of __getOwnPropNames(from))
12+
if (!__hasOwnProp.call(to, key) && key !== except)
13+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14+
}
15+
return to;
16+
};
17+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18+
19+
// hot-reload.ts
20+
var hot_reload_exports = {};
21+
__export(hot_reload_exports, {
22+
default: () => HotReload
23+
});
24+
module.exports = __toCommonJS(hot_reload_exports);
25+
var import_obsidian = require("obsidian");
26+
27+
// node_modules/.pnpm/[email protected]/node_modules/monkey-around/dist/index.mjs
28+
function around(obj, factories) {
29+
const removers = Object.keys(factories).map((key) => around1(obj, key, factories[key]));
30+
return removers.length === 1 ? removers[0] : function() {
31+
removers.forEach((r) => r());
32+
};
33+
}
34+
function around1(obj, method, createWrapper) {
35+
const inherited = obj[method], hadOwn = obj.hasOwnProperty(method), original = hadOwn ? inherited : function() {
36+
return Object.getPrototypeOf(obj)[method].apply(this, arguments);
37+
};
38+
let current = createWrapper(original);
39+
if (inherited)
40+
Object.setPrototypeOf(current, inherited);
41+
Object.setPrototypeOf(wrapper, current);
42+
obj[method] = wrapper;
43+
return remove;
44+
function wrapper(...args) {
45+
if (current === original && obj[method] === wrapper)
46+
remove();
47+
return current.apply(this, args);
48+
}
49+
function remove() {
50+
if (obj[method] === wrapper) {
51+
if (hadOwn)
52+
obj[method] = original;
53+
else
54+
delete obj[method];
55+
}
56+
if (current === original)
57+
return;
58+
current = original;
59+
Object.setPrototypeOf(wrapper, inherited || Function);
60+
}
61+
}
62+
63+
// hot-reload.ts
64+
var watchNeeded = !import_obsidian.Platform.isMacOS && !import_obsidian.Platform.isWin;
65+
var HotReload = class extends import_obsidian.Plugin {
66+
constructor() {
67+
super(...arguments);
68+
this.statCache = /* @__PURE__ */ new Map();
69+
// path -> Stat
70+
this.run = taskQueue();
71+
this.reindexPlugins = (0, import_obsidian.debounce)(() => this.run(() => this.getPluginNames()), 250, true);
72+
this.pluginReloaders = {};
73+
this.pluginNames = {};
74+
this.enabledPlugins = /* @__PURE__ */ new Set();
75+
this.currentlyLoading = 0;
76+
this.isSymlink = (() => {
77+
try {
78+
const { lstatSync } = require("fs");
79+
return (path) => {
80+
const realPath = [this.app.vault.adapter.basePath, path].join("/");
81+
const lstat = lstatSync(realPath, { throwIfNoEntry: false });
82+
return lstat && lstat.isSymbolicLink();
83+
};
84+
} catch (e) {
85+
return () => true;
86+
}
87+
})();
88+
this.checkVersion = async (plugin) => {
89+
const { dir } = this.app.plugins.manifests[plugin];
90+
for (const file of ["main.js", "styles.css"]) {
91+
const path = `${dir}/${file}`;
92+
const stat = await this.app.vault.adapter.stat(path);
93+
if (stat) {
94+
if (this.statCache.has(path) && stat.mtime !== this.statCache.get(path).mtime) {
95+
this.requestReload(plugin);
96+
}
97+
this.statCache.set(path, stat);
98+
}
99+
}
100+
};
101+
this.onFileChange = (filename) => {
102+
if (!filename.startsWith(this.app.plugins.getPluginFolder() + "/"))
103+
return;
104+
const path = filename.split("/");
105+
const base = path.pop(), dir = path.pop();
106+
if (path.length === 1 && dir === "plugins")
107+
return this.watch(filename);
108+
if (path.length != 2)
109+
return;
110+
const plugin = dir && this.pluginNames[dir];
111+
if (base === "manifest.json" || base === ".hotreload" || base === ".git" || !plugin)
112+
return this.reindexPlugins();
113+
if (base !== "main.js" && base !== "styles.css")
114+
return;
115+
this.checkVersion(plugin);
116+
};
117+
}
118+
async onload() {
119+
await this.getPluginNames();
120+
this.addCommand({
121+
id: "scan-for-changes",
122+
name: "Check plugins for changes and reload them",
123+
callback: this.reindexPlugins
124+
});
125+
this.app.workspace.onLayoutReady(() => {
126+
this.registerEvent(this.app.vault.on("raw", this.onFileChange));
127+
this.watch(this.app.plugins.getPluginFolder());
128+
});
129+
}
130+
async watch(path) {
131+
var _a;
132+
if ((_a = this.app.vault.adapter.watchers) == null ? void 0 : _a.hasOwnProperty(path))
133+
return;
134+
if ((await this.app.vault.adapter.stat(path)).type !== "folder")
135+
return;
136+
if (watchNeeded || this.isSymlink(path))
137+
this.app.vault.adapter.startWatchPath(path, false);
138+
}
139+
checkVersions() {
140+
return Promise.all(Object.values(this.pluginNames).map(this.checkVersion));
141+
}
142+
async getPluginNames() {
143+
const plugins = {}, enabled = /* @__PURE__ */ new Set();
144+
for (const { id, dir } of Object.values(this.app.plugins.manifests)) {
145+
this.watch(dir);
146+
plugins[dir.split("/").pop()] = id;
147+
if (await this.app.vault.exists(dir + "/.git") || await this.app.vault.exists(dir + "/.hotreload"))
148+
enabled.add(id);
149+
}
150+
this.pluginNames = plugins;
151+
this.enabledPlugins = enabled;
152+
await this.checkVersions();
153+
}
154+
requestReload(plugin) {
155+
if (!this.enabledPlugins.has(plugin))
156+
return;
157+
const reloader = this.pluginReloaders[plugin] || (this.pluginReloaders[plugin] = (0, import_obsidian.debounce)(() => this.run(() => this.reload(plugin).catch(console.error)), 750, true));
158+
reloader();
159+
}
160+
async reload(plugin) {
161+
const plugins = this.app.plugins;
162+
if (!plugins.enabledPlugins.has(plugin))
163+
return;
164+
await plugins.disablePlugin(plugin);
165+
console.debug("disabled", plugin);
166+
const oldDebug = localStorage.getItem("debug-plugin");
167+
localStorage.setItem("debug-plugin", "1");
168+
const uninstall = preventSourcemapStripping(this.app, plugin);
169+
try {
170+
await plugins.enablePlugin(plugin);
171+
} finally {
172+
if (oldDebug === null)
173+
localStorage.removeItem("debug-plugin");
174+
else
175+
localStorage.setItem("debug-plugin", oldDebug);
176+
uninstall == null ? void 0 : uninstall();
177+
}
178+
console.debug("enabled", plugin);
179+
new import_obsidian.Notice(`Plugin "${plugin}" has been reloaded`);
180+
}
181+
};
182+
function preventSourcemapStripping(app, pluginName) {
183+
if ((0, import_obsidian.requireApiVersion)("1.6"))
184+
return around(app.vault.adapter, {
185+
read(old) {
186+
return function(path) {
187+
const res = old.apply(this, arguments);
188+
if (!path.endsWith(`/${pluginName}/main.js`))
189+
return res;
190+
return res.then((txt) => txt + "\n/* nosourcemap */");
191+
};
192+
}
193+
});
194+
}
195+
function taskQueue() {
196+
let last = Promise.resolve();
197+
return (action) => {
198+
return !action ? last : last = new Promise(
199+
(res, rej) => last.finally(
200+
() => {
201+
try {
202+
res(action());
203+
} catch (e) {
204+
rej(e);
205+
}
206+
}
207+
)
208+
);
209+
};
210+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": "hot-reload",
3+
"name": "Hot Reload",
4+
"author": "PJ Eby",
5+
"authorUrl": "https://github.com/pjeby",
6+
"version": "0.2.1",
7+
"minAppVersion": "1.5.8",
8+
"isDesktopOnly": true,
9+
"fundingUrl": "https://dirtsimple.org/tips/hot-reload",
10+
"description": "Automatically reload in-development plugins when their files are changed"
11+
}

tests/Gistr Demo/.obsidian/plugins/obsidian42-brat/data.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"pluginList": [
3+
"Benature/obsidian-plugin-reloader",
4+
"phibr0/obsidian-commander",
35
"Aetherinox/obsidian-gistr"
46
],
57
"pluginSubListFrozenVersion": [],

0 commit comments

Comments
 (0)