Skip to content

Commit

Permalink
Merge pull request #141 from Musicoll/dev/master
Browse files Browse the repository at this point in the history
v1.0.2
  • Loading branch information
eliottparis authored Jun 18, 2018
2 parents d978c87 + f127131 commit 6c00620
Show file tree
Hide file tree
Showing 117 changed files with 4,737 additions and 2,256 deletions.
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[submodule "ThirdParty/Juce"]
path = ThirdParty/Juce
url = https://github.com/julianstorer/JUCE.git
url=https://github.com/WeAreROLI/JUCE.git
[submodule "ThirdParty/concurrentqueue"]
path = ThirdParty/concurrentqueue
url = https://github.com/cameron314/concurrentqueue.git
[submodule "ThirdParty/Beast"]
path = ThirdParty/Beast
url = https://github.com/boostorg/beast.git
[submodule "ThirdParty/kiwi-node-server"]
path = ThirdParty/kiwi-node-server
url = https://github.com/Musicoll/kiwi-node-server.git
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ add_library(KiwiEngine STATIC ${KIWI_ENGINE_SRC})
target_include_directories(KiwiEngine PUBLIC ${ROOT_DIR}/Modules)
target_add_dependency(KiwiEngine KiwiModel)
target_add_dependency(KiwiEngine KiwiDsp)
target_add_dependency(KiwiEngine Juce)
set_target_properties(KiwiEngine PROPERTIES FOLDER Modules)
source_group_rec("${KIWI_ENGINE_SRC}" ${ROOT_DIR}/Modules/KiwiEngine)

Expand Down
142 changes: 111 additions & 31 deletions Client/Source/KiwiApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ namespace kiwi
m_api.reset(new Api(*m_api_controller));

m_instance = std::make_unique<Instance>();
m_command_manager->registerAllCommandsForTarget(this);

checkLatestRelease();

startTimer(10);
m_command_manager->registerAllCommandsForTarget(this);

#if JUCE_WINDOWS
openCommandFile(commandLine);
Expand All @@ -136,7 +132,11 @@ namespace kiwi
macMainMenuPopup.addSeparator();
macMainMenuPopup.addCommandItem(&getCommandManager(), CommandIDs::showAppSettingsWindow);
juce::MenuBarModel::setMacMainMenu(m_menu_model.get(), &macMainMenuPopup, TRANS("Open Recent"));
#endif
#endif

pingServer();
startTimer(TimerIds::MainScheduler, 10); // main scheduler update
startTimer(TimerIds::ServerPing, 3000); // Server ping
}

void KiwiApp::anotherInstanceStarted(juce::String const& command_line)
Expand Down Expand Up @@ -209,7 +209,9 @@ namespace kiwi
engine::SwitchTilde::declare();
engine::Float::declare();
engine::ClipTilde::declare();
engine::Clip::declare();
engine::Clip::declare();
engine::SfPlayTilde::declare();
engine::SfRecordTilde::declare();
}

void KiwiApp::declareObjectViews()
Expand All @@ -230,7 +232,8 @@ namespace kiwi
juce::MenuBarModel::setMacMainMenu(nullptr);
#endif

stopTimer();
stopTimer(TimerIds::MainScheduler);
stopTimer(TimerIds::ServerPing);

m_instance.reset();
m_api->cancelAll();
Expand Down Expand Up @@ -270,9 +273,18 @@ namespace kiwi
return true;
}

void KiwiApp::timerCallback()
void KiwiApp::timerCallback(int timer_id)
{
m_scheduler->process();
if(timer_id == TimerIds::MainScheduler)
{
m_instance->tick();
m_scheduler->process();
}
else if(timer_id == TimerIds::ServerPing)
{
// ping server
pingServer();
}
}

bool KiwiApp::isMacOSX()
Expand Down Expand Up @@ -331,7 +343,6 @@ namespace kiwi
void KiwiApp::setAuthUser(Api::AuthUser const& auth_user)
{
(*KiwiApp::use().m_api_controller).setAuthUser(auth_user);

KiwiApp::useInstance().login();
}

Expand All @@ -342,45 +353,114 @@ namespace kiwi

void KiwiApp::logout()
{
useInstance().logout();
useInstance().handleConnectionLost();
KiwiApp::use().m_api_controller->logout();
KiwiApp::commandStatusChanged();
}

void KiwiApp::checkLatestRelease()
bool KiwiApp::canConnectToServer()
{
std::string current_version = getApplicationVersion().toStdString();
const auto server_version = KiwiApp::use().m_last_server_version_check;

Api::CallbackFn<std::string const&> on_success = [current_version](std::string const& latest_version)
return (!server_version.empty()
&& server_version != "null"
&& KiwiApp::use().canConnectToServerVersion(server_version));
}

bool KiwiApp::canConnectToServerVersion(std::string const& server_version)
{
const auto& version = KiwiApp::use().getApplicationVersion();
return (version.compare(server_version) == 0);
}

void KiwiApp::pingSucceed(std::string const& new_server_version)
{
bool was_connected = canConnectToServer();

if((new_server_version == m_last_server_version_check) && was_connected)
return;

if (was_connected)
{
KiwiApp::useScheduler().schedule([current_version, latest_version]()
{
if (current_version.compare(latest_version) != 0)
{
juce::AlertWindow::showMessageBoxAsync(juce::AlertWindow::QuestionIcon,
"New release available" ,
"Upgrading required to access remote documents.\n\n Please visit:\n https://github.com/Musicoll/Kiwi/releases");
}
});
};
logout();
}

