var setup_menu = function(type) { if(!menu.btn()) return false; if(!type && data_handler.get('auth', false)) type = 'menu'; switch(type) { case 'menu': // main app menu (usually shown when fully logged in) menu.on_click(function() { menu.open(); }); menu.button().buttons(function(btn) { btn.setAttribute('image', data.url('app/images/favicon.png')); btn.setAttribute('tooltiptext', 'Turtl menu'); }); menu.set_dispatch(function(url) { menu.close(); switch(url) { case 'app': open_app(); break; case 'bookmark': bookmark.open(); break; case 'personas': personas.open(); break; case 'personas-join': personas.open({ force: true, add: true, join: true }); break; case 'invites': invites.open(); break; case 'logout': do_logout(); break; } }); break; case 'login': default: // login menu, shown when logged out menu.on_click(function() { user.open(menu.btn()); }); menu.button().buttons(function(btn) { btn.setAttribute('image', data.url('app/images/favicon.gray.png')); btn.setAttribute('tooltiptext', 'Login/Join'); }); break; } };
var tab_ready = function(tab) { // attach a script which sets/inits specific variables within the // app itself. this is mainly to let the app know it's being loaded // by an extension. var worker = tab.attach({ contentScriptFile: data.url('app_load.js') }); // if tab reloads, reset app tab.on('ready', function(tab) { //pinned = tab.isPinned; worker.destroy(); if(tab.url.match(app_base_url)) { tab.close(); open_app(); } }); // we may need to open the personas interface via the app. it's more // consistent to do it via the background panel than in-app worker.port.on('personas-add-open', function() { personas.open({add: true, force: true}); }); worker.port.on('msglol', function(msg) { console.log('object: ', msg); }); // load that shit, and pass in our auth object. worker.port.emit('do_load', data_handler.get('auth'), data_handler.get('profile'), data.url('app'), config); // give the app tab access to XHR // ...NOOOOOT!!!! //xhr_wrapper.wrap(worker.port); // give the tab direct access to the message passer tab.port = worker.port; };
var monitor_app_tabs = function() { // if we're logged in, no need to close any tabs if(data_handler.get('auth')) return false; var tablist = tab_util.getTabs(); for(var i = 0, n = tablist.length; i < n; i++) { var tab = tablist[i]; var taburl = tab_util.getURI(tab); var tab_base = base_url(taburl); // if we find an open turtl tab, close it if(tab_base == app_base_url) { tab_util.closeTab(tab); } } };
var open_app = function(options) { options || (options = {}); // if we already have an app tab open, activate it and return var tabs = windows.activeWindow.tabs; var app_tab = false; for(var i = 0; i < tabs.length; i++) { var tab = tabs[i]; if(tab.url.match(app_base_url)) { app_tab = tab; break; } } if(app_tab) { app_tab.activate(); return true; } // don't load app unless logged in if(!data_handler.get('auth', false)) return false; var tab_ready = function(tab) { // attach a script which sets/inits specific variables within the // app itself. this is mainly to let the app know it's being loaded // by an extension. var worker = tab.attach({ contentScriptFile: data.url('app_load.js') }); // if tab reloads, reset app tab.on('ready', function(tab) { //pinned = tab.isPinned; worker.destroy(); if(tab.url.match(app_base_url)) { tab.close(); open_app(); } }); // we may need to open the personas interface via the app. it's more // consistent to do it via the background panel than in-app worker.port.on('personas-add-open', function() { personas.open({add: true, force: true}); }); worker.port.on('msglol', function(msg) { console.log('object: ', msg); }); // load that shit, and pass in our auth object. worker.port.emit('do_load', data_handler.get('auth'), data_handler.get('profile'), data.url('app'), config); // give the app tab access to XHR // ...NOOOOOT!!!! //xhr_wrapper.wrap(worker.port); // give the tab direct access to the message passer tab.port = worker.port; }; // open a new tab to the app tabs.open({ // points to our generated index.html, which loads everything url: data.url('index.html'), //isPinned: !!pinned, onReady: tab_ready, isPrivate: private_br.isPrivate(windows.activeWindow) }); };