From aaa8530f5abb8a860a51c054de2bd39bd7af5e35 Mon Sep 17 00:00:00 2001 From: Andrey Shovkoplyas Date: Tue, 9 Oct 2018 17:00:07 +0200 Subject: [PATCH] download latest nightly in desktop Signed-off-by: Andrey Shovkoplyas --- .../ui/components/desktop/events.cljs | 15 +++++++++++---- .../desktop/main/tabs/profile/views.cljs | 13 +++++++++++-- src/status_im/ui/screens/events.cljs | 18 +++++++++++++++++- src/status_im/utils/platform.cljs | 3 +++ 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/status_im/ui/components/desktop/events.cljs b/src/status_im/ui/components/desktop/events.cljs index 65f8960ad5..61d9057134 100644 --- a/src/status_im/ui/components/desktop/events.cljs +++ b/src/status_im/ui/components/desktop/events.cljs @@ -4,7 +4,14 @@ (handlers/register-handler-fx :show-desktop-tab (fn [{:keys [db] :as cofx} [_ tab-name]] - {:db (assoc-in db [:desktop/desktop :tab-view-id] tab-name) - :dispatch [:navigate-to (if (and (= tab-name :home) (:current-chat-id db)) - :chat - :home)]})) + (merge {:db (assoc-in db [:desktop/desktop :tab-view-id] tab-name) + :dispatch [:navigate-to (if (and (= tab-name :home) (:current-chat-id db)) + :chat + :home)]} + (when (= tab-name :profile) + {:http-get + {:url + "https://raw.githubusercontent.com/status-im/status-im.github.io/develop/env.sh" + :success-event-creator + (fn [o] + [:fetch-desktop-version-success o])}})))) diff --git a/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs b/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs index 3a0bfb2942..13878a9165 100644 --- a/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs +++ b/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs @@ -105,8 +105,10 @@ (views/defview profile [{:keys [seed-backed-up? mnemonic] :as user}] (views/letsubs [current-view-id [:get :view-id] + nightly-version [:get-in [:desktop/desktop :nightly-version]] editing? [:get :my-profile/editing?]] ;; TODO janherich: refactor my-profile, unnecessary complicated structure in db (could be just `:staged-name`/`:editing?` fields in account map) and horrible way to access it woth `:get`/`:set` subs/events - (let [adv-settings-open? (= current-view-id :advanced-settings) + (let [{:keys [url commit]} nightly-version + adv-settings-open? (= current-view-id :advanced-settings) backup-recovery-phrase-open? (= current-view-id :backup-recovery-phrase) show-backup-seed? (and (not seed-backed-up?) (not (string/blank? mnemonic)))] [react/view @@ -137,7 +139,14 @@ [react/view {:style (styles/profile-row false)} [react/touchable-highlight {:on-press #(re-frame/dispatch [:accounts.logout.ui/logout-confirmed])} [react/text {:style (styles/profile-row-text colors/red)} (i18n/label :t/logout)]] - [react/view [react/text {:style (styles/profile-row-text colors/gray)} "V" build/version " (" build/commit-sha ")"]]]]]))) + [react/view [react/text {:style (styles/profile-row-text colors/gray)} "V" build/version " (" build/commit-sha ")"]]] + (when (and url commit (not= (subs build/commit-sha 0 6) commit)) + [react/view {:style {:margin-top 20}} + [react/touchable-highlight {:on-press #(.openURL react/linking url)} + [react/view {:style styles/share-contact-code} + [react/view {:style styles/share-contact-code-text-container} + [react/text {:style styles/share-contact-code-text} + (str "Download latest " commit)]]]]])]]))) (views/defview profile-data [] (views/letsubs diff --git a/src/status_im/ui/screens/events.cljs b/src/status_im/ui/screens/events.cljs index 41d5265860..6550b27eb2 100644 --- a/src/status_im/ui/screens/events.cljs +++ b/src/status_im/ui/screens/events.cljs @@ -31,7 +31,10 @@ [status-im.utils.handlers :as handlers] [status-im.utils.http :as http] [status-im.utils.utils :as utils] - [status-im.utils.fx :as fx])) + [status-im.utils.fx :as fx] + [status-im.utils.platform :as platform] + [taoensso.timbre :as log] + [clojure.string :as str])) (defn- http-get [{:keys [url response-validator success-event-creator failure-event-creator timeout-ms]}] (let [on-success #(re-frame/dispatch (success-event-creator %)) @@ -144,3 +147,16 @@ :update-window-dimensions (fn [{:keys [db]} [_ dimensions]] {:db (assoc db :dimensions/window (dimensions/window dimensions))})) + +(handlers/register-handler-fx + :fetch-desktop-version-success + (fn [{:keys [db]} [_ result]] + (when (and result (not (str/blank? result)) (or platform/isMacOs? platform/isNix?)) + (let [lines (str/split-lines result) + var (if platform/isMacOs? "DMG_URL=\"" "NIX_URL=\"") + param (first (filter #(not= -1 (.indexOf % var)) lines))] + (when param + (let [url (subs param (+ 9 (.indexOf param var)) (- (count param) 1)) + dt (- (count url) (if platform/isMacOs? 12 17)) + commit (subs url (- dt 6) dt)] + {:db (assoc-in db [:desktop/desktop :nightly-version] {:url url :commit commit})})))))) diff --git a/src/status_im/utils/platform.cljs b/src/status_im/utils/platform.cljs index 93c0113e82..a7144c5d4f 100644 --- a/src/status_im/utils/platform.cljs +++ b/src/status_im/utils/platform.cljs @@ -21,6 +21,9 @@ (def mobile? (not= os "desktop")) (def iphone-x? (and ios? (ios/iphone-x-dimensions?))) +(def isMacOs? (when platform (.-isMacOs platform))) +(def isNix? (when platform (or (.-isLinux platform) (.-isUnix platform)))) + (def platform-specific (cond android? android/platform-specific