@ -69,7 +69,7 @@ Ext.define('Rambox.view.main.MainController', {
Ext . getCmp ( 'tab_' + e . record . get ( 'id' ) ) . setTitle ( e . record . get ( 'name' ) ) ;
Ext . getCmp ( 'tab_' + e . record . get ( 'id' ) ) . setTitle ( e . record . get ( 'name' ) ) ;
}
}
, onEnableDisableService : function ( cc , rowIndex , checked ) {
, onEnableDisableService : function ( cc , rowIndex , checked , obj , hideTab ) {
var rec = Ext . getStore ( 'Services' ) . getAt ( rowIndex ) ;
var rec = Ext . getStore ( 'Services' ) . getAt ( rowIndex ) ;
if ( ! checked ) {
if ( ! checked ) {
@ -87,6 +87,7 @@ Ext.define('Rambox.view.main.MainController', {
, displayTabUnreadCounter : rec . get ( 'displayTabUnreadCounter' )
, displayTabUnreadCounter : rec . get ( 'displayTabUnreadCounter' )
, enabled : rec . get ( 'enabled' )
, enabled : rec . get ( 'enabled' )
, record : rec
, record : rec
, hidden : hideTab
, tabConfig : {
, tabConfig : {
service : rec
service : rec
}
}
@ -100,32 +101,60 @@ Ext.define('Rambox.view.main.MainController', {
} ) ;
} ) ;
}
}
, removeServiceFn : function ( serviceId ) {
, removeServiceFn : function ( serviceId , total , actual ) {
var me = this ;
if ( ! serviceId ) return false ;
if ( ! serviceId ) return false ;
// Get Tab
var tab = Ext . getCmp ( 'tab_' + serviceId ) ;
// Get Record
// Get Record
var rec = Ext . getStore ( 'Services' ) . getById ( serviceId ) ;
var rec = Ext . getStore ( 'Services' ) . getById ( serviceId ) ;
if ( ! rec . get ( 'enabled' ) ) {
rec . set ( 'enabled' , true ) ;
me . onEnableDisableService ( null , Ext . getStore ( 'Services' ) . indexOf ( rec ) , true , null , true ) ;
Ext . defer ( function ( ) {
// Get Tab
var tab = Ext . getCmp ( 'tab_' + serviceId ) ;
// Clear all trash data
const webview = tab . getWebView ( ) ;
webview . addEventListener ( "did-finish-load" , function ( ) {
clearData ( webview , tab ) ;
} ) ;
} , 1000 ) ;
} else {
// Get Tab
var tab = Ext . getCmp ( 'tab_' + serviceId ) ;
// Clear all trash data
// Clear all trash data
if ( rec . get ( 'enabled' ) && tab . down ( 'component' ) . el ) {
const webview = tab . getWebView ( ) ;
tab . down ( 'component' ) . el . dom . getWebContents ( ) . session . clearCache ( Ext . emptyFn ) ;
clearData ( webview , tab ) ;
tab . down ( 'component' ) . el . dom . getWebContents ( ) . session . clearStorageData ( { } , Ext . emptyFn ) ;
}
}
function clearData ( webview , tab ) {
webview . getWebContents ( ) . clearHistory ( ) ;
webview . getWebContents ( ) . session . flushStorageData ( ) ;
webview . getWebContents ( ) . session . clearCache ( function ( ) {
webview . getWebContents ( ) . session . clearStorageData ( function ( ) {
webview . getWebContents ( ) . session . cookies . flushStore ( function ( ) {
// Remove record from localStorage
// Remove record from localStorage
Ext . getStore ( 'Services' ) . remove ( rec ) ;
Ext . getStore ( 'Services' ) . remove ( rec ) ;
// Close tab
// Close tab
tab . close ( ) ;
tab . close ( ) ;
// Close waiting message
if ( total === actual ) Ext . Msg . hide ( ) ;
} ) ;
} ) ;
} ) ;
}
}
}
, removeService : function ( gridView , rowIndex , colIndex , col , e , rec , rowEl ) {
, removeService : function ( gridView , rowIndex , colIndex , col , e , rec , rowEl ) {
var me = this ;
var me = this ;
Ext . Msg . confirm ( locale [ 'app.window[12]' ] , locale [ 'app.window[13]' ] + ' <b>' + rec . get ( 'name' ) + '</b>?' , function ( btnId ) {
Ext . Msg . confirm ( locale [ 'app.window[12]' ] , locale [ 'app.window[13]' ] + ' <b>' + rec . get ( 'name' ) + '</b>?' , function ( btnId ) {
if ( btnId === 'yes' ) me . removeServiceFn ( rec . get ( 'id' ) ) ;
if ( btnId === 'yes' ) {
Ext . Msg . wait ( 'Please wait until we clear all.' , 'Removing...' ) ;
me . removeServiceFn ( rec . get ( 'id' ) , 1 , 1 ) ;
}
} ) ;
} ) ;
}
}
@ -140,8 +169,11 @@ Ext.define('Rambox.view.main.MainController', {
if ( btnId === 'yes' ) {
if ( btnId === 'yes' ) {
Ext . cq1 ( 'app-main' ) . suspendEvent ( 'remove' ) ;
Ext . cq1 ( 'app-main' ) . suspendEvent ( 'remove' ) ;
Ext . getStore ( 'Services' ) . load ( ) ;
Ext . getStore ( 'Services' ) . load ( ) ;
Ext . Msg . wait ( 'Please wait until we clear all.' , 'Removing...' ) ;
const count = Ext . getStore ( 'Services' ) . getCount ( ) ;
var i = 1 ;
Ext . Array . each ( Ext . getStore ( 'Services' ) . collect ( 'id' ) , function ( serviceId ) {
Ext . Array . each ( Ext . getStore ( 'Services' ) . collect ( 'id' ) , function ( serviceId ) {
me . removeServiceFn ( serviceId ) ;
me . removeServiceFn ( serviceId , count , i ++ ) ;
} ) ;
} ) ;
if ( Ext . isFunction ( callback ) ) callback ( ) ;
if ( Ext . isFunction ( callback ) ) callback ( ) ;
Ext . cq1 ( 'app-main' ) . resumeEvent ( 'remove' ) ;
Ext . cq1 ( 'app-main' ) . resumeEvent ( 'remove' ) ;
@ -152,7 +184,7 @@ Ext.define('Rambox.view.main.MainController', {
Ext . cq1 ( 'app-main' ) . suspendEvent ( 'remove' ) ;
Ext . cq1 ( 'app-main' ) . suspendEvent ( 'remove' ) ;
Ext . getStore ( 'Services' ) . load ( ) ;
Ext . getStore ( 'Services' ) . load ( ) ;
Ext . Array . each ( Ext . getStore ( 'Services' ) . collect ( 'id' ) , function ( serviceId ) {
Ext . Array . each ( Ext . getStore ( 'Services' ) . collect ( 'id' ) , function ( serviceId ) {
me . removeServiceFn ( serviceId ) ;
me . removeServiceFn ( serviceId , 1 , 2 ) ;
} ) ;
} ) ;
if ( Ext . isFunction ( callback ) ) callback ( ) ;
if ( Ext . isFunction ( callback ) ) callback ( ) ;
Ext . cq1 ( 'app-main' ) . resumeEvent ( 'remove' ) ;
Ext . cq1 ( 'app-main' ) . resumeEvent ( 'remove' ) ;