-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 18ceab1
Showing
16 changed files
with
687 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
client-log.log | ||
.DS_STORE | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/hex" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/murlokswarm/app" | ||
"github.com/sadlil/go-trigger" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
var updemiaUser *Updemia | ||
|
||
type Updemia struct { | ||
Email string | ||
Passphrase string | ||
Hash string | ||
Imgs []UpdemiaImg | ||
} | ||
|
||
type UpdemiaImg struct { | ||
Key string | ||
Url string | ||
Img string | ||
} | ||
|
||
type ImgsResponse struct { | ||
Collection []UpdemiaImg | ||
} | ||
|
||
func (h *Updemia) Render() string { | ||
return ` | ||
<div class="WindowLayout" oncontextmenu="OnContextMenu"> | ||
{{if .Hash}} | ||
<div class="Updemia"> | ||
<img src="http://www.updemia.com/images/logo.png" alt="" /> | ||
<img src="folder.png" alt="" onclick="OnOpenFolder" /> | ||
</div> | ||
<div class="Gravatar"> | ||
<img src="https://www.gravatar.com/avatar/{{html .Hash}}" title="logout" onclick="OnUserLogout" alt="" /> | ||
</div> | ||
<div class=""> | ||
<div class="listMedias"> | ||
{{ range $index, $element := .Imgs }} | ||
<div class="media"> | ||
<a href="{{html .Url}}" target="_blank" style="background-image: url('{{ $element.Img }}');"> </a> | ||
</div> | ||
{{ end }} | ||
</div> | ||
</div> | ||
{{else}} | ||
<div class="HelloBox center"> | ||
<img src="http://www.updemia.com/images/logo.png" alt="" /> | ||
<h1> | ||
Hello, you | ||
</h1> | ||
<form> | ||
<input type="email" | ||
value="{{html .Email}}" | ||
placeholder="What's your user email?" | ||
autofocus="true" | ||
onkeydown="Email" | ||
onkeyup="Email" required="required" /> | ||
<input type="password" | ||
value="{{html .Passphrase}}" | ||
placeholder="Pass phrase" | ||
onkeydown="Passphrase" | ||
onkeyup="Passphrase" required="required" /> | ||
<input type="submit" value="Start" class="btn" onclick="OnUserLog" /> | ||
</form> | ||
</div> | ||
{{end}} | ||
</div> | ||
` | ||
} | ||
|
||
func (h *Updemia) OnUserLogout(arg app.ChangeArg) { | ||
h.Hash = "" | ||
app.Render(updemiaUser) | ||
} | ||
|
||
func (h *Updemia) OnUserLog(arg app.ChangeArg) { | ||
|
||
if len(h.Email) > 0 { | ||
hash := md5.Sum([]byte(h.Email)) | ||
h.Hash = hex.EncodeToString(hash[:]) | ||
|
||
h.updateImgs() | ||
updemiaUser = h | ||
|
||
// update screenshot capture | ||
updateScreencaptureDirectory(getDestinationPath()) | ||
|
||
// start watching directory | ||
go watchUploadFolder() | ||
} | ||
|
||
app.Render(h) | ||
|
||
trigger.On("user-newfile-success", func() { | ||
h.updateImgs() | ||
app.Render(updemiaUser) | ||
}) | ||
} | ||
|
||
func (h *Updemia) OnOpenFolder(arg app.ChangeArg) { | ||
openDirectory(getDestinationPath()) | ||
} | ||
|
||
func (h *Updemia) updateImgs() { | ||
url := fmt.Sprintf("http://www.updemia.com/api/v1/get?hash=%s", h.Hash) | ||
req, _ := http.NewRequest("GET", url, nil) | ||
client := &http.Client{} | ||
resp, _ := client.Do(req) | ||
defer resp.Body.Close() | ||
|
||
keys := make([]UpdemiaImg, 0) | ||
if err := json.NewDecoder(resp.Body).Decode(&keys); err != nil { | ||
log.Println(err) | ||
} | ||
|
||
h.Imgs = keys | ||
} | ||
|
||
func (h *Updemia) OnContextMenu() { | ||
ctxmenu := app.NewContextMenu() | ||
ctxmenu.Mount(&AppMainMenu{}) | ||
} | ||
|
||
func init() { | ||
app.RegisterComponent(&Updemia{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "Updemia", | ||
"id": "com.updemia.client", | ||
"version": "1.0", | ||
"build-number": 1, | ||
"icon": "logo2.png", | ||
"dev-region": "en", | ||
"deployment-target": "10.12", | ||
"copyright": "Copyright © 2017 scullwm. All rights reserved", | ||
"role": "None", | ||
"category": "", | ||
"sandbox": true, | ||
"capabilities": { | ||
"network": { | ||
"in": false, | ||
"out": true | ||
}, | ||
"hardware": { | ||
"camera": false, | ||
"microphone": false, | ||
"usb": false, | ||
"printing": false, | ||
"bluetooth": false | ||
}, | ||
"app-data": { | ||
"contacts": false, | ||
"location": false, | ||
"calendar": false | ||
}, | ||
"file-access": { | ||
"user-selected": "read-write", | ||
"downloads": "read-write", | ||
"pictures": "read-write", | ||
"music": "read-write", | ||
"movies": "read-write" | ||
} | ||
}, | ||
"store": false, | ||
"sign-id": "", | ||
"supported-files": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/murlokswarm/app" | ||
_ "github.com/murlokswarm/mac" | ||
) | ||
|
||
var ( | ||
win app.Contexter | ||
) | ||
|
||
func main() { | ||
app.OnLaunch = func() { | ||
appMenu := &AppMainMenu{} | ||
app.MenuBar().Mount(appMenu) | ||
|
||
appMenuDock := &AppMainMenu{} | ||
app.Dock().Mount(appMenuDock) | ||
|
||
win = newMainWindow() | ||
} | ||
|
||
app.OnReopen = func(hasVisibleWindow bool) { | ||
if win != nil { | ||
return | ||
} | ||
|
||
win = newMainWindow() | ||
} | ||
|
||
defer app.Run() | ||
} | ||
|
||
func newMainWindow() app.Contexter { | ||
// Creates a window context. | ||
win := app.NewWindow(app.Window{ | ||
Title: "Updemia - Client", | ||
Width: 320, | ||
Height: 720, | ||
MinWidth: 320, | ||
MinHeight: 720, | ||
MaxWidth: 320, | ||
TitlebarHidden: true, | ||
OnClose: func() bool { | ||
win = nil | ||
return true | ||
}, | ||
}) | ||
|
||
hello := &Updemia{} // Creates a Hello component. | ||
win.Mount(hello) // Mounts the Hello component into the window context. | ||
return win | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/murlokswarm/app" | ||
"github.com/murlokswarm/log" | ||
) | ||
|
||
// AppMainMenu implements app.Componer interface. | ||
type AppMainMenu struct { | ||
CustomTitle string | ||
Disabled bool | ||
} | ||
|
||
// Render returns the HTML markup that describes the appearance of the | ||
// component. | ||
// In this case, the component will be mounted into a menu context. | ||
// This restrict the markup to a compositon of menu and menuitem. | ||
func (m *AppMainMenu) Render() string { | ||
return ` | ||
<menu> | ||
<menu label="app"> | ||
<menuitem label="{{if .CustomTitle}}{{.CustomTitle}}{{else}}Custom item{{end}}" | ||
shortcut="ctrl+c" | ||
onclick="OnCustomMenuClick" | ||
separator="true" | ||
disabled="{{.Disabled}}" /> | ||
<menuitem label="Quit" shortcut="meta+q" selector="terminate:" /> | ||
</menu> | ||
<WindowMenu /> | ||
</menu> | ||
` | ||
} | ||
|
||
// OnCustomMenuClick is the handler called when an onclick event occurs in a menuitem. | ||
func (m *AppMainMenu) OnCustomMenuClick() { | ||
log.Info("OnCustomMenuClick") | ||
} | ||
|
||
// WindowMenu implements app.Componer interface. | ||
// It's another component which will be nested inside the AppMenu component. | ||
type WindowMenu struct { | ||
} | ||
|
||
func (m *WindowMenu) Render() string { | ||
return ` | ||
<menu label="Window"> | ||
<menuitem label="Close" selector="performClose:" shortcut="meta+w" /> | ||
</menu> | ||
` | ||
} | ||
|
||
func init() { | ||
app.RegisterComponent(&AppMainMenu{}) | ||
app.RegisterComponent(&WindowMenu{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/deckarep/gosx-notifier" | ||
"github.com/sadlil/go-trigger" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
const userSuccess string = "Upload complete" | ||
const userFail string = "Upload fail" | ||
const notifTitle string = "On updemia.com" | ||
const distantLogo string = "http://www.updemia.com/images/logo.png" | ||
const localLogo string = "/tmp/m1UIjW1.png" | ||
|
||
func notifyUserSuccess(url string) { | ||
note := gosxnotifier.NewNotification(userSuccess) | ||
note.AppIcon = localLogo | ||
note.Title = notifTitle | ||
note.Link = url | ||
note.Group = "com.unique.updemia.identifier" | ||
err := note.Push() | ||
|
||
if err != nil { | ||
log.Println("notification error") | ||
} | ||
|
||
trigger.Fire("user-newfile-success") | ||
} | ||
|
||
func notifyUserFail() { | ||
note := gosxnotifier.NewNotification(userFail) | ||
note.AppIcon = localLogo | ||
note.Title = notifTitle | ||
note.Group = "com.unique.updemia.identifier" | ||
err := note.Push() | ||
|
||
if err != nil { | ||
log.Println("notification error") | ||
} | ||
} | ||
|
||
func saveNotificationLogo() { | ||
img, _ := os.Create(localLogo) | ||
defer img.Close() | ||
|
||
resp, _ := http.Get(distantLogo) | ||
defer resp.Body.Close() | ||
|
||
_, err := io.Copy(img, resp.Body) | ||
if err != nil { | ||
log.Println("Error getting logo") | ||
} | ||
} |
Oops, something went wrong.