working on VFS binding of Google drive

This commit is contained in:
Xuan Sang LE 2018-02-27 16:40:36 +01:00
parent 67b934d7fb
commit 79138f4198
9 changed files with 161 additions and 61 deletions

View File

@ -6,6 +6,7 @@ NC=\033[0m
coffees= src/core/core.coffee\
src/core/api.coffee\
src/core/settings.coffee\
src/core/handlers/RemoteHandler.coffee\
src/core/vfs.coffee\
src/core/vfs/GoogleDriveHandler.coffee\

View File

@ -156,9 +156,20 @@ self.OS.API =
path = "resources/#{r}"
_API.get path, c, f
libready: (l) ->
return _API.shared[l] || false
require: (l,f) ->
path = "os:///scripts/"
if not _API.shared[l]
if l.match /^(https?:\/\/[^\s]+)/g
_API.script l, () ->
_API.shared[l] = true
_courrier.trigger "sharedlibraryloaded", l
f() if f
, (e, s) ->
_courrier.oserror "Cannot load 3rd library at: #{l}", e, r
else
path = "os:///scripts/"
js = "#{path}#{l}.js"
js.asFileHandler().onready (d) ->
_API.shared[l] = true

View File

@ -352,30 +352,8 @@ self.OS.GUI =
# clean up things
_OS.cleanup()
# get setting from conf
_OS.setting.desktop = conf.desktop if conf.desktop
_OS.setting.applications = conf.applications if conf.applications
_OS.setting.appearance = conf.appearance if conf.appearance
_OS.setting.user = conf.user
_OS.setting.VFS = conf.VFS if conf.VFS
_OS.setting.desktop.path = "home:///.desktop" unless _OS.setting.desktop.path
_OS.setting.desktop.menu = {} unless _OS.setting.desktop.menu
_OS.setting.VFS.mountpoints = [
#TODO: multi app try to write to this object, it neet to be cloned
{ text: "Applications", path: 'app:///', iconclass: "fa fa-adn", type: "app" },
{ text: "Home", path: 'home:///', iconclass: "fa fa-home", type: "fs" },
{ text: "OS", path: 'os:///', iconclass: "fa fa-inbox", type: "fs" },
{ text: "Desktop", path: _OS.setting.desktop.path , iconclass: "fa fa-desktop", type: "fs" },
{ text: "Shared", path: 'shared:///' , iconclass: "fa fa-share-square", type: "fs" }
] if not _OS.setting.VFS.mountpoints
_OS.setting.system = conf.system if conf.system
_OS.setting.system.pkgpaths = [
"home:///.packages",
"os:///packages"
] unless _OS.setting.system.pkgpaths
_OS.setting.system.menu = {} unless _OS.setting.system.menu
_OS.setting.system.repositories = [] unless _OS.setting.system.repositories
_OS.setting.appearance.theme = "antos" unless _OS.setting.appearance.theme
_OS.systemSetting(conf)
console.log _OS.setting
# load theme
_GUI.loadTheme _OS.setting.appearance.theme
# initDM

33
src/core/settings.coffee Normal file
View File

@ -0,0 +1,33 @@
self.OS.systemSetting = (conf) ->
_OS.setting.desktop = conf.desktop if conf.desktop
_OS.setting.applications = conf.applications if conf.applications
_OS.setting.appearance = conf.appearance if conf.appearance
_OS.setting.user = conf.user
_OS.setting.VFS = conf.VFS if conf.VFS
_OS.setting.desktop.path = "home:///.desktop" unless _OS.setting.desktop.path
_OS.setting.desktop.menu = {} unless _OS.setting.desktop.menu
_OS.setting.VFS.mountpoints = [
#TODO: multi app try to write to this object, it neet to be cloned
{ text: "Applications", path: 'app:///', iconclass: "fa fa-adn", type: "app" },
{ text: "Home", path: 'home:///', iconclass: "fa fa-home", type: "fs" },
{ text: "OS", path: 'os:///', iconclass: "fa fa-inbox", type: "fs" },
{ text: "Desktop", path: _OS.setting.desktop.path , iconclass: "fa fa-desktop", type: "fs" },
{ text: "Shared", path: 'shared:///' , iconclass: "fa fa-share-square", type: "fs" }
] if not _OS.setting.VFS.mountpoints
_OS.setting.system = conf.system if conf.system
_OS.setting.system.pkgpaths = [
"home:///.packages",
"os:///packages"
] unless _OS.setting.system.pkgpaths
_OS.setting.system.menu = {} unless _OS.setting.system.menu
_OS.setting.system.repositories = [] unless _OS.setting.system.repositories
_OS.setting.appearance.theme = "antos" unless _OS.setting.appearance.theme
_OS.setting.VFS.gdrive = {
CLIENT_ID: "1006507170703-l322pfkrhf9cgta4l4jh2p8ughtc14id.apps.googleusercontent.com"
API_KEY: "AIzaSyBZhM5KbARvT10acWC8JQKlRn2WbSsmfLc"
apilink: "https://apis.google.com/js/api.js"
DISCOVERY_DOCS: ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"]
SCOPES: 'https://www.googleapis.com/auth/drive.metadata.readonly'
} unless _OS.setting.VFS.gdrive

View File

@ -1,6 +1,68 @@
# GoogleDrive File Handler
class GoogleDriveHandler extends this.OS.API.VFS.BaseFileHandler
constructor: (path) ->
super path
me = @
@setting = _OS.setting.VFS.gdrive
return _courrier.oserror "Unknown API setting for google drive VFS", (_API.throwe "OS.VFS"), null unless @setting
@gid = 'root' if @isRoot()
oninit: (f) ->
me = @
return unless @setting
if _API.libready @setting.apilink
f()
else
_API.require @setting.apilink, () ->
gapi.load "client:auth2", () ->
gapi.client.init {
apiKey: me.setting.API_KEY,
clientId: me.setting.CLIENT_ID,
discoveryDocs: me.setting.DISCOVERY_DOCS,
scope: me.setting.SCOPES
}
.then () ->
fn = (r) ->
return f() if r
# perform the login
gapi.auth2.getAuthInstance().signIn()
gapi.auth2.getAuthInstance().isSignedIn.listen (r) ->
fn(r)
fn(gapi.auth2.getAuthInstance().isSignedIn.get())
meta: (f) ->
@oninit () ->
gapi.client.drive.files.list {
q: 'parents = "root" and trashed = false ',
fields: "nextPageToken, files(id, name)"
}
.then (r) ->
console.log(r)
f()
action: (n, p, f) ->
me = @
switch n
when "read"
return
when "mk"
return
when "write"
return
when "upload"
return
when "remove"
return
when "publish"
return
when "download"
return
when "move"
return
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
self.OS.API.VFS.register "^gdv$", GoogleDriveHandler

View File

@ -65,6 +65,18 @@ class Files extends this.OS.GUI.BaseApplication
@applySetting()
@subscribe "VFS", (d) ->
me.chdir null if d.data.file.hash() is me.currdir.hash() or d.data.file.parent().hash() is me.currdir.hash()
@bindKey "CTRL-F", () -> me.actionFile "#{me.name}-mkf"
@bindKey "CTRL-D", () -> me.actionFile "#{me.name}-mkdir"
@bindKey "CTRL-U", () -> me.actionFile "#{me.name}-upload"
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-share"
@bindKey "CTRL-I", () -> me.actionFile "#{me.name}-info"
@bindKey "CTRL-R", () -> me.actionEdit "#{me.name}-mv"
@bindKey "CTRL-M", () -> me.actionEdit "#{me.name}-rm"
@bindKey "CTRL-X", () -> me.actionEdit "#{me.name}-cut"
@bindKey "CTRL-C", () -> me.actionEdit "#{me.name}-copy"
@bindKey "CTRL-P", () -> me.actionEdit "#{me.name}-paste"
@chdir null
applySetting: (k) ->
@ -98,14 +110,14 @@ class Files extends this.OS.GUI.BaseApplication
arr = {
text: "File",
child: [
{ text: "New file", dataid: "#{@name}-mkf" },
{ text: "New folder", dataid: "#{@name}-mkdir" },
{ text: "New file", dataid: "#{@name}-mkf", shortcut: 'C-F' },
{ text: "New folder", dataid: "#{@name}-mkdir", shortcut: 'C-D' },
{ text: "Open with", dataid: "#{@name}-open", child:@apps },
{ text: "Upload", dataid: "#{@name}-upload" },
{ text: "Upload", dataid: "#{@name}-upload", shortcut: 'C-U' },
{ text: "Download", dataid: "#{@name}-download" },
{ text: "Share file", dataid: "#{@name}-share" },
{ text: "Properties", dataid: "#{@name}-info" }
], onmenuselect: (e) -> me.actionFile e
{ text: "Share file", dataid: "#{@name}-share", shortcut: 'C-S' },
{ text: "Properties", dataid: "#{@name}-info", shortcut: 'C-I' }
], onmenuselect: (e) -> me.actionFile e.item.data.dataid
}
return arr
mnEdit: () ->
@ -113,12 +125,12 @@ class Files extends this.OS.GUI.BaseApplication
{
text: "Edit",
child: [
{ text: "Rename", dataid: "#{@name}-mv" },
{ text: "Delete", dataid: "#{@name}-rm" },
{ text: "Cut", dataid: "#{@name}-cut" },
{ text: "Copy", dataid: "#{@name}-copy" },
{ text: "Paste", dataid: "#{@name}-paste" }
], onmenuselect: (e) -> me.actionEdit e
{ text: "Rename", dataid: "#{@name}-mv", shortcut: 'C-R' },
{ text: "Delete", dataid: "#{@name}-rm", shortcut: 'C-M' },
{ text: "Cut", dataid: "#{@name}-cut", shortcut: 'C-X' },
{ text: "Copy", dataid: "#{@name}-copy", shortcut: 'C-C' },
{ text: "Paste", dataid: "#{@name}-paste", shortcut: 'C-P' }
], onmenuselect: (e) -> me.actionEdit e.item.data.dataid
}
menu: () ->
me = @
@ -173,7 +185,7 @@ class Files extends this.OS.GUI.BaseApplication
actionEdit: (e) ->
me = @
file = @view.get "selectedFile"
switch e.item.data.dataid
switch e
when "#{@name}-mv"
return unless file
@openDialog "PromptDialog",
@ -226,7 +238,7 @@ class Files extends this.OS.GUI.BaseApplication
actionFile: (e) ->
me = @
file = @view.get "selectedFile"
switch e.item.data.dataid
switch e
when "#{@name}-mkdir"
@openDialog "PromptDialog",

