                                                 fileNameWithoutAfterDot, false, false, false
     atom.notifications.addInfo "#{daemonName} added"
 
+  isLinuxDistribution: (name,callback) -> #other better solution?
+    command = "uname"
+    args = ["-v"]
+    alreadyGetCheckString = false
+    stdout = (output) ->
+      if output.indexOf(name) >- 1
+        alreadyGetCheckString = true
+    exit = (code) ->
+      callback() if alreadyGetCheckString
+    process = new BufferedProcess({command, args, stdout, exit})
+
+class ScanDaemons #extends this
+  name : ""   #replace
+  init : null # replace
+
+  constructor: (@scanDaemons) ->
+    @init()
+    @info()
+
+  startScan: (dirUrl,re) -> #run this
+    dir = new Directory(dirUrl)
+    @scanForFile dir, re if dir.isDirectory()
+  scanForFile = (dir,re) ->
+    dir.getEntries (err,entries) =>
+      for entrie in entries
+        if not entrie.isDirectory()
+          result = re.exec entrie.getBaseName()
+          if result != null
+            @regNewDaemon entrie, result[1]
+        else @scanForFile entrie #scan subfolder
+
+  regNewDaemon = (file,fileNameWithoutAfterDot) => #TODO: change format
+    @scanDeamons.addDaemon file.getParent().getBaseName(), file.path, fileNameWithoutAfterDot
+
+  info : ->
+    atom.notifications.addInfo "Scan #{@name} Daemons"
+#Scan Class for (Debian)/Ubuntu
+class ScanDaemonsUbuntu extends ScanDaemons
+  name: "Brew"
+  init: ->
+    @startScan "/usr/local/opt/", /^([\w\.]+)\.plist$/
+
 #Scan Class for Brew
-class ScanDaemonsBrew
-  constructor: (@scanDeamons) ->
-    dir = new Directory('/usr/local/opt/')
-    if dir.isDirectory()
-      atom.notifications.addInfo "Scan Brew like Daemons"
-      @searchPlist dir
-
-  searchPlist: (dir) ->
-    re = /^([\w\.]+)\.plist$/
-    searchPlist = (dir) =>
-      dir.getEntries (err,entries) =>
-        for entrie in entries
-          if entrie.isDirectory()
-            searchPlist entrie
-          else
-            result = re.exec(entrie.getBaseName())
-            if result != null
-              regNewPlist entrie, result[1]
-
-    regNewPlist = (file,fileNameWithoutAfterDot) =>
-      @scanDeamons.addDaemon file.getParent().getBaseName(), file.path, fileNameWithoutAfterDot
-    searchPlist dir
+class ScanDaemonsBrew extends ScanDaemons
+  name: "Brew"
+  init: ->
+    @startScan "/usr/local/opt/", /^([\w\.]+)\.plist$/

{Directory} = require 'atom'
DaemonItem = require "./daemon-item"

module.exports =
class ScanDeamons

    @defineScanFunction()

  defineScanFunction: ->
    if process.platform == "darwin" #mac
      @scanFunction = ScanDaemonsBrew
    else if /^linux/.test(process.platform) #linux
      @isLinuxDistribution "Ubuntu", =>
        @scanFunction = ScanDaemonsUbuntu
    #else if /^win/.test(process.platform) #win
      #atom.notifications.addInfo "There is no scan algorithm for your #{process.platform} platform, plaese add this!"
      #atom.notifications.addInfo "Add manual daemons with CMD+SHIFT+P -> Smart Daemon Control: New Daemon"
      #@daemonManagement.newDaemon()

  run: ->
    if @scanFunction?
      new @scanFunction(this)
    else
      #console.log process
      atom.notifications.addInfo "There is no scan-algorithm for your OS #{process.platform} right now."

  thereIsScanDaemonForOs: ->
    if @scanFunction == null
