2023-02-12 20:30:38 +00:00
{
const storage = require ( "Storage" ) ;
let settings = storage . readJSON ( "quicklaunch.json" , true ) || { } ;
let reset = function ( name ) {
if ( ! settings [ name ] ) settings [ name ] = { "name" : "(none)" } ;
if ( ! storage . read ( settings [ name ] . src ) ) settings [ name ] = { "name" : "(none)" } ;
storage . write ( "quicklaunch.json" , settings ) ;
} ;
2023-03-12 00:11:07 +00:00
let leaveTrace = function ( trace ) {
2023-03-18 11:14:23 +00:00
if ( settings [ trace + "app" ] . name != "" ) {
settings . trace = trace ;
storage . writeJSON ( "quicklaunch.json" , settings ) ;
} else { trace = trace . substring ( 0 , trace . length - 1 ) ; }
2023-03-12 00:11:07 +00:00
return trace ;
} ;
2023-03-14 17:48:21 +00:00
let launchApp = function ( trace ) {
2023-03-18 11:14:23 +00:00
if ( settings [ trace + "app" ] ) {
if ( settings [ trace + "app" ] . src ) {
if ( settings [ trace + "app" ] . name == "Show Launcher" ) Bangle . showLauncher ( ) ; else if ( ! storage . read ( settings [ trace + "app" ] . src ) ) reset ( trace + "app" ) ; else load ( settings [ trace + "app" ] . src ) ;
}
2023-03-14 17:48:21 +00:00
}
2023-03-18 11:14:23 +00:00
} ;
2023-03-14 17:48:21 +00:00
2023-03-31 20:16:17 +00:00
let trace = ( settings [ settings . trace + "app" ] . src == "quicklaunch.app.js" ) ? settings . trace : settings . trace . substring ( 0 , settings . trace . length - 1 ) ; // If the stored trace leads beyond extension screens, walk back to the last extension screen. Compatibility with "Fastload Utils" App History feature.
2023-03-12 00:11:07 +00:00
2023-02-12 20:30:38 +00:00
let touchHandler = ( _ , e ) => {
2023-03-13 20:33:56 +00:00
if ( e . type == 2 ) return ;
2023-02-12 20:30:38 +00:00
let R = Bangle . appRect ;
if ( e . x < R . x || e . x > R . x2 || e . y < R . y || e . y > R . y2 ) return ;
2023-03-12 20:23:19 +00:00
trace = leaveTrace ( trace + "t" ) ; // t=tap.
2023-03-14 17:48:21 +00:00
launchApp ( trace ) ;
2023-02-12 20:30:38 +00:00
} ;
let swipeHandler = ( lr , ud ) => {
2023-03-12 00:11:07 +00:00
if ( lr == - 1 ) trace = leaveTrace ( trace + "l" ) ; // l=left,
if ( lr == 1 ) trace = leaveTrace ( trace + "r" ) ; // r=right,
if ( ud == - 1 ) trace = leaveTrace ( trace + "u" ) ; // u=up,
if ( ud == 1 ) trace = leaveTrace ( trace + "d" ) ; // d=down.
2023-03-14 17:48:21 +00:00
launchApp ( trace ) ;
2023-03-13 20:33:56 +00:00
} ;
let onLongTouchDoPause = ( e ) => {
if ( e . b == 1 && timeoutToClock ) { clearTimeout ( timeoutToClock ) ; timeoutToClock = false ; }
if ( e . b == 0 && ! timeoutToClock ) updateTimeoutToClock ( ) ;
2023-02-12 20:30:38 +00:00
} ;
Bangle . setUI ( {
2023-03-09 18:56:23 +00:00
mode : "custom" ,
2023-02-12 20:30:38 +00:00
touch : touchHandler ,
swipe : swipeHandler ,
2023-03-13 20:33:56 +00:00
drag : onLongTouchDoPause ,
2023-03-11 00:10:31 +00:00
remove : ( ) => { if ( timeoutToClock ) clearTimeout ( timeoutToClock ) ; } // Compatibility with Fastload Utils.
2023-02-12 20:30:38 +00:00
} ) ;
2023-02-13 19:59:57 +00:00
g . clearRect ( Bangle . appRect ) ;
2023-03-12 20:23:19 +00:00
"Bangle.loadWidgets()" ; // Hack: Fool Fastload Utils that we call Bangle.loadWidgets(). This way we get the fastest possibe loading in whichever environment we find ourselves.
2023-02-13 20:56:52 +00:00
// taken from Icon Launcher with some alterations
let timeoutToClock ;
const updateTimeoutToClock = function ( ) {
2023-03-12 10:25:42 +00:00
let time = 1500 ; // milliseconds
2023-02-13 20:56:52 +00:00
if ( timeoutToClock ) clearTimeout ( timeoutToClock ) ;
2023-03-09 18:56:23 +00:00
timeoutToClock = setTimeout ( load , time ) ;
2023-02-13 20:56:52 +00:00
} ;
updateTimeoutToClock ( ) ;
2023-03-12 10:25:42 +00:00
2023-03-09 18:56:23 +00:00
let R = Bangle . appRect ;
2023-03-12 10:25:42 +00:00
2023-03-11 00:10:31 +00:00
// Draw app hints
2023-03-09 18:56:23 +00:00
g . setFont ( "Vector" , 11 )
2023-03-12 11:22:02 +00:00
. setFontAlign ( 0 , 1 , 3 ) . drawString ( settings [ trace + "lapp" ] . name , R . x2 , R . y + R . h / 2 )
. setFontAlign ( 0 , 1 , 1 ) . drawString ( settings [ trace + "rapp" ] . name , R . x , R . y + R . h / 2 )
. setFontAlign ( 0 , 1 , 0 ) . drawString ( settings [ trace + "uapp" ] . name , R . x + R . w / 2 , R . y2 )
. setFontAlign ( 0 , - 1 , 0 ) . drawString ( settings [ trace + "dapp" ] . name , R . x + R . w / 2 , R . y )
. setFontAlign ( 0 , 0 , 0 ) . drawString ( settings [ trace + "tapp" ] . name , R . x + R . w / 2 , R . y + R . h / 2 ) ;
2023-02-12 20:30:38 +00:00
}