Skip to content

Try opening redirect link automatically on native app #434

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 14 additions & 5 deletions src/entrypoints/my-redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
extractSearchParamsObject,
} from "../util/search-params";
import { getInstanceUrl } from "../data/instance_info";
import { Redirect } from "../const";
import { MOBILE_URL, Redirect } from "../const";
import { svgPencil } from "../components/svg-pencil";
import { isMobile } from "../data/is_mobile";
import { validateParam } from "../util/validate";
Expand Down Expand Up @@ -40,6 +40,12 @@ const createRedirectParams = (): string => {

let changingInstance = false;

const getRedirectUrl = (baseUrl: string, params) => {
return window.redirect.redirect === "oauth"
? `${baseUrl}/auth/external/callback${params}`
: `${baseUrl}/_my_redirect/${window.redirect.redirect}${params}`;
};

const render = (showTroubleshooting: boolean) => {
const instanceUrl = getInstanceUrl();

Expand All @@ -56,6 +62,12 @@ const render = (showTroubleshooting: boolean) => {
return;
}

if (!isMobile && navigator.userAgent.includes("Windows")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like this idea, but agree with Bram that the user should never aware of this.

Just allowing it for Windows is ok. But prefer if we could also allow it for Chromium browsers on Mac, but that can be in a subsequent PR.

I will ask a Windows users to verify the behavior and then this can be merged. Definitely better than another button.

// Try opening the native app on Windows
const redirectUrlToNativeApp = getRedirectUrl(MOBILE_URL, params);
document.location.assign(redirectUrlToNativeApp);
}

const changeUrl = `/redirect/_change/?redirect=${encodeURIComponent(
window.redirect.redirect + "/" + params
)}`;
Expand All @@ -66,10 +78,7 @@ const render = (showTroubleshooting: boolean) => {
return;
}

const redirectUrl =
window.redirect.redirect === "oauth"
? `${instanceUrl}/auth/external/callback${params}`
: `${instanceUrl}/_my_redirect/${window.redirect.redirect}${params}`;
const redirectUrl = getRedirectUrl(instanceUrl, params);

const openLink = document.querySelector(".open-link") as HTMLElement;
openLink.outerHTML = `
Expand Down
Loading