Toby Chui 1 тиждень тому
батько
коміт
e1d296475c
3 змінених файлів з 32 додано та 3 видалено
  1. 2 1
      src/agi.go
  2. 3 2
      src/mod/agi/agi.go
  3. 27 0
      src/mod/agi/agi.system.go

+ 2 - 1
src/agi.go

@@ -19,7 +19,8 @@ func AGIInit() {
 		InternalVersion:      internal_version,
 		LoadedModule:         moduleHandler.GetModuleNameList(),
 		ReservedTables:       []string{"auth", "permisson", "register", "desktop"},
-		ModuleRegisterParser: moduleHandler.RegisterModuleFromAGI,
+		ModuleRegisterParser:  moduleHandler.RegisterModuleFromAGI,
+		ExtIconRegisterParser: moduleHandler.RegisterExtIcon,
 		ModuleListProvider:   moduleHandler.GetModuleListJSONForUser,
 		PackageManager:       packageManager,
 		Logger:               systemWideLogger,

+ 3 - 2
src/mod/agi/agi.go

@@ -63,8 +63,9 @@ type AgiSysInfo struct {
 	UserHandler          *user.UserHandler
 	ReservedTables       []string
 	PackageManager       *apt.AptPackageManager
-	ModuleRegisterParser func(string) error
-	ModuleListProvider   func(username string) string //Returns JSON of accessible modules for a user
+	ModuleRegisterParser  func(string) error
+	ModuleListProvider    func(username string) string //Returns JSON of accessible modules for a user
+	ExtIconRegisterParser func(ext, iconPath string)   //Called when registerExtensionIcon() fires in an init.agi
 	FileSystemRender     *metadata.RenderHandler
 	IotManager           *iot.Manager
 	ShareManager         *share.Manager

+ 27 - 0
src/mod/agi/agi.system.go

@@ -316,6 +316,33 @@ func (g *Gateway) injectStandardLibs(vm *otto.Otto, scriptFile string, scriptSco
 		return otto.Value{}
 	})
 
+	// registerExtensionIcon(ext, iconPath) — lets init.agi scripts publish a
+	// per-extension fallback icon shown by the file manager when no thumbnail
+	// can be generated (e.g. for proprietary formats like ".pxs").
+	// iconPath may be relative to the module directory (e.g. "./img/file.png").
+	vm.Set("registerExtensionIcon", func(call otto.FunctionCall) otto.Value {
+		ext, err := call.Argument(0).ToString()
+		if err != nil || ext == "" {
+			return otto.FalseValue()
+		}
+		iconPath, err := call.Argument(1).ToString()
+		if err != nil || iconPath == "" {
+			return otto.FalseValue()
+		}
+
+		if scriptFile != "" && scriptScope != "" {
+			moduleDir := static.GetScriptRoot(scriptFile, scriptScope)
+			if !filepath.IsAbs(iconPath) && !strings.HasPrefix(iconPath, moduleDir+"/") {
+				iconPath = filepath.ToSlash(filepath.Join(moduleDir, iconPath))
+			}
+		}
+
+		if g.Option.ExtIconRegisterParser != nil {
+			g.Option.ExtIconRegisterParser(ext, iconPath)
+		}
+		return otto.TrueValue()
+	})
+
 	//Package Executation. Only usable when called to a given script File.
 	if scriptFile != "" && scriptScope != "" {
 		//Package request --> Install linux package if not exists