Browse Source

Improve removing service option

Clearing all cache, storage data, etc. before removing but it keeps a
folder inside the app Partitions folder. This seems to be a "bug" of
Electron.
Related #828
pull/1193/head
Ramiro Saenz 8 years ago
parent
commit
b327f70f93
  1. 8
      app/ux/WebView.js
  2. 66
      app/view/main/MainController.js

8
app/ux/WebView.js

@ -658,4 +658,12 @@ Ext.define('Rambox.ux.WebView',{
me.record.set('zoomLevel', me.zoomLevel); me.record.set('zoomLevel', me.zoomLevel);
} }
} }
,getWebView: function() {
if ( this.record.get('enabled') ) {
return this.down('component').el.dom;
} else {
return false;
}
}
}); });

66
app/view/main/MainController.js

@ -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,8 +87,9 @@ 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);
// Clear all trash data if ( !rec.get('enabled') ) {
if ( rec.get('enabled') && tab.down('component').el ) { rec.set('enabled', true);
tab.down('component').el.dom.getWebContents().session.clearCache(Ext.emptyFn); me.onEnableDisableService(null, Ext.getStore('Services').indexOf(rec), true, null, true);
tab.down('component').el.dom.getWebContents().session.clearStorageData({}, Ext.emptyFn); 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
const webview = tab.getWebView();
clearData(webview, tab);
} }
// Remove record from localStorage function clearData(webview, tab) {
Ext.getStore('Services').remove(rec); webview.getWebContents().clearHistory();
webview.getWebContents().session.flushStorageData();
// Close tab webview.getWebContents().session.clearCache(function() {
tab.close(); webview.getWebContents().session.clearStorageData(function() {
webview.getWebContents().session.cookies.flushStore(function() {
// Remove record from localStorage
Ext.getStore('Services').remove(rec);
// Close tab
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');

Loading…
Cancel
Save