mirror of
https://github.com/lxsang/antos-frontend.git
synced 2025-04-07 17:16:44 +02:00
working on VFS binding of Google drive
This commit is contained in:
parent
67b934d7fb
commit
79138f4198
1
Makefile
1
Makefile
@ -6,6 +6,7 @@ NC=\033[0m
|
|||||||
|
|
||||||
coffees= src/core/core.coffee\
|
coffees= src/core/core.coffee\
|
||||||
src/core/api.coffee\
|
src/core/api.coffee\
|
||||||
|
src/core/settings.coffee\
|
||||||
src/core/handlers/RemoteHandler.coffee\
|
src/core/handlers/RemoteHandler.coffee\
|
||||||
src/core/vfs.coffee\
|
src/core/vfs.coffee\
|
||||||
src/core/vfs/GoogleDriveHandler.coffee\
|
src/core/vfs/GoogleDriveHandler.coffee\
|
||||||
|
@ -156,9 +156,20 @@ self.OS.API =
|
|||||||
path = "resources/#{r}"
|
path = "resources/#{r}"
|
||||||
_API.get path, c, f
|
_API.get path, c, f
|
||||||
|
|
||||||
|
libready: (l) ->
|
||||||
|
return _API.shared[l] || false
|
||||||
|
|
||||||
require: (l,f) ->
|
require: (l,f) ->
|
||||||
path = "os:///scripts/"
|
|
||||||
if not _API.shared[l]
|
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 = "#{path}#{l}.js"
|
||||||
js.asFileHandler().onready (d) ->
|
js.asFileHandler().onready (d) ->
|
||||||
_API.shared[l] = true
|
_API.shared[l] = true
|
||||||
|
@ -352,30 +352,8 @@ self.OS.GUI =
|
|||||||
# clean up things
|
# clean up things
|
||||||
_OS.cleanup()
|
_OS.cleanup()
|
||||||
# get setting from conf
|
# get setting from conf
|
||||||
_OS.setting.desktop = conf.desktop if conf.desktop
|
_OS.systemSetting(conf)
|
||||||
_OS.setting.applications = conf.applications if conf.applications
|
console.log _OS.setting
|
||||||
_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
|
|
||||||
# load theme
|
# load theme
|
||||||
_GUI.loadTheme _OS.setting.appearance.theme
|
_GUI.loadTheme _OS.setting.appearance.theme
|
||||||
# initDM
|
# initDM
|
||||||
|
33
src/core/settings.coffee
Normal file
33
src/core/settings.coffee
Normal 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
|
@ -1,6 +1,68 @@
|
|||||||
|
|
||||||
# GoogleDrive File Handler
|
# GoogleDrive File Handler
|
||||||
class GoogleDriveHandler extends this.OS.API.VFS.BaseFileHandler
|
class GoogleDriveHandler extends this.OS.API.VFS.BaseFileHandler
|
||||||
constructor: (path) ->
|
constructor: (path) ->
|
||||||
super 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
|
self.OS.API.VFS.register "^gdv$", GoogleDriveHandler
|
@ -65,6 +65,18 @@ class Files extends this.OS.GUI.BaseApplication
|
|||||||
@applySetting()
|
@applySetting()
|
||||||
@subscribe "VFS", (d) ->
|
@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()
|
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
|
@chdir null
|
||||||
|
|
||||||
applySetting: (k) ->
|
applySetting: (k) ->
|
||||||
@ -98,14 +110,14 @@ class Files extends this.OS.GUI.BaseApplication
|
|||||||
arr = {
|
arr = {
|
||||||
text: "File",
|
text: "File",
|
||||||
child: [
|
child: [
|
||||||
{ text: "New file", dataid: "#{@name}-mkf" },
|
{ text: "New file", dataid: "#{@name}-mkf", shortcut: 'C-F' },
|
||||||
{ text: "New folder", dataid: "#{@name}-mkdir" },
|
{ text: "New folder", dataid: "#{@name}-mkdir", shortcut: 'C-D' },
|
||||||
{ text: "Open with", dataid: "#{@name}-open", child:@apps },
|
{ 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: "Download", dataid: "#{@name}-download" },
|
||||||
{ text: "Share file", dataid: "#{@name}-share" },
|
{ text: "Share file", dataid: "#{@name}-share", shortcut: 'C-S' },
|
||||||
{ text: "Properties", dataid: "#{@name}-info" }
|
{ text: "Properties", dataid: "#{@name}-info", shortcut: 'C-I' }
|
||||||
], onmenuselect: (e) -> me.actionFile e
|
], onmenuselect: (e) -> me.actionFile e.item.data.dataid
|
||||||
}
|
}
|
||||||
return arr
|
return arr
|
||||||
mnEdit: () ->
|
mnEdit: () ->
|
||||||
@ -113,12 +125,12 @@ class Files extends this.OS.GUI.BaseApplication
|
|||||||
{
|
{
|
||||||
text: "Edit",
|
text: "Edit",
|
||||||
child: [
|
child: [
|
||||||
{ text: "Rename", dataid: "#{@name}-mv" },
|
{ text: "Rename", dataid: "#{@name}-mv", shortcut: 'C-R' },
|
||||||
{ text: "Delete", dataid: "#{@name}-rm" },
|
{ text: "Delete", dataid: "#{@name}-rm", shortcut: 'C-M' },
|
||||||
{ text: "Cut", dataid: "#{@name}-cut" },
|
{ text: "Cut", dataid: "#{@name}-cut", shortcut: 'C-X' },
|
||||||
{ text: "Copy", dataid: "#{@name}-copy" },
|
{ text: "Copy", dataid: "#{@name}-copy", shortcut: 'C-C' },
|
||||||
{ text: "Paste", dataid: "#{@name}-paste" }
|
{ text: "Paste", dataid: "#{@name}-paste", shortcut: 'C-P' }
|
||||||
], onmenuselect: (e) -> me.actionEdit e
|
], onmenuselect: (e) -> me.actionEdit e.item.data.dataid
|
||||||
}
|
}
|
||||||
menu: () ->
|
menu: () ->
|
||||||
me = @
|
me = @
|
||||||
@ -173,7 +185,7 @@ class Files extends this.OS.GUI.BaseApplication
|
|||||||
actionEdit: (e) ->
|
actionEdit: (e) ->
|
||||||
me = @
|
me = @
|
||||||
file = @view.get "selectedFile"
|
file = @view.get "selectedFile"
|
||||||
switch e.item.data.dataid
|
switch e
|
||||||
when "#{@name}-mv"
|
when "#{@name}-mv"
|
||||||
return unless file
|
return unless file
|
||||||
@openDialog "PromptDialog",
|
@openDialog "PromptDialog",
|
||||||
@ -226,7 +238,7 @@ class Files extends this.OS.GUI.BaseApplication
|
|||||||
actionFile: (e) ->
|
actionFile: (e) ->
|
||||||
me = @
|
me = @
|
||||||
file = @view.get "selectedFile"
|
file = @view.get "selectedFile"
|
||||||
switch e.item.data.dataid
|
switch e
|
||||||
|
|
||||||
when "#{@name}-mkdir"
|
when "#{@name}-mkdir"
|
||||||
@openDialog "PromptDialog",
|
@openDialog "PromptDialog",
|
||||||
|
@ -44,6 +44,9 @@ class MarkOn extends this.OS.GUI.BaseApplication
|
|||||||
me.currfile.dirty = true
|
me.currfile.dirty = true
|
||||||
me.scheme.set "apptitle", "#{me.currfile.basename}*"
|
me.scheme.set "apptitle", "#{me.currfile.basename}*"
|
||||||
@on "hboxchange", (e) -> me.resizeContent()
|
@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()
|
@resizeContent()
|
||||||
@open @currfile
|
@open @currfile
|
||||||
|
|
||||||
@ -80,11 +83,11 @@ class MarkOn extends this.OS.GUI.BaseApplication
|
|||||||
menu = [{
|
menu = [{
|
||||||
text: "File",
|
text: "File",
|
||||||
child: [
|
child: [
|
||||||
{ text: "Open", dataid: "#{@name}-Open" },
|
{ text: "Open", dataid: "#{@name}-Open", shortcut: "A-O" },
|
||||||
{ text: "Save", dataid: "#{@name}-Save" },
|
{ text: "Save", dataid: "#{@name}-Save", shortcut: "C-S" },
|
||||||
{ text: "Save as", dataid: "#{@name}-Saveas" }
|
{ text: "Save as", dataid: "#{@name}-Saveas", shortcut: "A-W" }
|
||||||
],
|
],
|
||||||
onmenuselect: (e) -> me.actionFile e
|
onmenuselect: (e) -> me.actionFile e.item.data.dataid
|
||||||
}]
|
}]
|
||||||
menu
|
menu
|
||||||
|
|
||||||
@ -95,7 +98,7 @@ class MarkOn extends this.OS.GUI.BaseApplication
|
|||||||
me.currfile.setPath "#{d}/#{n}"
|
me.currfile.setPath "#{d}/#{n}"
|
||||||
me.save me.currfile
|
me.save me.currfile
|
||||||
, "Save as", { file: me.currfile }
|
, "Save as", { file: me.currfile }
|
||||||
switch e.item.data.dataid
|
switch e
|
||||||
when "#{@name}-Open"
|
when "#{@name}-Open"
|
||||||
@openDialog "FileDiaLog", ( d, f ) ->
|
@openDialog "FileDiaLog", ( d, f ) ->
|
||||||
me.open "#{d}/#{f}".asFileHandler()
|
me.open "#{d}/#{f}".asFileHandler()
|
||||||
|
@ -106,7 +106,7 @@ class NotePad extends this.OS.GUI.BaseApplication
|
|||||||
#@tabarea.set "closable", true
|
#@tabarea.set "closable", true
|
||||||
@bindKey "ALT-O", () -> me.actionFile "#{me.name}-Open"
|
@bindKey "ALT-O", () -> me.actionFile "#{me.name}-Open"
|
||||||
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save"
|
@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 @currfile
|
||||||
|
|
||||||
open: (file) ->
|
open: (file) ->
|
||||||
@ -245,7 +245,7 @@ class NotePad extends this.OS.GUI.BaseApplication
|
|||||||
child: [
|
child: [
|
||||||
{ text: "Open", dataid: "#{@name}-Open", shortcut: "A-O" },
|
{ text: "Open", dataid: "#{@name}-Open", shortcut: "A-O" },
|
||||||
{ text: "Save", dataid: "#{@name}-Save", shortcut: "C-S" },
|
{ 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
|
onmenuselect: (e) -> me.actionFile e.item.data.dataid
|
||||||
}]
|
}]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user