Resources/js/d/main.js
changeset 1 b3419d05eabb
parent 0 80c32ef237c6
equal deleted inserted replaced
0:80c32ef237c6 1:b3419d05eabb
       
     1 
       
     2 // Initialization.
       
     3 D.init();
       
     4 
     1 
     5 
     2 $( window ).ready( function() {
     6 $( window ).ready( function() {
     3 	if ( D.getBoolPref('fullscreen') ) D.window.main.setFullscreen( true );
       
     4 
     7 
     5 	// If we're in development mode, just display the main window,
     8 	// FIXME: screwin around
     6 	// the inpector, and stop here.
     9 	var updateIdle = function() {
       
    10 		var idlesecs = Math.round( Ti.UI.getIdleTime() / 1000 );
       
    11 		Ti.UI.setBadge( idlesecs.toString() );
       
    12 		D.delay( updateIdle, 1000, true );
       
    13 	};
       
    14 	updateIdle();
       
    15 
       
    16 	// FIXME: more screwin around
       
    17 	$( '.thing' ).contextmenu( function( event ) {
       
    18 		var menu = Ti.UI.createMenu();
       
    19 		var val = $(this).data( 'value' );
       
    20 
       
    21 		menu.addItem( 'Whoa!', function() {
       
    22 			console.log( "This seems to have worked: " + val );
       
    23 		});
       
    24 
       
    25 		D.window.main.setContextMenu( menu );
       
    26 		event.stopPropagation();
       
    27 	});
       
    28 
       
    29 	$( '.save' ).click( function() {
       
    30 		var canvas = $( '#draw' )[0];
       
    31 		var img = canvas.toDataURL( "image/png" ).replace( 'data:image/png;base64,', '' );
       
    32 		img = window.atob( img );
       
    33 
       
    34 		D.window.main.openSaveAsDialog( function( path ) {
       
    35 			if ( path.length != 1 ) return;
       
    36 
       
    37 			var file = Ti.Filesystem.getFileStream( path[0] );
       
    38 			file.open( Ti.Filesystem.MODE_WRITE, true, false );
       
    39 			file.write( img );
       
    40 			file.close();
       
    41 
       
    42 			Processing.getInstanceById( 'draw' ).setup();
       
    43 		},
       
    44 		{
       
    45 			title: "Save image..",
       
    46 			path:  Ti.Filesystem.getDesktopDirectory().toString(),
       
    47 			types: [ 'png' ],
       
    48 			defaultFile: 'image.png'
       
    49 		});
       
    50 	});
       
    51 
       
    52 
       
    53 	// If we're in development mode, automatically display the inspector.
       
    54 	if ( D.devmode() ) D.window.main.showInspector( true );
       
    55 
       
    56 	// Make sure we're able to talk to the remote server.
     7 	//
    57 	//
     8 	if ( D.getBoolPref('devmode') ) {
    58 	var remoteCheck = function() {
     9 		D.window.main.showInspector( true );
    59 		if ( D.tf.version ) return;  // all is well
    10 		return;
    60 
       
    61 		// URI configured, but unable to get the version.
       
    62 		//
       
    63 		if ( D.tf.uri ) {
       
    64 			D.notify( 'Offline', 'Unable to talk to the Thingfish server!' );
       
    65 		}
       
    66 
       
    67 		// No URI configured.
       
    68 		//
       
    69 		else {
       
    70 			D.window.prefs = D.window.main.createWindow( 'app://window/prefs.html#server' );
       
    71 			D.window.prefs.open();
       
    72 			D.notify( 'Configuration needed.', 'Please point me to a Thingfish server URI!' );
       
    73 		}
       
    74 	};
       
    75 
       
    76 	// Skip the splash screen.
       
    77 	//
       
    78 	if ( D.getBoolPref('hidesplash') ) {
       
    79 		if ( D.getBoolPref('remember_window') ) D.setWindowState();
       
    80 		remoteCheck();
    11 	}
    81 	}
    12 
    82 
    13 	// "Regular" behavior.  Hide the main window, show splash.
    83 	// "Regular" behavior.  Hide the main window, show splash
       
    84 	// before continuing.
    14 	//
    85 	//
    15 	if ( ! D.getBoolPref('hidesplash') ) {
    86 	else {
    16 		D.window.main.hide();
    87 		D.window.main.hide();
    17 		D.window.splash = D.window.main.createWindow( 'app://window/splash.html' );
    88 		D.window.splash = D.window.main.createWindow( 'app://window/splash.html' );
    18 		D.window.splash.setTopMost( true );
    89 		D.window.splash.setTopMost( true );
    19 		D.window.splash.open();
    90 		D.window.splash.open();
       
    91 
       
    92 		// Show the main window after a few moments.
       
    93 		//
       
    94 		D.delay(function() {
       
    95 			D.window.splash.close();
       
    96 			D.window.main.show();
       
    97 			if ( D.getBoolPref('remember_window') ) D.setWindowState();
       
    98 			remoteCheck();
       
    99 		}, 3000, true );
    20 	}
   100 	}
    21 
       
    22 	var server_uri = D.getPref( 'server_uri' );
       
    23 	if ( server_uri ) D.checkServer( server_uri );
       
    24 
       
    25 
       
    26 	// Show the main window after a few moments.
       
    27 	//
       
    28 	D.delay(function() {
       
    29 		if ( ! D.getBoolPref('hidesplash') ) {
       
    30 			D.window.main.show();
       
    31 			D.window.splash.close();
       
    32 		}
       
    33 
       
    34 		// Throw up the prefs window if this is the first time.
       
    35 		//
       
    36 		if ( D.firstrun ) {
       
    37 			D.window.prefs = D.window.main.createWindow( 'app://window/prefs.html#server' );
       
    38 			D.window.prefs.open();
       
    39 			D.notify( 'Initial setup', 'Please point me to a Thingfish server!' );
       
    40 		}
       
    41 	}, 3000 );
       
    42 });
   101 });
    43 
   102