View File

@ -44,6 +44,9 @@ class MarkOn extends this.OS.GUI.BaseApplication
me.currfile.dirty = true
me.scheme.set "apptitle", "#{me.currfile.basename}*"
@on "hboxchange", (e) -> me.resizeContent()
@bindKey "ALT-O", () -> me.actionFile "#{me.name}-Open"
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save"
@bindKey "ALT-W", () -> me.actionFile "#{me.name}-Saveas"
@resizeContent()
@open @currfile
@ -80,11 +83,11 @@ class MarkOn extends this.OS.GUI.BaseApplication
menu = [{
text: "File",
child: [
{ text: "Open", dataid: "#{@name}-Open" },
{ text: "Save", dataid: "#{@name}-Save" },
{ text: "Save as", dataid: "#{@name}-Saveas" }
{ text: "Open", dataid: "#{@name}-Open", shortcut: "A-O" },
{ text: "Save", dataid: "#{@name}-Save", shortcut: "C-S" },
{ text: "Save as", dataid: "#{@name}-Saveas", shortcut: "A-W" }
],
onmenuselect: (e) -> me.actionFile e
onmenuselect: (e) -> me.actionFile e.item.data.dataid
}]
menu
@ -95,7 +98,7 @@ class MarkOn extends this.OS.GUI.BaseApplication
me.currfile.setPath "#{d}/#{n}"
me.save me.currfile
, "Save as", { file: me.currfile }
switch e.item.data.dataid
switch e
when "#{@name}-Open"
@openDialog "FileDiaLog", ( d, f ) ->
me.open "#{d}/#{f}".asFileHandler()

View File

@ -106,7 +106,7 @@ class NotePad extends this.OS.GUI.BaseApplication
#@tabarea.set "closable", true
@bindKey "ALT-O", () -> me.actionFile "#{me.name}-Open"
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save"
@bindKey "META-S", () -> me.actionFile "#{me.name}-Saveas"
@bindKey "ALT-W", () -> me.actionFile "#{me.name}-Saveas"
@open @currfile
open: (file) ->
@ -245,7 +245,7 @@ class NotePad extends this.OS.GUI.BaseApplication
child: [
{ text: "Open", dataid: "#{@name}-Open", shortcut: "A-O" },
{ text: "Save", dataid: "#{@name}-Save", shortcut: "C-S" },
{ text: "Save as", dataid: "#{@name}-Saveas", shortcut: "M-S" }
{ text: "Save as", dataid: "#{@name}-Saveas", shortcut: "A-W" }
],
onmenuselect: (e) -> me.actionFile e.item.data.dataid
}]