Files F2: Convert android_app_list_model to TS
Bug: b:289003444
Change-Id: I431baf9e5e52747ecc40f33d07b15287f8688ee1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5086348
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Reviewed-by: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1233220}
diff --git a/ui/file_manager/file_manager/foreground/js/android_app_list_model.js b/ui/file_manager/file_manager/foreground/js/android_app_list_model.js
deleted file mode 100644
index feffc2f7..0000000
--- a/ui/file_manager/file_manager/foreground/js/android_app_list_model.js
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2019 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-import {NativeEventTarget as EventTarget} from 'chrome://resources/ash/common/event_target.js';
-
-import {addAndroidApps} from '../../state/ducks/android_apps.js';
-import {getStore} from '../../state/store.js';
-
-/**
- * Model for managing a list of Android apps.
- */
-export class AndroidAppListModel extends EventTarget {
- /**
- * @param {boolean} showAndroidPickerApps Whether to show picker apps in file
- * selector.
- * @param {boolean} includeAllFiles Corresponds to LaunchParam.includeAllFiles
- * @param {!Array<!Object>} typeList Corresponds to LaunchParam.typeList
- */
- constructor(showAndroidPickerApps, includeAllFiles, typeList) {
- super();
-
- /** @private @type {!Array<!chrome.fileManagerPrivate.AndroidApp>} */
- this.apps_ = [];
-
- if (!showAndroidPickerApps) {
- return;
- }
-
- // @ts-ignore: error TS7034: Variable 'extensions' implicitly has type
- // 'any[]' in some locations where its type cannot be determined.
- let extensions = [];
- if (!includeAllFiles) {
- for (let i = 0; i < typeList.length; i++) {
- // @ts-ignore: error TS2339: Property 'extensions' does not exist on
- // type 'Object'.
- extensions = extensions.concat(typeList[i].extensions);
- }
- }
-
- chrome.fileManagerPrivate.getAndroidPickerApps(extensions, apps => {
- this.apps_ = apps;
- getStore().dispatch(addAndroidApps({apps}));
- this.dispatchEvent(new CustomEvent('permuted'));
- });
- }
-
- /**
- * @return {number} Number of picker apps.
- */
- length() {
- return this.apps_.length;
- }
-
- /**
- * @param {number} index Index of the picker app to be retrieved.
- * @return {chrome.fileManagerPrivate.AndroidApp} The value of the |index|-th
- * picker app.
- */
- item(index) {
- // @ts-ignore: error TS2322: Type 'AndroidApp | undefined' is not assignable
- // to type 'AndroidApp'.
- return this.apps_[index];
- }
-}
diff --git a/ui/file_manager/file_manager/foreground/js/android_app_list_model.ts b/ui/file_manager/file_manager/foreground/js/android_app_list_model.ts
new file mode 100644
index 0000000..6de2f05
--- /dev/null
+++ b/ui/file_manager/file_manager/foreground/js/android_app_list_model.ts
@@ -0,0 +1,60 @@
+// Copyright 2019 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import {NativeEventTarget as EventTarget} from 'chrome://resources/ash/common/event_target.js';
+
+import type {TypeList} from '../../common/js/files_app_state.js';
+import {addAndroidApps} from '../../state/ducks/android_apps.js';
+import {getStore} from '../../state/store.js';
+
+/**
+ * Model for managing a list of Android apps.
+ */
+export class AndroidAppListModel extends EventTarget {
+ private apps_: chrome.fileManagerPrivate.AndroidApp[] = [];
+ /**
+ * @param showAndroidPickerApps Whether to show picker apps in file
+ * selector.
+ * @param includeAllFiles Corresponds to LaunchParam.includeAllFiles
+ * @param typeList Corresponds to LaunchParam.typeList
+ */
+ constructor(
+ showAndroidPickerApps: boolean, includeAllFiles: boolean,
+ typeList: TypeList[]) {
+ super();
+
+ if (!showAndroidPickerApps) {
+ return;
+ }
+
+ let extensions: string[] = [];
+ if (!includeAllFiles) {
+ for (const type of typeList) {
+ extensions = extensions.concat(type.extensions);
+ }
+ }
+
+ chrome.fileManagerPrivate.getAndroidPickerApps(extensions, apps => {
+ this.apps_ = apps;
+ getStore().dispatch(addAndroidApps({apps}));
+ this.dispatchEvent(new CustomEvent('permuted'));
+ });
+ }
+
+ /**
+ * @return Number of picker apps.
+ */
+ length(): number {
+ return this.apps_.length;
+ }
+
+ /**
+ * @param index Index of the picker app to be retrieved.
+ * @return The value of the |index|-th
+ * picker app.
+ */
+ item(index: number): chrome.fileManagerPrivate.AndroidApp|undefined {
+ return this.apps_[index];
+ }
+}
diff --git a/ui/file_manager/file_manager/foreground/js/navigation_list_model.js b/ui/file_manager/file_manager/foreground/js/navigation_list_model.js
index edc7e5a..84cc104 100644
--- a/ui/file_manager/file_manager/foreground/js/navigation_list_model.js
+++ b/ui/file_manager/file_manager/foreground/js/navigation_list_model.js
@@ -347,7 +347,9 @@
this.androidAppList_ = [];
for (let i = 0; i < this.androidAppListModel_.length(); i++) {
- this.androidAppList_.push(this.androidAppListModel_.item(i));
+ this.androidAppList_.push(
+ /** @type {chrome.fileManagerPrivate.AndroidApp} */ (
+ this.androidAppListModel_.item(i)));
}
// Reorder volumes, shortcuts, and optional items for initial display.
diff --git a/ui/file_manager/file_names.gni b/ui/file_manager/file_names.gni
index a41fdaa..cfae43a 100644
--- a/ui/file_manager/file_names.gni
+++ b/ui/file_manager/file_names.gni
@@ -40,7 +40,6 @@
"file_manager/externs/ts/store.js",
# Files app Foreground:
- "file_manager/foreground/js/android_app_list_model.js",
"file_manager/foreground/js/app_state_controller.js",
"file_manager/foreground/js/constants.js",
"file_manager/foreground/js/crostini_controller.js",
@@ -287,6 +286,7 @@
# Foreground.
"file_manager/foreground/js/actions_model.ts",
"file_manager/foreground/js/actions_controller.ts",
+ "file_manager/foreground/js/android_app_list_model.ts",
"file_manager/foreground/js/banner_controller.ts",
"file_manager/foreground/js/crossover_search_utils.ts",
"file_manager/foreground/js/dialog_action_controller.ts",