Skip to content

Commit

Permalink
Merge branch 'interprocessing'
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Oct 7, 2021
2 parents bcb05d9 + 6e84bb5 commit b9130b8
Show file tree
Hide file tree
Showing 28 changed files with 749 additions and 58 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -69,3 +69,6 @@
[submodule "third_party/curl"]
path = third_party/curl
url = https://github.com/aseprite/curl.git
[submodule "third_party/IXWebSocket"]
path = third_party/IXWebSocket
url = https://github.com/machinezone/IXWebSocket
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -70,6 +70,7 @@ option(ENABLE_MEMLEAK "Enable memory-leaks detector (only for developers)"
option(ENABLE_NEWS "Enable the news in Home tab" on)
option(ENABLE_UPDATER "Enable automatic check for updates" on)
option(ENABLE_SCRIPTING "Compile with scripting support" on)
option(ENABLE_WEBSOCKET "Compile with websocket support" on)
option(ENABLE_TESTS "Compile unit tests" off)
option(ENABLE_BENCHMARKS "Compile benchmarks" off)
option(ENABLE_TRIAL_MODE "Compile the trial version" off)
Expand Down
2 changes: 2 additions & 0 deletions data/strings/en.ini
Expand Up @@ -1377,11 +1377,13 @@ title = Security
script_label = The following script:
file_label = wants to access to this file:
command_label = wants to execute the following command:
websocket_label = wants to open a WebSocket connection to this URL:
dont_show_for_this_access = Don't show this specific alert again for this script
dont_show_for_this_script = Give full trust to this script
allow_execute_access = &Allow Execute Access
allow_write_access = &Allow Write Access
allow_read_access = &Allow Read Access
allow_open_conn_access = &Allow to Open Connections
give_full_access = Give Script Full &Access
stop_script = &Stop Script
Expand Down
2 changes: 1 addition & 1 deletion laf
Submodule laf updated 2 files
+1 −0 base/CMakeLists.txt
+8 −0 base/sha1.h
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -74,6 +74,11 @@ if(ENABLE_SCRIPTING)
add_definitions(-DENABLE_SCRIPTING)
endif()

if(ENABLE_WEBSOCKET)
# Needed for "app" and "main"
add_definitions(-DENABLE_WEBSOCKET)
endif()

######################################################################
# Aseprite Libraries (in preferred order to be built)

Expand Down
10 changes: 10 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -147,6 +147,10 @@ if(ENABLE_SCRIPTING)
commands/cmd_open_script_folder.cpp
ui/devconsole_view.cpp)
endif()
if(ENABLE_WEBSOCKET)
set(scripting_files_ws
script/websocket_class.cpp)
endif()
set(scripting_files
commands/cmd_run_script.cpp
script/app_command_object.cpp
Expand All @@ -159,6 +163,7 @@ if(ENABLE_SCRIPTING)
script/color_space_class.cpp
script/dialog_class.cpp
script/engine.cpp
script/events_class.cpp
script/frame_class.cpp
script/frames_class.cpp
script/image_class.cpp
Expand Down Expand Up @@ -190,6 +195,7 @@ if(ENABLE_SCRIPTING)
script/values.cpp
script/version_class.cpp
shell.cpp
${scripting_files_ws}
${scripting_files_ui})
endif()

Expand Down Expand Up @@ -674,6 +680,10 @@ endif()

if(ENABLE_SCRIPTING)
target_link_libraries(app-lib lua lauxlib lualib)

if(ENABLE_WEBSOCKET)
target_link_libraries(app-lib ixwebsocket)
endif()
endif()

if(ENABLE_UPDATER)
Expand Down
11 changes: 6 additions & 5 deletions src/app/active_site_handler.cpp
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2021 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
Expand Down Expand Up @@ -28,10 +28,11 @@ ActiveSiteHandler::~ActiveSiteHandler()
void ActiveSiteHandler::addDoc(Doc* doc)
{
Data data;
if (doc::Layer* layer = doc->sprite()->root()->firstLayer())
data.layer = layer->id();
else
data.layer = doc::NullId;
data.layer = doc::NullId;
if (doc->sprite()) { // The sprite can be nullptr in some tests
if (doc::Layer* layer = doc->sprite()->root()->firstLayer())
data.layer = layer->id();
}
data.frame = 0;
m_data.insert(std::make_pair(doc, data));
doc->add_observer(this);
Expand Down
29 changes: 21 additions & 8 deletions src/app/context.cpp
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -81,7 +81,7 @@ Doc* Context::activeDocument() const

void Context::setActiveDocument(Doc* document)
{
onSetActiveDocument(document);
onSetActiveDocument(document, true);
}

void Context::setActiveLayer(doc::Layer* layer)
Expand Down Expand Up @@ -206,15 +206,19 @@ void Context::onAddDocument(Doc* doc)

if (m_activeSiteHandler)
m_activeSiteHandler->addDoc(doc);

notifyActiveSiteChanged();
}

