Skip to content

Commit

Permalink
snap: Fixed issues with storing the default session
Browse files Browse the repository at this point in the history
Also added a workaround to help people who've already installed and ran
the snap.

Closes mapeditor#2852
  • Loading branch information
bjorn committed Jun 30, 2020
1 parent 40049fd commit 14f8f5f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/tiled/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,14 @@ QString Preferences::startupSession() const

void Preferences::setLastSession(const QString &fileName)
{
setValue(QLatin1String("Project/LastSession"), fileName);
// Don't store the path to the default session, since this path may vary
// between restarts. For example the snap release includes the build
// number in the path and trying to save to a session file for a different
// version doesn't work.
if (fileName == Session::defaultFileName())
setValue(QLatin1String("Project/LastSession"), QString());
else
setValue(QLatin1String("Project/LastSession"), fileName);
}

bool Preferences::restoreSessionOnStartup() const
Expand Down
16 changes: 15 additions & 1 deletion src/tiled/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,21 @@ QString Session::defaultFileNameForProject(const QString &projectFile)
Session &Session::initialize()
{
Q_ASSERT(!mCurrent);
return switchCurrent(Preferences::instance()->startupSession());
auto &session = switchCurrent(Preferences::instance()->startupSession());

// Workaround for users facing issue #2852, bringing their default session
// to the right location.
if (session.project.isEmpty()) {
if (QFileInfo(session.fileName()).fileName() == QLatin1String("default.tiled-session")) {
const QString defaultName = defaultFileName();
if (session.fileName() != defaultName) {
session.setFileName(defaultName);
Preferences::instance()->setLastSession(defaultName);
}
}
}

return session;
}

Session &Session::current()
Expand Down

0 comments on commit 14f8f5f

Please sign in to comment.