Skip to content

Commit

Permalink
fix: Switch isMobileApp checks to isMobile and dynamically requir…
Browse files Browse the repository at this point in the history
…e node core packages to prevent plugin failure when emulating mobile on desktop
  • Loading branch information
Zachatoo committed Oct 30, 2024
1 parent 884a91d commit 3f8f764
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class InternalModuleFile extends InternalModule {
generate_path(): (relative: boolean) => string {
return (relative = false) => {
let vault_path = "";
if (Platform.isMobileApp) {
if (Platform.isMobile) {
const vault_adapter = this.plugin.app.vault.adapter.fs.uri;
const vault_base = this.plugin.app.vault.adapter.basePath;
vault_path = `${vault_adapter}/${vault_base}`;
Expand Down
12 changes: 7 additions & 5 deletions src/core/functions/user_functions/UserSystemFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { exec } from "child_process";
import { promisify } from "util";
import { FileSystemAdapter, Platform } from "obsidian";

import TemplaterPlugin from "main";
import { IGenerateObject } from "../IGenerateObject";
import { RunningConfig } from "core/Templater";
Expand All @@ -18,12 +15,17 @@ export class UserSystemFunctions implements IGenerateObject {

constructor(private plugin: TemplaterPlugin) {
if (
Platform.isMobileApp ||
Platform.isMobile ||
!(this.plugin.app.vault.adapter instanceof FileSystemAdapter)
) {
this.cwd = "";
} else {
this.cwd = this.plugin.app.vault.adapter.getBasePath();
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { promisify } = require("util") as typeof import("util");
const { exec } =
// eslint-disable-next-line @typescript-eslint/no-var-requires
require("child_process") as typeof import("child_process");
this.exec_promise = promisify(exec);
}
}
Expand Down Expand Up @@ -51,7 +53,7 @@ export class UserSystemFunctions implements IGenerateObject {
continue;
}

if (Platform.isMobileApp) {
if (Platform.isMobile) {
user_system_functions.set(template, (): Promise<string> => {
return new Promise((resolve) =>
resolve(UNSUPPORTED_MOBILE_TEMPLATE)
Expand Down
3 changes: 1 addition & 2 deletions src/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export class Editor {

mobileShouldHighlight(): boolean {
return (
Platform.isMobileApp &&
this.plugin.settings.syntax_highlighting_mobile
Platform.isMobile && this.plugin.settings.syntax_highlighting_mobile
);
}

Expand Down

0 comments on commit 3f8f764

Please sign in to comment.