99import { createHash } from "crypto" ;
1010import * as fs from "fs-extra" ;
1111import { dirname , extname , join } from "path" ;
12- import { AccessToken , assert , BeEvent , DbResult , Mutable , OpenMode } from "@itwin/core-bentley" ;
12+ import { AccessToken , assert , BeEvent , DbResult , Mutable , OpenMode , ProcessDetector } from "@itwin/core-bentley" ;
1313import { CloudSqliteError , FilePropertyProps , LocalDirName , LocalFileName , WorkspaceError } from "@itwin/core-common" ;
1414import { CloudSqlite } from "../../CloudSqlite" ;
1515import { IModelHost , KnownLocations } from "../../IModelHost" ;
@@ -27,6 +27,7 @@ import { CreateNewWorkspaceContainerArgs, CreateNewWorkspaceDbVersionArgs, Edita
2727import { WorkspaceSqliteDb } from "./WorkspaceSqliteDb" ;
2828import { SettingsImpl } from "./SettingsImpl" ;
2929import { _implementationProhibited , _nativeDb } from "../Symbols" ;
30+ import { getOnlineStatus } from "../OnlineStatus" ;
3031
3132function workspaceDbNameWithDefault ( dbName ?: WorkspaceDbName ) : WorkspaceDbName {
3233 return dbName ?? "workspace-db" ;
@@ -119,6 +120,17 @@ class WorkspaceContainerImpl implements WorkspaceContainer {
119120 // sharedConnect returns true if we just connected (if the container is shared, it may have already been connected)
120121 if ( cloudContainer . sharedConnect ( ) && false !== props . syncOnConnect ) {
121122 try {
123+ if ( ProcessDetector . isMobileAppBackend || ProcessDetector . isElectronAppBackend ) {
124+ // Even though we've already confirmed that we are running in a native app backend,
125+ // having code here that references NativeHost causes a runtime exception. So we use
126+ // getOnlineStatus to determine whether we're online, which NativeHost keeps up to date.
127+ if ( ! getOnlineStatus ( ) ) {
128+ // If running in a native app and we're offline, don't check for changes.
129+ // Doing so will fail and be caught below, but it has to wait for the network
130+ // timeout.
131+ return ;
132+ }
133+ }
122134 cloudContainer . checkForChanges ( ) ;
123135 } catch {
124136 // must be offline
0 commit comments