Add support for the windows application restart api

This commit is contained in:
Marek Roszko 2020-07-20 20:33:35 -04:00 committed by Wayne Stambaugh
parent 1374d82114
commit 9278660b10
8 changed files with 184 additions and 0 deletions

View File

@ -62,6 +62,7 @@
#include <settings/settings_manager.h>
#include <netlist.h>
#include <widgets/infobar.h>
#include <kiplatform/app.h>
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName )
@ -325,6 +326,10 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
LoadProjectSettings();
SetShutdownBlockReason( _( "Schematic file changes are unsaved" ) );
if( Kiface().IsSingle() )
{
KIPLATFORM::APP::RegisterApplicationRestart( fullFileName );
}
if( is_new )
{

View File

@ -31,6 +31,7 @@
#include <executable_names.h>
#include <filehistory.h>
#include <gestfich.h>
#include <kiplatform/app.h>
#include <kiway.h>
#include <kiway_express.h>
#include <kiway_player.h>
@ -378,6 +379,8 @@ void KICAD_MANAGER_FRAME::LoadProject( const wxFileName& aProjectFileName )
wxPostEvent( this, cmd );
PrintPrjInfo();
KIPLATFORM::APP::RegisterApplicationRestart( aProjectFileName.GetFullPath() );
}

View File

@ -2,6 +2,7 @@
# Add the appropriate source files
if( APPLE )
set( PLATFORM_SRCS
osx/app.mm
osx/ui.mm
)
@ -13,10 +14,12 @@ if( APPLE )
)
elseif( WIN32 )
set( PLATFORM_SRCS
msw/app.cpp
msw/ui.cpp
)
elseif( UNIX )
set( PLATFORM_SRCS
gtk/app.cpp
gtk/ui.cpp
)
endif()

View File

@ -0,0 +1,37 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <kiplatform/app.h>
#include <wx/string.h>
bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine )
{
// Not implemented on this platform
return true;
}
bool KIPLATFORM::APP::UnregisterApplicationRestart()
{
// Not implemented on this platform
return true;
}

View File

@ -0,0 +1,46 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KIPLATFORM_APP_H_
#define KIPLATFORM_APP_H_
class wxString;
namespace KIPLATFORM
{
namespace APP
{
/**
* Registers the application for restart with the OS with the given command line string to pass as args
*
* @param aCommandLine is string the OS will invoke the application with
*/
bool RegisterApplicationRestart( const wxString& aCommandLine );
/**
* Unregisters the application from automatic restart
*
* Depending on OS, this may not be required
*/
bool UnregisterApplicationRestart();
}
}
#endif // KIPLATFORM_UI_H_

View File

@ -0,0 +1,47 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <kiplatform/app.h>
#include <wx/string.h>
#include <windows.h>
#include <strsafe.h>
bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine )
{
HRESULT hr = S_OK; // not if registering for recovery and restart fails.
WCHAR wsCommandLine[RESTART_MAX_CMD_LINE];
RtlZeroMemory( wsCommandLine, sizeof( wsCommandLine ) );
StringCchCopyW( wsCommandLine, sizeof( wsCommandLine ), aCommandLine.wc_str() );
hr = ::RegisterApplicationRestart( wsCommandLine, RESTART_NO_PATCH );
return SUCCEEDED( hr );
}
bool KIPLATFORM::APP::UnregisterApplicationRestart()
{
// Note, this isn't required to be used on Windows if you are just closing the program
return SUCCEEDED( ::UnregisterApplicationRestart() );
}

View File

@ -0,0 +1,37 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <kiplatform/app.h>
#include <wx/string.h>
bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine )
{
// Not implemented on this platform
return true;
}
bool KIPLATFORM::APP::UnregisterApplicationRestart()
{
// Not implemented on this platform
return true;
}

View File

@ -50,6 +50,7 @@
#include <wx/stdpaths.h>
#include <pcb_layer_widget.h>
#include <ratsnest/ratsnest_data.h>
#include <kiplatform/app.h>
#include <wx/wupdlock.h>
#include <settings/common_settings.h>
@ -461,6 +462,11 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
wxString fullFileName( aFileSet[0] );
if( Kiface().IsSingle() )
{
KIPLATFORM::APP::RegisterApplicationRestart( fullFileName );
}
// We insist on caller sending us an absolute path, if it does not, we say it's a bug.
wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(), wxT( "Path is not absolute!" ) );