Api::ErrorCallback on_fail =[](Api::Error error)
if (canConnectToServerVersion(new_server_version))
{
useInstance().login();
}
else if(m_last_server_version_check != new_server_version)
{
const auto current_version = KiwiApp::use().getApplicationVersion().toStdString();
warning("Can't connect to server! Requires Kiwi " + new_server_version
+ ", please visit:");
warning("https://github.com/Musicoll/Kiwi/releases");
}

m_last_server_version_check = new_server_version;

if(!was_connected && canConnectToServer())
{
const auto api_host = m_api_controller->getHost();
post("Connection established to " + api_host);
}
}

void KiwiApp::pingFailed(Api::Error error)
{
static const std::string ping_failed = "null";

const bool was_connected = canConnectToServer();
if(was_connected)
{
KiwiApp::error("Connection lost");
m_instance->handleConnectionLost();
}
else if(m_last_server_version_check != ping_failed)
{
KiwiApp::error("Connection to server failed: " + error.getMessage());
}

m_last_server_version_check = ping_failed;
}

void KiwiApp::pingServer()
{
Api::CallbackFn<std::string const&> success = [this](std::string const& server_version) {

KiwiApp::useScheduler().schedule([this, server_version]() {
pingSucceed(server_version);
});

};

useApi().getRelease(on_success, on_fail);
useApi().getRelease(success, [this](Api::Error err) {

KiwiApp::useScheduler().schedule([this, err = std::move(err)]() {
pingFailed(err);
});

});
}

void KiwiApp::networkSettingsChanged(NetworkSettings const& settings, juce::Identifier const& id)
{
if (id == Ids::server_address)
{
logout();
auto& api = *m_api_controller;

m_api_controller->setHost(settings.getHost());
m_api_controller->setPort(settings.getApiPort());
const auto host = settings.getHost();
const auto api_port = settings.getApiPort();
//const auto session_port = settings.getSessionPort();

checkLatestRelease();
if((api.getHost() != host) || (api_port != api.getPort()))
{
// settings changed
m_api_controller->setHost(settings.getHost());
m_api_controller->setPort(settings.getApiPort());

pingServer();
}
}
}

Expand Down
67 changes: 45 additions & 22 deletions Client/Source/KiwiApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
namespace ProjectInfo
{
const char* const projectName = "Kiwi";
const char* const versionString = "v1.0.1";
const int versionNumber = 0x101;
const char* const versionString = "v1.0.2";
const int versionNumber = 0x102;
}

namespace kiwi
Expand All @@ -44,9 +44,10 @@ namespace kiwi
// KiWi APPLICATION //
// ================================================================================ //

class KiwiApp : public juce::JUCEApplication,
public NetworkSettings::Listener,
public juce::Timer
class KiwiApp
: public juce::JUCEApplication
, public NetworkSettings::Listener
, public juce::MultiTimer
{
public: // methods

Expand Down Expand Up @@ -76,7 +77,7 @@ namespace kiwi
bool moreThanOneInstanceAllowed() override;

//! @brief Timer call back, processes the scheduler events list.
void timerCallback() override final;
void timerCallback(int timer_id) override;

//! @brief Returns true if the app is running in a Mac OSX operating system.
static bool isMacOSX();
Expand Down Expand Up @@ -111,7 +112,10 @@ namespace kiwi
static Api::AuthUser const& getCurrentUser();

//! @brief Log-out the user
static void logout();
static void logout();

//! @brief Return true if the application can connect to the server.
static bool canConnectToServer();

//! @brief Get the current running engine instance.
static engine::Instance& useEngineInstance();
Expand Down Expand Up @@ -220,7 +224,20 @@ namespace kiwi
KiwiApp() = default;
~KiwiApp() = default;

private: // methods
private: // methods

//! @internal Returns true if the App is compatible with a given server version.
bool canConnectToServerVersion(std::string const& server_version);

//! @internal Ping the server to test current connection
//! @brief Called regularly by the App
void pingServer();

//! @internal handle ping succeed
void pingSucceed(std::string const& server_version);

//! @internal handle ping failed
void pingFailed(Api::Error error);

//! @internal Utility to quit the app asynchronously.
class AsyncQuitRetrier;
Expand All @@ -231,27 +248,33 @@ namespace kiwi
//! @internal Initializes gui specific objects.
void declareObjectViews();

//! @internal Checks if current Kiwi version is the latest. Show popup if version not up to date.
void checkLatestRelease();

// @brief Handles changes of server address.
void networkSettingsChanged(NetworkSettings const& settings, juce::Identifier const& ids) override final;

//! @brief Parse startup command line and open file if exists.
void openCommandFile(juce::String const& command_line);

private: // members

std::unique_ptr<ApiController> m_api_controller;
std::unique_ptr<Api> m_api;
private: // members

enum TimerIds : int
{
MainScheduler = 0,
ServerPing,
};

LookAndFeel m_looknfeel;
TooltipWindow m_tooltip_window;

std::unique_ptr<Instance> m_instance;
std::unique_ptr<juce::ApplicationCommandManager> m_command_manager;
std::unique_ptr<MainMenuModel> m_menu_model;
std::unique_ptr<ApiController> m_api_controller = nullptr;
std::unique_ptr<Api> m_api = nullptr;

LookAndFeel m_looknfeel;
TooltipWindow m_tooltip_window;
std::unique_ptr<StoredSettings> m_settings;
std::unique_ptr<tool::Scheduler<>> m_scheduler;
std::unique_ptr<Instance> m_instance = nullptr;
std::unique_ptr<juce::ApplicationCommandManager> m_command_manager = nullptr;
std::unique_ptr<MainMenuModel> m_menu_model = nullptr;
std::unique_ptr<StoredSettings> m_settings = nullptr;

std::unique_ptr<tool::Scheduler<>> m_scheduler = nullptr;

std::string m_last_server_version_check {};
};
}
Loading

0 comments on commit 6c00620

Please sign in to comment.