-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a module to handle deep links following the documentation (#1198)
- Loading branch information
Showing
2 changed files
with
48 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import querystring from 'querystring'; | ||
import url from 'url'; | ||
import { getMainWindow } from './mainWindow'; | ||
|
||
|
||
const normalizeUrl = (hostUrl) => { | ||
if (!/^https?:\/\//.test(hostUrl)) { | ||
return `https://${ hostUrl }`; | ||
} | ||
|
||
return hostUrl; | ||
}; | ||
|
||
const processAuth = async ({ host, token, userId }) => { | ||
const mainWindow = await getMainWindow(); | ||
const hostUrl = normalizeUrl(host); | ||
mainWindow.send('add-host', hostUrl, { token, userId }); | ||
}; | ||
|
||
const processRoom = async ({ host, rid, path }) => { | ||
const mainWindow = await getMainWindow(); | ||
const hostUrl = normalizeUrl(host); | ||
mainWindow.send('add-host', hostUrl); | ||
mainWindow.send('open-room', hostUrl, { rid, path }); | ||
}; | ||
|
||
export const processDeepLink = (link) => { | ||
const { protocol, hostname: action, query } = url.parse(link); | ||
|
||
if (protocol !== 'rocketchat:') { | ||
return; | ||
} | ||
|
||
switch (action) { | ||
case 'auth': { | ||
processAuth(querystring.parse(query)); | ||
break; | ||
} | ||
case 'room': { | ||
processRoom(querystring.parse(query)); | ||
break; | ||
} | ||
} | ||
}; |