void Context::onRemoveDocument(Doc* doc)
{
if (doc == m_lastSelectedDoc)
m_lastSelectedDoc = nullptr;

if (m_activeSiteHandler)
m_activeSiteHandler->removeDoc(doc);

if (doc == m_lastSelectedDoc) {
m_lastSelectedDoc = nullptr;
notifyActiveSiteChanged();
}
}

void Context::onGetActiveSite(Site* site) const
Expand All @@ -224,24 +228,33 @@ void Context::onGetActiveSite(Site* site) const
activeSiteHandler()->getActiveSiteForDoc(doc, site);
}

void Context::onSetActiveDocument(Doc* doc)
void Context::onSetActiveDocument(Doc* doc, bool notify)
{
m_lastSelectedDoc = doc;
if (notify)
notifyActiveSiteChanged();
}

void Context::onSetActiveLayer(doc::Layer* layer)
{
Doc* newDoc = (layer ? static_cast<Doc*>(layer->sprite()->document()): nullptr);
if (!newDoc)
return;

activeSiteHandler()->setActiveLayerInDoc(newDoc, layer);

if (newDoc != m_lastSelectedDoc)
setActiveDocument(newDoc);
if (newDoc)
activeSiteHandler()->setActiveLayerInDoc(newDoc, layer);
else
notifyActiveSiteChanged();
}

void Context::onSetActiveFrame(const doc::frame_t frame)
{
if (m_lastSelectedDoc)
activeSiteHandler()->setActiveFrameInDoc(m_lastSelectedDoc, frame);

notifyActiveSiteChanged();
}

void Context::onSetRange(const DocRange& range)
Expand Down
8 changes: 5 additions & 3 deletions src/app/context.h
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -110,7 +110,7 @@ namespace app {
void onRemoveDocument(Doc* doc) override;

virtual void onGetActiveSite(Site* site) const;
virtual void onSetActiveDocument(Doc* doc);
virtual void onSetActiveDocument(Doc* doc, bool notify);
virtual void onSetActiveLayer(doc::Layer* layer);
virtual void onSetActiveFrame(const doc::frame_t frame);
virtual void onSetRange(const DocRange& range);
Expand All @@ -122,10 +122,12 @@ namespace app {
private:
ActiveSiteHandler* activeSiteHandler() const;

// This must be defined before m_docs because ActiveSiteHandler
// will be an observer of all documents.
mutable std::unique_ptr<ActiveSiteHandler> m_activeSiteHandler;
mutable Docs m_docs;
ContextFlags m_flags; // Last updated flags.
Doc* m_lastSelectedDoc;
mutable std::unique_ptr<ActiveSiteHandler> m_activeSiteHandler;
mutable std::unique_ptr<Preferences> m_preferences;

DISABLE_COPYING(Context);
Expand Down
8 changes: 8 additions & 0 deletions src/app/doc.cpp
Expand Up @@ -70,6 +70,14 @@ Doc::Doc(Sprite* sprite)
Doc::~Doc()
{
DOC_TRACE("DOC: Deleting", this);

try {
notify_observers<Doc*>(&DocObserver::onDestroy, this);
}
catch (...) {
LOG(ERROR, "DOC: Exception on DocObserver::onDestroy()\n");
}

removeFromContext();
}

Expand Down
3 changes: 1 addition & 2 deletions src/app/doc_observer.h
Expand Up @@ -17,6 +17,7 @@ namespace app {
public:
virtual ~DocObserver() { }

virtual void onDestroy(Doc* doc) { }
virtual void onFileNameChanged(Doc* doc) { }

// General update. If an observer receives this event, it's because
Expand Down Expand Up @@ -80,8 +81,6 @@ namespace app {
// Slices
virtual void onSliceNameChange(DocEvent& ev) { }

// Called to destroy the observable. (Here you could call "delete this".)
virtual void dispose() { }
};

} // namespace app
Expand Down
11 changes: 6 additions & 5 deletions src/app/doc_undo_observer.h
@@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2021 Igara Studio S.A.
// Copyright (C) 2015-2018 David Capello
//
// This program is distributed under the terms of
Expand All @@ -19,12 +20,12 @@ namespace app {
class DocUndoObserver {
public:
virtual ~DocUndoObserver() { }
virtual void onAddUndoState(DocUndo* history) = 0;
virtual void onAddUndoState(DocUndo* history) { }
virtual void onDeleteUndoState(DocUndo* history,
undo::UndoState* state) = 0;
virtual void onCurrentUndoStateChange(DocUndo* history) = 0;
virtual void onClearRedo(DocUndo* history) = 0;
virtual void onTotalUndoSizeChange(DocUndo* history) = 0;
undo::UndoState* state) { }
virtual void onCurrentUndoStateChange(DocUndo* history) { }
virtual void onClearRedo(DocUndo* history) { }
virtual void onTotalUndoSizeChange(DocUndo* history) { }
};

} // namespace app
Expand Down
6 changes: 3 additions & 3 deletions src/app/script/app_fs_object.cpp
Expand Up @@ -126,7 +126,7 @@ int AppFS_makeDirectory(lua_State* L)
return 1;
}

