उत्पादकता की दृष्टि से लुमेन टेबा: हम एक स्मार्ट बल्ब के लिए अपना आवेदन लिखते हैं

छवि , «» , - . OpenWrt GPIO ( ). , .

«» , . . LuMini. , , «» , , .

, LuMini . iOS, , . , reverse-engineering Android-. - , Java-, . apk . apk Google Play, . . , , Node.js, «» . , . , — .

छविछवि

.
1. . .
2. .
3. (, ). .
4. , , .

. . OS X Swift’e, . , .

OS X Swift, , -, . , «» : . ( ). .

छवि

— Swift Objective-C.
— , AppleScript.
— , ?
— , .
— , , , Safari.
— (). .
— , .

.

tell application "System Events" to set frontApp to name of first process whose frontmost is true

if (frontApp = "Safari") then
    using terms from application "Safari"
        tell application frontApp to set currentTabUrl to URL of front document
        tell application frontApp to set currentTabTitle to name of front document
    end using terms from
else if (frontApp = "Google Chrome") then
    using terms from application "Google Chrome"
        tell application frontApp to set currentTabUrl to URL of active tab of front window
        tell application frontApp to set currentTabTitle to title of active tab of front window
    end using terms from
else if (frontApp = "Lumen Taba") then
    return 1
else
    return
end if

return currentTabUrl


background’e .

//run tracker in background mode
let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
    while !self.needStop {
        self.isRunning = true
        var error: NSDictionary?
        
        //run script
        if let scriptObject = NSAppleScript(source: self.scriptText!) {
            if let output: NSAppleEventDescriptor = scriptObject.executeAndReturnError(
                &error) {
                //if browser is active
                if output.stringValue != nil {
                    
                    //this app is active
                    if (output.int32Value == 1) {
                        continue
                    }
                    
                    //if bad url
                    if self.urlValidator.isUrlStringBanned(output.stringValue!) {
                        
                        //bad url isn't changed
                        if self.lastBadUrl == output.stringValue {
                            continue
                        }
                        
                        self.lastBadUrl = output.stringValue
                        NSNotificationCenter.defaultCenter().postNotificationName("BadUrlIsOpened",
                            object: self.lastBadUrl)
                        continue
                    }
                    
                }
                
                
                //the browser is not active
                //turn off lamp if it was on
                if self.lastBadUrl != nil {
                    self.lastBadUrl = nil
                    NSNotificationCenter.defaultCenter().postNotificationName("BadUrlIsClosed", object: nil)
                }

            } else if (error != nil) {
                print("error")
            }
        }
        sleep(self.CHECK_INTERVAL)
    }
    
    self.isRunning = false
})
छवि
Swift.

url . - regex . . , , - ( vk.com Google). , :

private func checkUrl(url: NSURL) -> Bool {
    let domain = url.host
    
    //there is no domain
    if (domain == nil) {
        return false
    }
    
    let badRegexes = getBadRegexes()
    for br in badRegexes {
        if matchesForRegexInText(br, text: url.absoluteString) {
            return true
        }
    }
    
    return false
}

private func matchesForRegexInText(regex: String!, text: String!) -> Bool {
    do {
        let regex = try NSRegularExpression(pattern: regex, options: [])
        let nsString = text as NSString
        let results = regex.matchesInString(text,
                                            options: [],
                                            range: NSMakeRange(0, nsString.length))
        return results.count > 0 ? true : false
        
    } catch let error as NSError {
        print("invalid regex: \(error.localizedDescription)")
        return false
    }
}


, .

छवि
छवि



, .

, , : goo.gl/ppnr6z.

14 , , « Lumen» 10%- , GEEKT-UL.

Source: https://habr.com/ru/post/hi396195/


All Articles