From b35096bccaac993049b69e6254be9ab0295f5176 Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Sun, 4 Mar 2018 12:35:19 +0100 Subject: [PATCH] logout google account when user sign out --- src/core/core.coffee | 11 +++++++++- src/core/gui.coffee | 2 +- src/core/handlers/RemoteHandler.coffee | 11 +++++----- src/core/vfs/GoogleDriveHandler.coffee | 21 ++++++++++++++++++-- src/packages/CoreServices/UserService.coffee | 2 +- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/core/core.coffee b/src/core/core.coffee index ca409f0..5bdc637 100644 --- a/src/core/core.coffee +++ b/src/core/core.coffee @@ -117,4 +117,13 @@ self.OS or= _GUI.login() else # startX :) - _GUI.startAntOS d.result \ No newline at end of file + _GUI.startAntOS d.result + + cleanupHandlers: {} + exit: -> + #do clean up first + f() for n, f of _OS.cleanupHandlers + _API.handler.setting () -> + _API.handler.logout() + onexit: (n, f) -> + self.OS.cleanupHandlers[n] = f unless self.OS.cleanupHandlers[n] \ No newline at end of file diff --git a/src/core/gui.coffee b/src/core/gui.coffee index 2c86d03..23712ed 100644 --- a/src/core/gui.coffee +++ b/src/core/gui.coffee @@ -334,7 +334,7 @@ self.OS.GUI = dataid: "sys-logout", iconclass: "fa fa-user-times" menu.onmenuselect = (d) -> - return _API.handler.logout() if d.item.data.dataid is "sys-logout" + return _OS.exit() if d.item.data.dataid is "sys-logout" return _GUI.toggleFullscreen() if d.item.data.dataid is "os-fullsize" _GUI.launch d.item.data.app unless d.item.data.dataid diff --git a/src/core/handlers/RemoteHandler.coffee b/src/core/handlers/RemoteHandler.coffee index 34dae2e..9cfeacf 100644 --- a/src/core/handlers/RemoteHandler.coffee +++ b/src/core/handlers/RemoteHandler.coffee @@ -72,12 +72,11 @@ self.OS.API.handler = _API.post p, d, c, () -> alert "Resource not found: #{p}" logout: () -> - _API.handler.setting () -> - p = "#{_REST}/system/logout" - _API.post p, {}, (d) -> - _OS.boot() - , () -> - alert "Resource not found #{p}" + p = "#{_REST}/system/logout" + _API.post p, {}, (d) -> + _OS.boot() + , () -> + alert "Resource not found #{p}" setting: (f) -> p = "#{_REST}/system/settings" _API.post p, _OS.setting, (d) -> diff --git a/src/core/vfs/GoogleDriveHandler.coffee b/src/core/vfs/GoogleDriveHandler.coffee index 54edf34..2c77f44 100644 --- a/src/core/vfs/GoogleDriveHandler.coffee +++ b/src/core/vfs/GoogleDriveHandler.coffee @@ -43,7 +43,7 @@ class GoogleDriveHandler extends this.OS.API.VFS.BaseFileHandler _GUI.openDialog "YesNoDialog", (d) -> return _courrier.osinfo "User abort the authentification" unless d fn(gapi.auth2.getAuthInstance().isSignedIn.get()) - , "Authentification", { text: "Do you want to login to Google Drive ?" } + , "Authentification", { text: "Would you like to login to Google Drive ?" } .catch (err) -> _API.loaded q, "FAIL" _courrier.oserror "VFS cannot init GAPI: #{err.error}", (_API.throwe "OS.VFS"), err @@ -316,4 +316,21 @@ self.OS.API.onsearch "Google Drive", (t) -> file.complex = true file.detail = [{ text: file.path }] arr.push file - return arr \ No newline at end of file + return arr + +self.OS.onexit "cleanUpGoogleDrive", () -> + G_CACHE = { "gdv:///": { id: "root", mime: 'dir' } } + return unless _OS.setting.VFS.gdrive and _API.libready _OS.setting.VFS.gdrive.apilink + auth2 = gapi.auth2.getAuthInstance() + return unless auth2 + if auth2.isSignedIn.get() + el = $ '