2023-05-23 18:53:53 +00:00
import { safeRun } from "../common/util.ts" ;
2023-07-14 14:56:20 +00:00
import { Client } from "./client.ts" ;
2022-10-10 12:50:21 +00:00
2023-08-28 15:12:15 +00:00
const thinClientMode = ! ! localStorage . getItem ( "thinClientMode" ) ;
2022-10-10 12:50:21 +00:00
safeRun ( async ( ) = > {
2023-07-14 14:56:20 +00:00
console . log ( "Booting SilverBullet..." ) ;
2022-10-10 12:50:21 +00:00
2023-07-14 14:56:20 +00:00
const client = new Client (
2022-10-10 12:50:21 +00:00
document . getElementById ( "sb-root" ) ! ,
2023-08-26 06:31:51 +00:00
thinClientMode ,
2022-10-10 12:50:21 +00:00
) ;
2023-07-14 14:56:20 +00:00
await client . init ( ) ;
window . client = client ;
2022-10-10 12:50:21 +00:00
} ) ;
if ( navigator . serviceWorker ) {
navigator . serviceWorker
2022-11-24 11:04:00 +00:00
. register ( new URL ( "/service_worker.js" , location . href ) , {
2022-10-10 12:50:21 +00:00
type : "module" ,
} )
2022-11-24 15:55:30 +00:00
. then ( ( ) = > {
2022-10-10 12:50:21 +00:00
console . log ( "Service worker registered..." ) ;
} ) ;
2023-08-26 06:31:51 +00:00
if ( ! thinClientMode ) {
navigator . serviceWorker . ready . then ( ( registration ) = > {
registration . active ! . postMessage ( {
type : "config" ,
config : window.silverBulletConfig ,
} ) ;
2023-05-23 18:53:53 +00:00
} ) ;
2023-08-26 06:31:51 +00:00
}
2022-10-10 12:50:21 +00:00
} else {
2023-05-23 18:53:53 +00:00
console . warn (
"Not launching service worker, likely because not running from localhost or over HTTPs. This means SilverBullet will not be available offline." ,
2022-10-10 12:50:21 +00:00
) ;
}
2023-05-24 03:42:24 +00:00
if ( ! globalThis . indexedDB ) {
alert (
"SilverBullet requires IndexedDB to operate and it is not available in your browser. Please use a recent version of Chrome, Firefox (not in private mode) or Safari." ,
) ;
}