if (!ask_access(L, path, FileAccessMode::Write, true))
if (!ask_access(L, path, FileAccessMode::Full, ResourceType::File))
return luaL_error(L, "the script doesn't have access to create the directory '%s'", path);

try {
Expand All @@ -148,7 +148,7 @@ int AppFS_makeAllDirectories(lua_State* L)
return 1;
}

if (!ask_access(L, path, FileAccessMode::Write, true))
if (!ask_access(L, path, FileAccessMode::Write, ResourceType::File))
return luaL_error(L, "the script doesn't have access to create all directories '%s'", path);

try {
Expand All @@ -170,7 +170,7 @@ int AppFS_removeDirectory(lua_State* L)
return 1;
}

if (!ask_access(L, path, FileAccessMode::Write, true))
if (!ask_access(L, path, FileAccessMode::Write, ResourceType::File))
return luaL_error(L, "the script doesn't have access to remove the directory '%s'", path);

try {
Expand Down
9 changes: 8 additions & 1 deletion src/app/script/app_object.cpp
Expand Up @@ -58,7 +58,7 @@ int load_sprite_from_file(lua_State* L, const char* filename,
const LoadSpriteFromFileParam param)
{
std::string absFn = base::get_absolute_path(filename);
if (!ask_access(L, absFn.c_str(), FileAccessMode::Read, true))
if (!ask_access(L, absFn.c_str(), FileAccessMode::Read, ResourceType::File))
return luaL_error(L, "script doesn't have access to open file %s",
absFn.c_str());

Expand Down Expand Up @@ -456,6 +456,12 @@ int App_useTool(lua_State* L)
return 0;
}

int App_get_events(lua_State* L)
{
push_app_events(L);
return 1;
}

int App_get_activeSprite(lua_State* L)
{
app::Context* ctx = App::instance()->context();
Expand Down Expand Up @@ -736,6 +742,7 @@ const Property App_properties[] = {
{ "range", App_get_range, nullptr },
{ "isUIAvailable", App_get_isUIAvailable, nullptr },
{ "defaultPalette", App_get_defaultPalette, App_set_defaultPalette },
{ "events", App_get_events, nullptr },
{ nullptr, nullptr, nullptr }
};

Expand Down
6 changes: 6 additions & 0 deletions src/app/script/engine.cpp
Expand Up @@ -155,6 +155,7 @@ void register_color_space_class(lua_State* L);
#ifdef ENABLE_UI
void register_dialog_class(lua_State* L);
#endif
void register_events_class(lua_State* L);
void register_frame_class(lua_State* L);
void register_frames_class(lua_State* L);
void register_image_class(lua_State* L);
Expand All @@ -180,6 +181,7 @@ void register_tag_class(lua_State* L);
void register_tags_class(lua_State* L);
void register_tool_class(lua_State* L);
void register_version_class(lua_State* L);
void register_websocket_class(lua_State* L);

void set_app_params(lua_State* L, const Params& params);

Expand Down Expand Up @@ -386,6 +388,7 @@ Engine::Engine()
#ifdef ENABLE_UI
register_dialog_class(L);
#endif
register_events_class(L);
register_frame_class(L);
register_frames_class(L);
register_image_class(L);
Expand All @@ -411,6 +414,9 @@ Engine::Engine()
register_tags_class(L);
register_tool_class(L);
register_version_class(L);
#if ENABLE_WEBSOCKET
register_websocket_class(L);
#endif

// Check that we have a clean start (without dirty in the stack)
ASSERT(lua_gettop(L) == top);
Expand Down
11 changes: 3 additions & 8 deletions src/app/script/engine.h
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -58,13 +58,6 @@ namespace app {

namespace script {

enum class FileAccessMode {
Execute = 1,
Write = 2,
Read = 4,
Full = 7
};

class EngineDelegate {
public:
virtual ~EngineDelegate() { }
Expand Down Expand Up @@ -121,6 +114,7 @@ namespace app {
EngineDelegate* m_oldDelegate;
};

void push_app_events(lua_State* L);
int push_image_iterator_function(lua_State* L, const doc::Image* image, int extraArgIndex);
void push_brush(lua_State* L, const doc::BrushRef& brush);
void push_cel_image(lua_State* L, doc::Cel* cel);
Expand All @@ -136,6 +130,7 @@ namespace app {
void push_palette(lua_State* L, doc::Palette* palette);
void push_plugin(lua_State* L, Extension* ext);
void push_sprite_cel(lua_State* L, doc::Cel* cel);
void push_sprite_events(lua_State* L, doc::Sprite* sprite);
void push_sprite_frame(lua_State* L, doc::Sprite* sprite, doc::frame_t frame);
void push_sprite_frames(lua_State* L, doc::Sprite* sprite);
void push_sprite_frames(lua_State* L, doc::Sprite* sprite, const std::vector<doc::frame_t>& frames);
Expand Down

0 comments on commit b9130b8

Please sign in to comment.