Support tg:// deeplinks in Electron (#3807)
This commit is contained in:
parent
c59d468c73
commit
b806423831
@ -394,6 +394,12 @@ const Main: FC<OwnProps & StateProps> = ({
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return window.electron?.on(ElectronEvent.DEEPLINK, (link: string) => {
|
||||||
|
processDeepLink(decodeURIComponent(link));
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const parsedLocationHash = parseLocationHash();
|
const parsedLocationHash = parseLocationHash();
|
||||||
if (!parsedLocationHash) return;
|
if (!parsedLocationHash) return;
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
productName: "Telegram A"
|
productName: Telegram A
|
||||||
artifactName: "${productName}-${arch}.${ext}"
|
artifactName: ${productName}-${arch}.${ext}
|
||||||
appId: "org.telegram.TelegramA"
|
appId: org.telegram.TelegramA
|
||||||
extraMetadata:
|
extraMetadata:
|
||||||
main: "./dist/electron.js"
|
main: ./dist/electron.js
|
||||||
productName: "Telegram A"
|
productName: Telegram A
|
||||||
files:
|
files:
|
||||||
- "dist"
|
- "dist"
|
||||||
- "package.json"
|
- "package.json"
|
||||||
@ -14,40 +14,47 @@ files:
|
|||||||
- "!dist/get"
|
- "!dist/get"
|
||||||
- "!node_modules"
|
- "!node_modules"
|
||||||
directories:
|
directories:
|
||||||
buildResources: "./public"
|
buildResources: ./public
|
||||||
output: "./dist-electron"
|
output: ./dist-electron
|
||||||
|
protocols:
|
||||||
|
- name: Tg
|
||||||
|
schemes:
|
||||||
|
- tg
|
||||||
publish:
|
publish:
|
||||||
provider: "github"
|
provider: github
|
||||||
owner: "Ajaxy"
|
owner: Ajaxy
|
||||||
repo: "telegram-tt"
|
repo: telegram-tt
|
||||||
releaseType: "draft"
|
releaseType: draft
|
||||||
win:
|
win:
|
||||||
target: "nsis"
|
target: nsis
|
||||||
icon: "public/icon-electron-windows.ico"
|
icon: public/icon-electron-windows.ico
|
||||||
nsis:
|
nsis:
|
||||||
oneClick: false
|
oneClick: false
|
||||||
createDesktopShortcut: true
|
createDesktopShortcut: true
|
||||||
createStartMenuShortcut: true
|
createStartMenuShortcut: true
|
||||||
mac:
|
mac:
|
||||||
target:
|
target:
|
||||||
target: "default"
|
target: default
|
||||||
arch: ["x64", "arm64"]
|
arch:
|
||||||
entitlements: "public/electron-entitlements.mac.plist"
|
- x64
|
||||||
icon: "public/icon-electron-macos.icns"
|
- arm64
|
||||||
|
entitlements: public/electron-entitlements.mac.plist
|
||||||
|
icon: public/icon-electron-macos.icns
|
||||||
notarize:
|
notarize:
|
||||||
teamId: "Y54Z4K69Z9"
|
teamId: Y54Z4K69Z9
|
||||||
dmg:
|
dmg:
|
||||||
title: "Telegram A installer"
|
title: Telegram A installer
|
||||||
background: "public/background-electron-dmg.tiff"
|
background: public/background-electron-dmg.tiff
|
||||||
iconSize: 100
|
iconSize: 100
|
||||||
contents:
|
contents:
|
||||||
- x: 138
|
- x: 138
|
||||||
y: 225
|
y: 225
|
||||||
type: "file"
|
type: file
|
||||||
- x: 402
|
- x: 402
|
||||||
y: 225
|
y: 225
|
||||||
type: "link"
|
type: link
|
||||||
path: "/Applications"
|
path: "/Applications"
|
||||||
linux:
|
linux:
|
||||||
category: "Community"
|
category: Community
|
||||||
target: ["AppImage"]
|
target:
|
||||||
|
- AppImage
|
||||||
|
|||||||
78
src/electron/deeplink.ts
Normal file
78
src/electron/deeplink.ts
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import { app } from 'electron';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
import { ElectronEvent } from '../types/electron';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IS_LINUX, IS_MAC_OS, IS_WINDOWS, windows,
|
||||||
|
} from './utils';
|
||||||
|
|
||||||
|
const TG_PROTOCOL = 'tg';
|
||||||
|
|
||||||
|
let deeplinkUrl: string | undefined;
|
||||||
|
|
||||||
|
export function initDeeplink() {
|
||||||
|
const currentWindow = Array.from(windows).pop();
|
||||||
|
|
||||||
|
if (process.defaultApp) {
|
||||||
|
if (process.argv.length >= 2) {
|
||||||
|
app.setAsDefaultProtocolClient(TG_PROTOCOL, process.execPath, [path.resolve(process.argv[1])]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
app.setAsDefaultProtocolClient(TG_PROTOCOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
const gotTheLock = app.requestSingleInstanceLock();
|
||||||
|
|
||||||
|
if (!gotTheLock) {
|
||||||
|
app.quit();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.on('will-finish-launching', () => {
|
||||||
|
app.on('open-url', (event: Event, url: string) => {
|
||||||
|
event.preventDefault();
|
||||||
|
deeplinkUrl = url;
|
||||||
|
processDeeplink();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (IS_WINDOWS || IS_LINUX) {
|
||||||
|
deeplinkUrl = findDeeplink(process.argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
app.on('second-instance', (_, argv: string[]) => {
|
||||||
|
if (IS_MAC_OS) {
|
||||||
|
deeplinkUrl = argv[0];
|
||||||
|
} else {
|
||||||
|
deeplinkUrl = findDeeplink(argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
processDeeplink();
|
||||||
|
|
||||||
|
if (currentWindow) {
|
||||||
|
if (currentWindow.isMinimized()) {
|
||||||
|
currentWindow.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentWindow.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function processDeeplink() {
|
||||||
|
const currentWindow = Array.from(windows).pop();
|
||||||
|
|
||||||
|
if (!currentWindow || !deeplinkUrl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentWindow.webContents.send(ElectronEvent.DEEPLINK, deeplinkUrl);
|
||||||
|
|
||||||
|
deeplinkUrl = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function findDeeplink(args: string[]) {
|
||||||
|
return args.find((arg) => arg.startsWith(`${TG_PROTOCOL}://`));
|
||||||
|
}
|
||||||
@ -4,9 +4,12 @@ import { app, nativeImage } from 'electron';
|
|||||||
import contextMenu from 'electron-context-menu';
|
import contextMenu from 'electron-context-menu';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
|
import { initDeeplink } from './deeplink';
|
||||||
import { createWindow, setupCloseHandlers, setupElectronActionHandlers } from './window';
|
import { createWindow, setupCloseHandlers, setupElectronActionHandlers } from './window';
|
||||||
import { IS_MAC_OS, IS_WINDOWS } from './utils';
|
import { IS_MAC_OS, IS_WINDOWS } from './utils';
|
||||||
|
|
||||||
|
initDeeplink();
|
||||||
|
|
||||||
contextMenu({
|
contextMenu({
|
||||||
showLearnSpelling: false,
|
showLearnSpelling: false,
|
||||||
showLookUpSelection: false,
|
showLookUpSelection: false,
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import path from 'path';
|
|||||||
import { ElectronAction, ElectronEvent } from '../types/electron';
|
import { ElectronAction, ElectronEvent } from '../types/electron';
|
||||||
import type { TrafficLightPosition } from '../types/electron';
|
import type { TrafficLightPosition } from '../types/electron';
|
||||||
import setupAutoUpdates from './autoUpdates';
|
import setupAutoUpdates from './autoUpdates';
|
||||||
|
import { processDeeplink } from './deeplink';
|
||||||
import {
|
import {
|
||||||
forceQuit, getAppTitle, IS_MAC_OS, TRAFFIC_LIGHT_POSITION, windows,
|
forceQuit, getAppTitle, IS_MAC_OS, TRAFFIC_LIGHT_POSITION, windows,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
@ -123,6 +124,7 @@ export function createWindow(url?: string) {
|
|||||||
|
|
||||||
window.webContents.once('dom-ready', () => {
|
window.webContents.once('dom-ready', () => {
|
||||||
window.show();
|
window.show();
|
||||||
|
processDeeplink();
|
||||||
|
|
||||||
if (process.env.APP_ENV === 'production') {
|
if (process.env.APP_ENV === 'production') {
|
||||||
setupAutoUpdates(window, windowState);
|
setupAutoUpdates(window, windowState);
|
||||||
|
|||||||
@ -2,6 +2,7 @@ export enum ElectronEvent {
|
|||||||
FULLSCREEN_CHANGE = 'fullscreen-change',
|
FULLSCREEN_CHANGE = 'fullscreen-change',
|
||||||
UPDATE_ERROR = 'update-error',
|
UPDATE_ERROR = 'update-error',
|
||||||
UPDATE_DOWNLOADED = 'update-downloaded',
|
UPDATE_DOWNLOADED = 'update-downloaded',
|
||||||
|
DEEPLINK = 'deeplink',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ElectronAction {
|
export enum ElectronAction {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user