addons/isl/src/platform/androidStudioPlatform.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {Platform} from '../platform';
b69ab319import type {ThemeColor} from '../theme';
b69ab3110import type {OneIndexedLineNumber, RepoRelativePath} from '../types';
b69ab3111
b69ab3112import {makeBrowserLikePlatformImpl} from './browserPlatformImpl';
b69ab3113
b69ab3114declare global {
b69ab3115 interface Window {
b69ab3116 __IdeBridge: {
b69ab3117 openFileInAndroidStudio: (path: string, line?: number, col?: number) => void;
b69ab3118 clipboardCopy?: (data: string) => void;
b69ab3119 getIDETheme(): ThemeColor;
b69ab3120 };
b69ab3121 }
b69ab3122}
b69ab3123
b69ab3124// important: this file should not try to import other code from 'isl',
b69ab3125// since it will end up getting duplicated when bundling.
b69ab3126
b69ab3127const androidStudioPlatform: Platform = {
b69ab3128 ...makeBrowserLikePlatformImpl('androidStudio'),
b69ab3129
b69ab3130 confirm: (message: string, details?: string) => {
b69ab3131 // TODO: Android Studio-style confirm modal
b69ab3132 const ok = window.confirm(message + '\n' + (details ?? ''));
b69ab3133 return Promise.resolve(ok);
b69ab3134 },
b69ab3135
b69ab3136 openFile: (_path: RepoRelativePath, _options?: {line?: OneIndexedLineNumber}) => {
b69ab3137 window.__IdeBridge.openFileInAndroidStudio(_path, _options?.line);
b69ab3138 },
b69ab3139 openFiles: (paths: Array<RepoRelativePath>, _options?: {line?: OneIndexedLineNumber}) => {
b69ab3140 for (const path of paths) {
b69ab3141 window.__IdeBridge.openFileInAndroidStudio(path, _options?.line);
b69ab3142 }
b69ab3143 },
b69ab3144 canCustomizeFileOpener: false,
b69ab3145 upsellExternalMergeTool: false,
b69ab3146
b69ab3147 openExternalLink(_url: string): void {
b69ab3148 window.open(_url, '_blank');
b69ab3149 },
b69ab3150
b69ab3151 clipboardCopy(text: string, _html?: string) {
b69ab3152 window.__IdeBridge.clipboardCopy?.(text);
b69ab3153 },
b69ab3154
b69ab3155 theme: {
b69ab3156 getTheme(): ThemeColor {
b69ab3157 return 'dark'; // default to dark, IDE will adjust the theme if necessary
b69ab3158 },
b69ab3159 onDidChangeTheme(callback: (theme: ThemeColor) => unknown) {
b69ab3160 const updateTheme = (data: CustomEvent<ThemeColor>) => {
b69ab3161 callback(data.detail);
b69ab3162 };
b69ab3163
b69ab3164 window.addEventListener('onIDEThemeChange', updateTheme as EventListener, false);
b69ab3165
b69ab3166 return {
b69ab3167 dispose: () => {
b69ab3168 window.removeEventListener('onIDEThemeChange', updateTheme as EventListener, false);
b69ab3169 },
b69ab3170 };
b69ab3171 },
b69ab3172 },
b69ab3173};
b69ab3174
b69ab3175window.islPlatform = androidStudioPlatform;
b69ab3176
b69ab3177// Load the actual app entry, which must be done after the platform has been set up.
b69ab3178import('../index');