refactor: circular deps part 8

This commit is contained in:
Nathan Walker
2025-07-08 22:55:03 -07:00
parent 779def7609
commit 50cfd6fb25
12 changed files with 126 additions and 133 deletions

View File

@ -0,0 +1,73 @@
// This file exists to break cycles between debug.ts and file-system.
// Only put logic here that depends on file-system (e.g., knownFolders).
import { knownFolders } from '../file-system';
let applicationRootPath: string;
function ensureAppRootPath() {
if (!applicationRootPath) {
applicationRootPath = knownFolders.currentApp().path;
applicationRootPath = applicationRootPath.substring(0, applicationRootPath.length - 'app/'.length);
}
}
export class Source {
private _uri: string;
private _line: number;
private _column: number;
private static _source = Symbol('source');
constructor(uri: string, line: number, column: number) {
ensureAppRootPath();
if (uri.length > applicationRootPath.length && uri.substring(0, applicationRootPath.length) === applicationRootPath) {
this._uri = 'file://' + uri.substring(applicationRootPath.length);
} else {
this._uri = uri;
}
this._line = line;
this._column = column;
}
get uri(): string {
return this._uri;
}
get line(): number {
return this._line;
}
get column(): number {
return this._column;
}
public toString() {
return this._uri + ':' + this._line + ':' + this._column;
}
public static get(object: any): Source {
return object[Source._source];
}
public static set(object: any, src: Source) {
object[Source._source] = src;
}
}
export class ScopeError extends Error {
constructor(inner: Error, message?: string) {
let formattedMessage;
if (message && inner.message) {
formattedMessage = message + '\n > ' + inner.message.replace('\n', '\n ');
} else {
formattedMessage = message || inner.message || undefined;
}
super(formattedMessage);
this.stack = __ANDROID__ ? 'Error: ' + this.message + '\n' + inner.stack.substr(inner.stack.indexOf('\n') + 1) : inner.stack;
this.message = formattedMessage;
}
}
export class SourceError extends ScopeError {
constructor(child: Error, source: Source, message?: string) {
super(child, message ? message + ' @' + source + '' : source + '');
}
}

View File

@ -1,73 +1,2 @@
import { knownFolders } from '../file-system';
export const debug = true;
let applicationRootPath: string;
function ensureAppRootPath() {
if (!applicationRootPath) {
applicationRootPath = knownFolders.currentApp().path;
applicationRootPath = applicationRootPath.substring(0, applicationRootPath.length - 'app/'.length);
}
}
export class Source {
private _uri: string;
private _line: number;
private _column: number;
private static _source = Symbol('source');
constructor(uri: string, line: number, column: number) {
ensureAppRootPath();
if (uri.length > applicationRootPath.length && uri.substring(0, applicationRootPath.length) === applicationRootPath) {
this._uri = 'file://' + uri.substring(applicationRootPath.length);
} else {
this._uri = uri;
}
this._line = line;
this._column = column;
}
get uri(): string {
return this._uri;
}
get line(): number {
return this._line;
}
get column(): number {
return this._column;
}
public toString() {
return this._uri + ':' + this._line + ':' + this._column;
}
public static get(object: any): Source {
return object[Source._source];
}
public static set(object: any, src: Source) {
object[Source._source] = src;
}
}
export class ScopeError extends Error {
constructor(inner: Error, message?: string) {
let formattedMessage;
if (message && inner.message) {
formattedMessage = message + '\n > ' + inner.message.replace('\n', '\n ');
} else {
formattedMessage = message || inner.message || undefined;
}
super(formattedMessage);
this.stack = __ANDROID__ ? 'Error: ' + this.message + '\n' + inner.stack.substr(inner.stack.indexOf('\n') + 1) : inner.stack;
this.message = formattedMessage;
}
}
export class SourceError extends ScopeError {
constructor(child: Error, source: Source, message?: string) {
super(child, message ? message + ' @' + source + '' : source + '');
}
}
export { Source, ScopeError, SourceError } from './debug-source';

View File

@ -8,7 +8,7 @@ export * from './debug';
export * from './layout-helper';
export * from './macrotask-scheduler';
export * from './mainthread-helper';
export * from './native-helper';
export * from './native-helper'; // do not re-export getWindow here, use ios-helper.ts for that
export * from './types';
export * from './native-helper';

View File

@ -0,0 +1 @@
export { getWindow } from './native-helper';

View File

@ -191,6 +191,10 @@ function getInputMethodManager(): android.view.inputmethod.InputMethodManager {
return inputMethodManager;
}
export function getWindow() {
return getCurrentActivity()?.getWindow();
}
function showSoftInput(nativeView: android.view.View): void {
const inputManager = getInputMethodManager();
if (inputManager && nativeView instanceof android.view.View) {
@ -315,6 +319,7 @@ export const androidUtils = {
getApplication,
getCurrentActivity,
getApplicationContext,
getWindow,
getResources,
getPackageName,
getInputMethodManager,

View File

@ -14,6 +14,8 @@ export function dataDeserialize(nativeData?: any): any;
*/
export function isRealDevice(): boolean;
export function getWindow(): UIWindow | android.view.Window;
// /**
// * Module with android specific utilities.
// */
@ -228,6 +230,7 @@ export const android: {
getApplication: () => android.app.Application;
getCurrentActivity: () => androidx.appcompat.app.AppCompatActivity | android.app.Activity | null;
getApplicationContext: () => android.content.Context;
getWindow: () => android.view.Window;
getResources: () => android.content.res.Resources;
getPackageName: () => string;
getInputMethodManager: () => android.view.inputmethod.InputMethodManager;

View File

@ -173,7 +173,7 @@ function getRootViewController(): UIViewController {
return vc;
}
function getWindow(): UIWindow {
export function getWindow(): UIWindow {
let window: UIWindow;
if (SDK_VERSION >= 15 && typeof NativeScriptViewFactory !== 'undefined') {
// UIWindowScene.keyWindow is only available 15+