Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opening tasks in app on mobile devices #281

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changed all icons to be part of the Lucide set to align with Obsidian.
- The `title` part of the query is now optional.

### 🐛 Bug Fixes

- Opening tasks via the context menu should now work properly on mobile devices.

## [1.11.1] - 2023-04-09

### 🐛 Bug Fixes
Expand Down
42 changes: 17 additions & 25 deletions src/contextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,20 @@ export function showTaskContext(
.showAtPosition(position);
}

const openExternal: (url: string) => Promise<void> = async (url: string) => {
try {
await getElectronOpenExternal()(url);
} catch {
new Notice("Failed to open in external application.");
}
};

type OpenExternal = (url: string) => Promise<void>;

let electronOpenExternal: OpenExternal | undefined;

function getElectronOpenExternal(): OpenExternal {
if (electronOpenExternal) {
return electronOpenExternal;
}

try {
electronOpenExternal = require("electron").shell.openExternal;
} catch (e) {
electronOpenExternal = (url) => Promise.resolve();
}

return electronOpenExternal;
}
// A bit hacky, but in order to simulate clicking a link
// we create a unparented DOM element, dispatch an event,
// then remove the link. Using electron's openExternal doesn't
// work on mobile unfortunately.
function openExternal(url: string): void {
const link = document.createElement("a");
link.href = url;

const clickEvent = new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: window
});

link.dispatchEvent(clickEvent);
link.remove();
}
Loading