Skip to content

Commit be25aec

Browse files
Merge pull request #7 from andrewmcgivery/beta
Added version check, updated to support mobile
2 parents 2980a71 + 2b69360 commit be25aec

File tree

6 files changed

+115
-23
lines changed

6 files changed

+115
-23
lines changed

Diff for: esbuild.config.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import builtins from "builtin-modules";
44
import { sassPlugin } from "esbuild-sass-plugin";
55
import copyStaticFiles from "esbuild-copy-static-files";
66
import path from "path";
7+
import packageJson from "./package.json" assert { type: "json" };
78

89
const banner = `/*
910
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
@@ -55,6 +56,10 @@ const context = await esbuild.context({
5556
outdir: outdir,
5657
define: {
5758
"process.env.NODE_ENV": prod ? '"production"' : '"development"',
59+
"process.env.PLUGIN_VERSION": `"${packageJson.version}"`,
60+
"process.env.EMULATE_MOBILE": prod
61+
? "false"
62+
: process.argv.includes("--mobile").toString(),
5863
},
5964
});
6065

Diff for: main.ts

+70-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { App, Plugin, PluginSettingTab, Setting } from "obsidian";
1+
import {
2+
App,
3+
Notice,
4+
Plugin,
5+
PluginSettingTab,
6+
Setting,
7+
requestUrl,
8+
} from "obsidian";
9+
import { v4 as uuidv4 } from "uuid";
210

311
interface Divider {
412
id: string;
@@ -30,6 +38,8 @@ export default class DividerPlugin extends Plugin {
3038
async onload() {
3139
await this.loadSettings();
3240

41+
this.versionCheck();
42+
3343
// Render the dividers based on what is already in settings
3444
Object.keys(this.settings.dividers).forEach((dividerId) => {
3545
const divider = this.settings.dividers[dividerId];
@@ -39,6 +49,20 @@ export default class DividerPlugin extends Plugin {
3949

4050
// This adds a settings tab so the user can configure various aspects of the plugin
4151
this.addSettingTab(new DividerSettingTab(this.app, this));
52+
53+
if (process.env.NODE_ENV === "development") {
54+
// @ts-ignore
55+
if (process.env.EMULATE_MOBILE && !this.app.isMobile) {
56+
// @ts-ignore
57+
this.app.emulateMobile(true);
58+
}
59+
60+
// @ts-ignore
61+
if (!process.env.EMULATE_MOBILE && this.app.isMobile) {
62+
// @ts-ignore
63+
this.app.emulateMobile(false);
64+
}
65+
}
4266
}
4367

4468
onunload() {}
@@ -62,6 +86,43 @@ export default class DividerPlugin extends Plugin {
6286
await this.saveData(this.settings);
6387
}
6488

89+
/**
90+
* Check the local plugin version against github. If there is a new version, notify the user.
91+
*/
92+
async versionCheck() {
93+
const localVersion = process.env.PLUGIN_VERSION;
94+
const stableVersion = await requestUrl(
95+
"https://raw.githubusercontent.com/andrewmcgivery/obsidian-ribbon-divider/main/package.json"
96+
).then(async (res) => {
97+
if (res.status === 200) {
98+
const response = await res.json;
99+
return response.version;
100+
}
101+
});
102+
const betaVersion = await requestUrl(
103+
"https://raw.githubusercontent.com/andrewmcgivery/obsidian-ribbon-divider/beta/package.json"
104+
).then(async (res) => {
105+
if (res.status === 200) {
106+
const response = await res.json;
107+
return response.version;
108+
}
109+
});
110+
111+
if (localVersion?.indexOf("beta") !== -1) {
112+
if (localVersion !== betaVersion) {
113+
new Notice(
114+
"There is a beta update available for the Ribbon Divider plugin. Please update to to the latest version to get the latest features!",
115+
0
116+
);
117+
}
118+
} else if (localVersion !== stableVersion) {
119+
new Notice(
120+
"There is an update available for the Ribbon Divider plugin. Please update to to the latest version to get the latest features!",
121+
0
122+
);
123+
}
124+
}
125+
65126
/**
66127
* Renders a divider on the ribbon. The HTMLElement is saved to this.dividerElemenets so we can remove it if the
67128
* user deletes it from the settings screen.
@@ -70,7 +131,7 @@ export default class DividerPlugin extends Plugin {
70131
async renderDivider(divider: Divider) {
71132
const dividerIconEl = this.addRibbonIcon(
72133
"",
73-
`Divider: ${divider.id}`,
134+
`-`,
74135
(evt: MouseEvent) => {}
75136
);
76137
dividerIconEl.addClass("ribbon-divider");
@@ -97,8 +158,10 @@ export default class DividerPlugin extends Plugin {
97158
async removeDivider(dividerId: string) {
98159
delete this.settings.dividers[dividerId];
99160
this.saveSettings();
100-
this.dividerElements[dividerId].remove();
101-
delete this.dividerElements[dividerId];
161+
if (this.dividerElements[dividerId]) {
162+
this.dividerElements[dividerId].remove();
163+
delete this.dividerElements[dividerId];
164+
}
102165
}
103166
}
104167

@@ -127,20 +190,14 @@ class DividerSettingTab extends PluginSettingTab {
127190

128191
Object.keys(this.plugin.settings.dividers).forEach((dividerId) => {
129192
const divider = this.plugin.settings.dividers[dividerId];
130-
const dividerEl = dividersContainerEl.createEl("div", {
131-
attr: {
132-
"data-gate-id": divider.id,
133-
class: "ribbondividers-settings-divider",
134-
},
135-
});
136193

137-
new Setting(dividerEl)
194+
new Setting(dividersContainerEl)
138195
.setName("Divider")
139196
.setDesc(`Id: ${divider.id}`)
140197
.addButton((button) => {
141198
button.setButtonText("Delete").onClick(async () => {
142199
await this.plugin.removeDivider(divider.id);
143-
dividerEl.remove();
200+
this.display();
144201
});
145202
});
146203
});
@@ -149,7 +206,7 @@ class DividerSettingTab extends PluginSettingTab {
149206
.createEl("button", { text: "New divider", cls: "mod-cta" })
150207
.addEventListener("click", () => {
151208
this.plugin.addDivider({
152-
id: crypto.randomUUID(),
209+
id: uuidv4(),
153210
});
154211
this.display();
155212
});

Diff for: manifest.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"id": "ribbon-divider",
33
"name": "Ribbon Divider",
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"minAppVersion": "0.15.0",
66
"description": "Allows you to add dividers to the ribbon to space out your icons.",
77
"author": "Andrew McGivery",
88
"authorUrl": "https://github.com/andrewmcgivery",
99
"fundingUrl": "https://www.buymeacoffee.com/andrewmcgivery",
10-
"isDesktopOnly": true
11-
}
10+
"isDesktopOnly": false
11+
}

Diff for: package-lock.json

+23-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "obsidian-ribbon-divider",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "A plugin for Obsidian.MD that allows you to add dividers to the ribbon to space out your icons.",
55
"main": "dist/main.js",
66
"scripts": {
77
"dev": "node esbuild.config.mjs",
8+
"dev:mobile": "node esbuild.config.mjs --mobile",
89
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
910
"version": "node version-bump.mjs && git add manifest.json versions.json"
1011
},
@@ -15,6 +16,7 @@
1516
"@types/node": "^16.11.6",
1617
"@types/react": "^18.2.42",
1718
"@types/react-dom": "^18.2.17",
19+
"@types/uuid": "^9.0.8",
1820
"@typescript-eslint/eslint-plugin": "5.29.0",
1921
"@typescript-eslint/parser": "5.29.0",
2022
"builtin-modules": "3.3.0",
@@ -25,6 +27,7 @@
2527
},
2628
"dependencies": {
2729
"esbuild-copy-static-files": "^0.1.0",
28-
"esbuild-sass-plugin": "^2.16.0"
30+
"esbuild-sass-plugin": "^2.16.0",
31+
"uuid": "^9.0.1"
2932
}
3033
}

Diff for: versions.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{
2-
"1.0.0": "0.15.0"
3-
}
2+
"1.0.0": "0.15.0",
3+
"1.1.0-beta.1": "0.15.0",
4+
"1.1.0-beta.2": "0.15.0",
5+
"1.1.0-beta.3": "0.15.0",
6+
"1.1.0-beta.4": "0.15.0",
7+
"1.1.0-beta.5": "0.15.0",
8+
"1.1.0-beta.6": "0.15.0",
9+
"1.1.0": "0.15.0"
10+
}

0 commit comments

Comments
 (0)