Skip to content

Commit

Permalink
allow multi intancse on daemon mode
Browse files Browse the repository at this point in the history
  • Loading branch information
josephshen committed Jul 18, 2017
1 parent 3ada687 commit 74d7cc7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# exclude tmp build dir
tmp/

# exclude build result dir
dst/

# macOS
.DS_Store

Expand Down
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
endif()


if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set_target_properties(ColorPicker4MoDao PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dst/Windows/x64)
else()
set_target_properties(ColorPicker4MoDao PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dst/Windows/x32)
endif()
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set_target_properties(ColorPicker4MoDao PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dst/macOS)
endif()

################################################################################
# using this handle Qt5 static link
include(3rd/StaticQt5Base/SmartCute.cmake)
Expand Down
13 changes: 7 additions & 6 deletions demo/Electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ const child_process = require('child_process')
/** ****/

let color_picker_path = null

console.log(os.arch())
if( os.type() == "Darwin" ){
color_picker_path = './tmp/build_mac/ColorPicker4MoDao.app/Contents/MacOS/ColorPicker4MoDao';
color_picker_path = './dst/macOS/ColorPicker4MoDao.app/Contents/MacOS/ColorPicker4MoDao';
} else {
color_picker_path = 'tmp/build_win/ColorPicker4MoDao.exe';
if( os.arch() == 'x64') {
color_picker_path = './dst/Windows/x64/ColorPicker4MoDao.exe';
} else {
color_picker_path = './dst/Windows/x32/ColorPicker4MoDao.exe';
}
}

let color_picker_callbacker = null;
Expand All @@ -38,10 +42,7 @@ function bind_color_picker_callbacks(the_process) {
});

the_process.stdout.on('end', function () {
// some time ColorPicker might crash, so we just restart this
console.log('ColorPicker STDOUT Done');
color_picker_child_process = child_process.spawn(color_picker_path, ['--daemon'])
bind_color_picker_callbacks(color_picker_child_process)
});
}

Expand Down
7 changes: 3 additions & 4 deletions src/ColorPicker/DaemonModeHost.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ void DaemonThread::run()
}
}

static bool daemon_mode_check = false;

bool ShouldStartInDaemonMode()
{
auto the_check_function = []()->bool{
Expand All @@ -32,12 +30,13 @@ bool ShouldStartInDaemonMode()

if( (arguments.size() == 2) && (arguments[1] == QString("--daemon")) ){
// qDebug() << "Should Start In Daemon Mode";
daemon_mode_check = true;
return true;
}
return daemon_mode_check;
return false;
};

static auto value = the_check_function();
// qDebug() << "ShouldStartInDaemonMode" << value;
return value;
}

Expand Down
11 changes: 7 additions & 4 deletions src/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

int main(int argc, char *argv[])
{
if( Hack::WhetherOneInstanceStarted<Hack::OS::Current>() == true ){
return 0;
}

QApplication app(argc, argv);

// don't check single instance on daemon mode
if( ShouldStartInDaemonMode() == false ) {
if( Hack::WhetherOneInstanceStarted<Hack::OS::Current>() == true ){
return 0;
}
};

BootGlobalEventHook();

auto screens = qGuiApp->screens();
Expand Down

0 comments on commit 74d7cc7

Please sign in to comment.