Mobile / Desktop toggle switch

Switching between desktop and mobile emulation.

While developing my workspace for mobile and desktop use, I find myself constantly switching between emulation modes in order to code css for different uses.

Proposed solution

I would love it if there was a simple trigger to swap between mobile and desktop mode via a simple button or command prompt, rather than having to open developer mode and run the command, “this.app.emulateMobile(!this.app.isMobile);”, in the console.

Removed “plugin-release” tag because post doesn’t announce a release of a plugin.

This plugin has a command for it:

obsidian://show-plugin?id=obsidian-theme-design-utilities

Perfect!

Found the line that makes it happen. Super simple…

  this.addCommand({
        id: "toggle-emulate-mobile",
        name: "Mobile emulation toggle",
        callback: () => this.app.emulateMobile(!this.app.isMobile),
      });
1 Like

Now,the next question is… is it possible to access the core files for the slash command plugin and add this command into it?

Quick update that uses the public API of Platform.isMobile:

import { Platform } from "obsidian";

this.addCommand({
  id: "toggle-emulate-mobile",
  name: "Mobile emulation toggle",
  callback: () => this.app.emulateMobile(!Platform.isMobile),
});

Worth noting that this does not provide perfect emulation. For example, the bottom ribbon on Android does not appear.