Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Sofianel5 committed Jun 11, 2021
1 parent 724292a commit c63b73a
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 74 deletions.
Binary file modified .lsp/sqlite.db
Binary file not shown.
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"coffeescript": "^2.5.1",
"faye-websocket": "^0.11.3",
"form-data": "^0.2.0",
"menubar": "^9.0.4",
"node-localstorage": "^2.1.6",
"node-window-manager": "^2.2.4",
"postcss-cli": "^8.3.1",
Expand All @@ -51,4 +52,4 @@
"update-electron-app": "^2.0.1",
"utf-8-validate": "^5.0.4"
}
}
}
6 changes: 2 additions & 4 deletions resources/public/html/addbuddy.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<!DOCTYPE html>
<html>
<html style="-webkit-app-region: drag">

<head>
<meta charset="UTF-8">
<title>Add Buddy</title>
</head>

<body>
<div id="app-container">
</div>
<body id="app-container">
</body>
<script src="../js/add-buddy/add-buddy.js"></script>

Expand Down
171 changes: 103 additions & 68 deletions src/buddylistclient/main/core.cljs
Original file line number Diff line number Diff line change
@@ -1,63 +1,18 @@
(ns buddylistclient.main.core
(:require
[cljs.nodejs :as nodejs]
["electron" :refer [app BrowserWindow Menu Tray ipcMain crashReporter Notification dialog]]
["electron" :refer [app BrowserWindow Menu ipcMain crashReporter Notification dialog]]
["faye-websocket" :refer [Client]]
["path" :as path]
["menubar" :refer [menubar]]
["sound-play" :as sound]
[buddylistclient.main.forjure :refer [dissoc-in]]
[buddylistclient.main.user :as user]
["auto-launch" :as AutoLaunch]))

(def *win* (atom {}))

(def *user* (atom {}))

(if (.-isPackaged app)
(set! (-> nodejs/process .-env .-NODE_ENV) "production")
(println (-> nodejs/process .-env .-NODE_ENV)))

