Skip to content
This repository was archived by the owner on Feb 18, 2026. It is now read-only.
Open
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
6 changes: 6 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
22 changes: 22 additions & 0 deletions android/app/src/main/java/org/lichess/mobileapp/LiIntent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.lichess.mobileapp;

import android.content.Intent;

import com.getcapacitor.JSObject;
import com.getcapacitor.NativePlugin;
import com.getcapacitor.Plugin;

@NativePlugin()
public class LiIntent extends Plugin {
@Override
protected void handleOnNewIntent(Intent intent) {
String action = intent.getAction();
String text = intent.getStringExtra(Intent.EXTRA_TEXT);

if (Intent.ACTION_SEND.equals(action) && text != null) {
JSObject obj = new JSObject();
obj.put("pgn", text);
notifyListeners("importPGN", obj, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PatternMatcher;
import android.util.Log;
import android.webkit.WebView;

import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Dialogs;
import com.getcapacitor.Plugin;
import com.getcapacitor.community.keepawake.KeepAwake;
import com.getcapacitor.plugin.Storage;

import org.lichess.plugin.SoundEffect;
import org.lichess.mobileapp.stockfish.Stockfish;
Expand All @@ -41,6 +39,7 @@ public void onCreate(Bundle savedInstanceState) {
// Initializes the Bridge
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
// Additional plugins you've installed go here
add(LiIntent.class);
add(LiToast.class);
add(LiShare.class);
add(LiBuildConfig.class);
Expand Down
9 changes: 9 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import push from './push'
import router from './router'
import socket from './socket'
import sound from './sound'
import * as utils from './utils'
import { isForeground, setForeground, setBackground } from './utils/appMode'
import { ImportEvent } from './ui/importer/importer'

let firstConnection = true

Expand Down Expand Up @@ -88,6 +90,13 @@ export default function appInit(

Plugins.App.addListener('backButton', router.backbutton)

Plugins.LiIntent.addListener('importPGN', (e: ImportEvent) => {
const params: Record<string, string> = {
pgn: e.pgn,
}
router.set(`/importer?${utils.serializeQueryParameters(params)}`)
})

window.addEventListener('resize', debounce(onResize), false)
}

Expand Down
6 changes: 5 additions & 1 deletion src/ui/importer/ImporterCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import { OnlineGameData } from '../../lichess/interfaces/game'
export interface IImporterCtrl {
importGame(pgn: string): void
importing: Prop<boolean>
pgn: Prop<string | null>
}

export default function ImporterCtrl(): IImporterCtrl {

const importing = prop(false)

const pgn = prop<string | null>(null)

function submitOnline(pgn: string, analyse: boolean): Promise<OnlineGameData> {
const data: {[i: string]: string } = { pgn }
if (analyse) data.analyse = '1'
Expand Down Expand Up @@ -45,6 +48,7 @@ export default function ImporterCtrl(): IImporterCtrl {
handleXhrError(err)
})
},
importing
importing,
pgn
}
}
21 changes: 15 additions & 6 deletions src/ui/importer/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ interface State {
ctrl: IImporterCtrl
}

const ImporterScreen: Mithril.Component<Record<string, never>, State> = {
oninit() {
export interface ImportEvent {
pgn: string
}

const ImporterScreen: Mithril.Component<ImportEvent, State> = {
oninit(vnode) {
socket.createDefault()
this.ctrl = ImporterCtrl()
this.ctrl.pgn(vnode.attrs.pgn)
},

oncreate: helper.viewFadeIn,
Expand All @@ -35,13 +40,17 @@ function renderBody(ctrl: IImporterCtrl) {
h('form', {
onsubmit: (e: Event) => {
e.preventDefault()
const target = e.target as HTMLFormElement
const pgn: string = (target[0] as HTMLInputElement).value
if (pgn) ctrl.importGame(pgn)
if (ctrl.pgn()) ctrl.importGame(ctrl.pgn()!)
}
}, [
h('label', i18n('pasteThePgnStringHere') + ' :'),
h('textarea.pgnImport'),
h('textarea.pgnImport', {
value: ctrl.pgn(),
onchange(e: Event) {
const target = e.target as HTMLTextAreaElement
ctrl.pgn(target.value)
}
}),
formWidgets.renderCheckbox(i18n('requestAComputerAnalysis'), 'analyse', settings.importer.analyse),
h('button.fatButton', ctrl.importing() ?
h('div.fa.fa-hourglass-half') : i18n('importGame'))
Expand Down