added an option to disable frames on mobile

This commit is contained in:
Ell 2022-03-26 15:23:51 +01:00
parent f7c6d93b90
commit fc6bea2f50
2 changed files with 53 additions and 22 deletions

53
main.ts
View file

@ -9,6 +9,7 @@ const presets: Record<string, CustomFrame> = {
url: "https://keep.google.com", url: "https://keep.google.com",
displayName: "Google Keep", displayName: "Google Keep",
icon: "files", icon: "files",
hideOnMobile: false,
minimumWidth: 370, minimumWidth: 370,
customCss: `/* hide the menu bar and the "Keep" text */ customCss: `/* hide the menu bar and the "Keep" text */
.PvRhvb-qAWA2, .gb_2d.gb_Zc { .PvRhvb-qAWA2, .gb_2d.gb_Zc {
@ -26,6 +27,7 @@ interface CustomFrame {
url: string; url: string;
displayName: string; displayName: string;
icon: string; icon: string;
hideOnMobile: boolean;
minimumWidth: number; minimumWidth: number;
customCss: string; customCss: string;
} }
@ -41,6 +43,10 @@ export default class CustomFramesPlugin extends Plugin {
if (!frame.url || !frame.displayName) if (!frame.url || !frame.displayName)
continue; continue;
let name = `custom-frames-${frame.displayName.toLowerCase().replace(/\s/g, "-")}`; let name = `custom-frames-${frame.displayName.toLowerCase().replace(/\s/g, "-")}`;
if (Platform.isMobileApp && frame.hideOnMobile) {
console.log(`Skipping frame ${name} which is hidden on mobile`);
continue;
}
try { try {
console.log(`Registering frame ${name} for URL ${frame.url}`); console.log(`Registering frame ${name} for URL ${frame.url}`);
@ -90,11 +96,10 @@ class CustomFrameView extends ItemView {
this.contentEl.empty(); this.contentEl.empty();
this.contentEl.addClass("custom-frames-view"); this.contentEl.addClass("custom-frames-view");
let frame: any = document.createElement("webview"); let frame: HTMLIFrameElement | any;
frame.addClass("custom-frames-frame"); if (Platform.isDesktopApp) {
frame = document.createElement("webview");
frame.setAttribute("allowpopups", ""); frame.setAttribute("allowpopups", "");
frame.setAttribute("style", `padding: ${this.settings.padding}px`);
frame.setAttribute("src", this.frame.url);
frame.addEventListener("dom-ready", () => { frame.addEventListener("dom-ready", () => {
frame.insertCSS(this.frame.customCss); frame.insertCSS(this.frame.customCss);
@ -107,6 +112,15 @@ class CustomFrameView extends ItemView {
} }
} }
}); });
}
else {
frame = document.createElement("iframe");
frame.setAttribute("sandbox", "allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts allow-top-navigation-by-user-activation");
frame.setAttribute("allow", "encrypted-media; fullscreen; oversized-images; picture-in-picture; sync-xhr; geolocation;");
}
frame.addClass("custom-frames-frame");
frame.setAttribute("style", `padding: ${this.settings.padding}px`);
frame.setAttribute("src", this.frame.url);
this.contentEl.appendChild(frame); this.contentEl.appendChild(frame);
} }
@ -166,9 +180,7 @@ class CustomFramesSettingTab extends PluginSettingTab {
new Setting(this.containerEl) new Setting(this.containerEl)
.setName("Icon") .setName("Icon")
.setDesc(createFragment(f => { .setDesc(createFragment(f => {
f.createSpan({ text: "The icon that this frame's pane should have." }); f.createSpan({ text: "The icon that this frame's pane should have. The names of any " });
f.createEl("br");
f.createSpan({ text: "The names of any " });
f.createEl("a", { text: "Lucide icons", href: "https://lucide.dev/" }); f.createEl("a", { text: "Lucide icons", href: "https://lucide.dev/" });
f.createSpan({ text: " can be used." }); f.createSpan({ text: " can be used." });
})) }))
@ -189,9 +201,23 @@ class CustomFramesSettingTab extends PluginSettingTab {
await this.plugin.saveSettings(); await this.plugin.saveSettings();
}); });
}); });
new Setting(this.containerEl)
.setName("Disable on Mobile")
.setDesc("Custom Frames is a lot more restricted on mobile devices and doesn't allow for the same types of content to be displayed. If a frame doesn't work as expected on mobile, it can be disabled.")
.addToggle(t => {
t.setValue(frame.hideOnMobile);
t.onChange(async v => {
frame.hideOnMobile = v;
await this.plugin.saveSettings();
});
});
new Setting(this.containerEl) new Setting(this.containerEl)
.setName("Minimum Width") .setName("Minimum Width")
.setDesc("The width that this frame's pane should be adjusted to automatically if it is lower. Set to 0 to disable.") .setDesc(createFragment(f => {
f.createSpan({ text: "The width that this frame's pane should be adjusted to automatically if it is lower. Set to 0 to disable." });
f.createEl("br");
f.createEl("em", { text: "Note that this is only applied on Desktop." });
}))
.addText(t => { .addText(t => {
t.inputEl.type = "number"; t.inputEl.type = "number";
t.setValue(String(frame.minimumWidth)); t.setValue(String(frame.minimumWidth));
@ -202,7 +228,11 @@ class CustomFramesSettingTab extends PluginSettingTab {
}); });
new Setting(this.containerEl) new Setting(this.containerEl)
.setName("Additional CSS") .setName("Additional CSS")
.setDesc("A snippet of additional CSS that should be applied to this frame.") .setDesc(createFragment(f => {
f.createSpan({ text: "A snippet of additional CSS that should be applied to this frame." });
f.createEl("br");
f.createEl("em", { text: "Note that this is only applied on Desktop." });
}))
.addTextArea(t => { .addTextArea(t => {
t.inputEl.rows = 5; t.inputEl.rows = 5;
t.inputEl.cols = 50; t.inputEl.cols = 50;
@ -240,10 +270,11 @@ class CustomFramesSettingTab extends PluginSettingTab {
if (option == "new") { if (option == "new") {
this.plugin.settings.frames.push({ this.plugin.settings.frames.push({
url: "", url: "",
displayName: "", displayName: "New Frame",
icon: "", icon: "",
minimumWidth: 0, minimumWidth: 0,
customCss: "" customCss: "",
hideOnMobile: false
}); });
} }
else { else {

View file

@ -6,5 +6,5 @@
"description": "A plugin that turns web apps into panes using iframes with custom styling. Also comes with presets for Google Keep and more.", "description": "A plugin that turns web apps into panes using iframes with custom styling. Also comes with presets for Google Keep and more.",
"author": "Ellpeck", "author": "Ellpeck",
"authorUrl": "https://ellpeck.de", "authorUrl": "https://ellpeck.de",
"isDesktopOnly": true "isDesktopOnly": false
} }