(def application-menu-template [{:label "File"
:submenu [{:label "Open buddy list"
:click #(println "open buddy list")}
{:label "Close Window"}]}
{:label "Edit"
:submenu [{:label "Undo"
:accelerator "CmdOrCtrl+Z"
:selector "undo:"}
{:label "Redo"
:accelerator "Shift+CmdOrCtrl+Z"
:selector "redo:"}
{:label "Cut"
:accelerator "CmdOrCtrl+X"
:selector "cut:"}
{:label "Copy"
:accelerator "CmdOrCtrl+C"
:selector "copy:"}
{:label "Paste"
:accelerator "CmdOrCtrl+V"
:selector "paste:"}
{:label "Select All"
:accelerator "CmdOrCtrl+A"
:selector "selectAll:"}]}
{:label "Buddies"
:submenu [{:label "Add Buddy"
:click #(println "Add buddy")}
{:label "Remove Buddy"
:click #(println "remove buddy")}]}])

(if (= (.-platform nodejs/process) "darwin")
(def application-menu-template (into [{:label "BuddyList"
:submenu [{:label "Quit"
:accelerator (if (= (.-platform nodejs/process) "darwin") "Command+Q" "Ctrl+Q")
:click #(.quit app)}]}] application-menu-template)))

(if (not= (-> nodejs/process .-env .-NODE_ENV) "production")
(def application-menu-template (conj application-menu-template {:label "Developer Tools"
:submenu [{:label "Toggle DevTools"
:click #(.toggleDevTools %2)
:accelerator (if (= (.-platform nodejs/process) "darwin") "Command+I" "Ctrl+I")}]})))
(def application-menu-template (clj->js application-menu-template))
(def *user* (atom nil))

(defn on-buddy-message [e]
(println "Message: " (.-data e))
Expand All @@ -78,7 +33,8 @@
(.send (.-webContents window) "user" (->> @*user* clj->js (.stringify js/JSON)))))))

(defn connect-buddylist []
(let [socket (Client. "wss://buddylist.app/buddies" nil (clj->js {:headers {:authorization (:auth-token @*user*) :request-user (:username @*user*)}}))
(let [socket (Client. "wss://buddylist.app/buddies" nil (clj->js {:headers {:authorization (:auth-token @*user*) :request-user (:username @*user*)}
:ping 10}))
on-new-status-handler (fn [_ new-status]
(println "received new-status" new-status)
(let [package {:new-status new-status}
Expand Down Expand Up @@ -112,17 +68,6 @@
(.send (-> @*win* :buddylist .-webContents) "user" (->> @*user* clj->js (.stringify js/JSON)))
(connect-buddylist))))

(.on ipcMain "login"
(fn [_ username password]
(-> (user/log-in username password)
(.then (fn [user]
(reset! *user* user)
(-> @*win* :authentication .close)
(launch-buddylist)))
(.catch (fn [_]
(if-let [window (:authentication @*win*)]
(.send (.-webContents window) "login-error")))))))

(.on ipcMain "signup"
(fn [_ first-name last-name email phone username password]
(-> (user/sign-up first-name last-name email phone username password)
Expand Down Expand Up @@ -241,7 +186,8 @@
(.on (:authentication @*win*) "closed" #(swap! *win* dissoc :authentication)))

(defn connect-chat []
(let [socket (Client. (str "wss://buddylist.app/chat") nil (clj->js {:headers {:authorization (:auth-token @*user*) :request-user (:username @*user*)}}))
(let [socket (Client. (str "wss://buddylist.app/chat") nil (clj->js {:headers {:authorization (:auth-token @*user*) :request-user (:username @*user*)}
:ping 10}))
on-chat-sent (fn [_ to message]
(println "recieved chat from Client")
(let [package {:to to :message message}
Expand All @@ -264,9 +210,101 @@
(close-all-windows window)
(.close window))))

(defn gen-unauth-menu []
(let [base [{:label "Edit"
:submenu [{:label "Undo"
:accelerator "CmdOrCtrl+Z"
:selector "undo:"}
{:label "Redo"
:accelerator "Shift+CmdOrCtrl+Z"
:selector "redo:"}
{:label "Cut"
:accelerator "CmdOrCtrl+X"
:selector "cut:"}
{:label "Copy"
:accelerator "CmdOrCtrl+C"
:selector "copy:"}
{:label "Paste"
:accelerator "CmdOrCtrl+V"
:selector "paste:"}
{:label "Select All"
:accelerator "CmdOrCtrl+A"
:selector "selectAll:"}]}]]
(cond-> base
(= (.-platform nodejs/process) "darwin") (#(into [{:label "BuddyList"
:submenu [{:label "Quit"
:accelerator (if (= (.-platform nodejs/process) "darwin") "Command+Q" "Ctrl+Q")
:click (fn [] (.quit app))}]}] %))
(not= (-> nodejs/process .-env .-NODE_ENV) "production") (conj {:label "Developer Tools"
:submenu [{:label "Toggle DevTools"
:click #(.toggleDevTools %2)
:accelerator (if (= (.-platform nodejs/process) "darwin") "Command+I" "Ctrl+I")}]})
:always clj->js)))

(defn gen-authed-menu []
(let [base [{:label "File"
:submenu [{:label "Open buddy list"
:click (fn []
(if-let [win (:buddylist @*win*)]
(.show win)
(launch-buddylist)))}]}
{:label "Edit"
:submenu [{:label "Undo"
:accelerator "CmdOrCtrl+Z"
:selector "undo:"}
{:label "Redo"
:accelerator "Shift+CmdOrCtrl+Z"
:selector "redo:"}
{:label "Cut"
:accelerator "CmdOrCtrl+X"
:selector "cut:"}
{:label "Copy"
:accelerator "CmdOrCtrl+C"
:selector "copy:"}
{:label "Paste"
:accelerator "CmdOrCtrl+V"
:selector "paste:"}
{:label "Select All"
:accelerator "CmdOrCtrl+A"
:selector "selectAll:"}]}
{:label "Buddies"
:submenu [{:label "Add Buddy"
:click (fn []
(if-let [win (:add-buddy @*win*)]
(.show win)
(open-addbuddy-win)))}]}]]
(cond-> base
(= (.-platform nodejs/process) "darwin") (#(into [{:label "BuddyList"
:submenu [{:label "Quit"
:accelerator (if (= (.-platform nodejs/process) "darwin") "Command+Q" "Ctrl+Q")
:click (fn [] (.quit app))}]}] %))
(not= (-> nodejs/process .-env .-NODE_ENV) "production") (conj {:label "Developer Tools"
:submenu [{:label "Toggle DevTools"
:click #(.toggleDevTools %2)
:accelerator (if (= (.-platform nodejs/process) "darwin") "Command+I" "Ctrl+I")}]})
:always clj->js)))

(defn generate-menu-template []
(if-let [_ @*user*]
(gen-authed-menu)
(gen-unauth-menu)))

(.on ipcMain "login"
(fn [_ username password]
(-> (user/log-in username password)
(.then (fn [user]
(reset! *user* user)
(.setApplicationMenu Menu (.buildFromTemplate Menu (generate-menu-template)))
(-> @*win* :authentication .close)
(launch-buddylist)))
(.catch (fn [_]
(if-let [window (:authentication @*win*)]
(.send (.-webContents window) "login-error")))))))

(defn logout []
(close-all-windows @*win*)
(reset! *user* {})
(reset! *user* nil)
(.setApplicationMenu Menu (.buildFromTemplate Menu (generate-menu-template)))
(user/clear-all)
(launch-unauth-flow))

Expand Down Expand Up @@ -300,17 +338,14 @@
(.then user (fn [u] (if u (do
(println "User:" u)
(reset! *user* u)
(.setApplicationMenu Menu (.buildFromTemplate Menu (generate-menu-template)))
(-> @*win* :loading .close)
(launch-buddylist)
(user/cache-user @*user*)
(connect-chat))
(launch-unauth-flow))))
(launch-unauth-flow))
(let [tray (Tray. (.resolve path (js* "__dirname") "../assets/list.png"))
context-menu (.buildFromTemplate Menu (clj->js [{:label "BuddyList"}]))]
(.setToolTip tray "BuddyList")
(.setContextMenu tray context-menu))
(let [launch (AutoLaunch. {:name "BuddyList"})]
(let [launch (AutoLaunch. (clj->js {:name "BuddyList"}))]
(.enable launch))))

(.setApplicationMenu Menu (.buildFromTemplate Menu application-menu-template)))
(.setApplicationMenu Menu (.buildFromTemplate Menu (generate-menu-template))))
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1259,12 +1259,17 @@
"sanitize-filename" "^1.6.0"
"semver" "^5.3.0"

"electron-positioner@^4.1.0":
"integrity" "sha512-726DfbI9ZNoCg+Fcu6XLuTKTnzf+6nFqv7h+K/V6Ug7IbaPMI7s9S8URnGtWFCy5N5PL4HSzRFF2mXuinftDdg=="
"resolved" "https://registry.npmjs.org/electron-positioner/-/electron-positioner-4.1.0.tgz"
"version" "4.1.0"

"electron-to-chromium@^1.3.723":
"integrity" "sha512-ihL14knI9FikJmH2XUIDdZFWJxvr14rPSdOhJ7PpS27xbz8qmaRwCwyg/bmFwjWKmWK9QyamiCZVCvXm5CH//Q=="
"resolved" "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.742.tgz"
"version" "1.3.742"

"electron@^12.0.6", "electron@>= 6.0.0":
"electron@^12.0.6", "electron@^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0", "electron@>= 6.0.0":
"integrity" "sha512-p5aEt1tIh/PYjwN+6MHTc5HtW529XR9r4Qlj9PPcSb5ubkotSsS0BtWJoRPhDenSAN8sgHk3sbZLxXPJtdnRYA=="
"resolved" "https://registry.npmjs.org/electron/-/electron-12.0.9.tgz"
"version" "12.0.9"
Expand Down Expand Up @@ -2683,6 +2688,13 @@
"resolved" "https://registry.npmjs.org/memoize-one/-/memoize-one-5.2.1.tgz"
"version" "5.2.1"

"menubar@^9.0.4":
"integrity" "sha512-GaMW1MKobIYEthPyDqKuLnxq6Ae4G37x5XBdP0tP1mRtMmDuK/dewTc1ihhQF8RetGMWkLYlHJUadZro/Sqc7w=="
"resolved" "https://registry.npmjs.org/menubar/-/menubar-9.0.4.tgz"
"version" "9.0.4"
dependencies:
"electron-positioner" "^4.1.0"

"meow@^3.1.0":
"integrity" "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs="
"resolved" "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz"
Expand Down

0 comments on commit c63b73a

Please sign in to comment.