Skip to content

Commit

Permalink
add a setting to preserve redirect-to-drive behaviour from the home page
Browse files Browse the repository at this point in the history
disable it by default
  • Loading branch information
ansuz committed May 31, 2021
1 parent 1fe57c7 commit 3fbb771
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 3 deletions.
2 changes: 1 addition & 1 deletion customize.dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define([
// Make sure we don't display non-translated content (empty button)
$main.find('#data').removeClass('hidden');

if (LocalStore.isLoggedIn()) {
if (LocalStore.isLoggedIn() && LocalStore.getDriveRedirectPreference()) {
if (window.location.pathname === '/') {
window.location = '/drive/';
return;
Expand Down
1 change: 1 addition & 0 deletions www/common/common-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define(['/customize/application_config.js'], function (AppConfig) {
oldStorageKey: 'CryptPad_RECENTPADS',
storageKey: 'filesData',
tokenKey: 'loginToken',
prefersDriveRedirectKey: 'prefersDriveRedirect',
displayPadCreationScreen: 'displayPadCreationScreen',
deprecatedKey: 'deprecated',
MAX_TEAMS_SLOTS: AppConfig.maxTeamsSlots || 5,
Expand Down
10 changes: 10 additions & 0 deletions www/common/cryptpad-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,11 @@ define([
postMessage('BURN_PAD', data);
};

common.setDriveRedirectPreference = function (data, cb) {
LocalStore.setDriveRedirectPreference(data && data.value);
cb();
};

common.changePadPassword = function (Crypt, Crypto, data, cb) {
var href = data.href;
var oldPassword = data.oldPassword;
Expand Down Expand Up @@ -2506,6 +2511,11 @@ define([
}
if (data.anonHash && !cfg.userHash) { LocalStore.setFSHash(data.anonHash); }

var prefersDriveRedirect = data[Constants.prefersDriveRedirectKey];
if (typeof(prefersDriveRedirect) === 'boolean') {
LocalStore.setDriveRedirectPreference(prefersDriveRedirect);
}

initialized = true;
channelIsReady();
});
Expand Down
4 changes: 4 additions & 0 deletions www/common/outer/async-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3167,6 +3167,10 @@ define([
initialized = false;
}

var redirect = Constants.prefersDriveRedirectKey;
var redirectPreference = Util.find(store, [ 'proxy', 'settings', 'general', redirect, ]);
ret[redirect] = redirectPreference;

callback(ret);
});

Expand Down
10 changes: 10 additions & 0 deletions www/common/outer/local-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ define([
return window.CP_logged_in || typeof getUserHash() === "string";
};

LocalStore.getDriveRedirectPreference = function () {
try {
return JSON.parse(localStorage[Constants.redirectToDriveKey]);
} catch (err) { return; }
};

LocalStore.setDriveRedirectPreference = function (bool) {
localStorage.setItem(Constants.redirectToDriveKey, Boolean(bool));
};

LocalStore.login = function (hash, name, cb) {
if (!hash) { throw new Error('expected a user hash'); }
if (!name) { throw new Error('expected a user name'); }
Expand Down
1 change: 1 addition & 0 deletions www/common/sframe-common-outer.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ define([
newTemplate: Array.isArray(Cryptpad.initialPath)
&& Cryptpad.initialPath[0] === "template",
feedbackAllowed: Utils.Feedback.state,
prefersDriveRedirect: Utils.LocalStore.getDriveRedirectPreference(),
isPresent: parsed.hashData && parsed.hashData.present,
isEmbed: parsed.hashData && parsed.hashData.embed,
oldVersionHash: parsed.hashData && parsed.hashData.version < 2, // password
Expand Down
50 changes: 48 additions & 2 deletions www/settings/inner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ define([
'/api/config',
'/common/make-backup.js',
'/common/common-feedback.js',
'/common/common-constants.js',

'/common/jscolor.js',
'/bower_components/file-saver/FileSaver.min.js',
Expand All @@ -35,7 +36,8 @@ define([
AppConfig,
ApiConfig,
Backup,
Feedback
Feedback,
Constants
) {
var saveAs = window.saveAs;
var APP = window.APP = {};
Expand Down Expand Up @@ -72,7 +74,8 @@ define([
'cp-settings-thumbnails',
'cp-settings-drive-backup',
'cp-settings-drive-import-local',
'cp-settings-trim-history'
'cp-settings-trim-history',
'cp-settings-redirect',
//'cp-settings-drive-reset'
],
'cursor': [ // Msg.settings_cat_cursor
Expand Down Expand Up @@ -841,6 +844,49 @@ define([
return $div;
};

Messages.settings_driveRedirectTitle = "DRIVE REDIRECT TITLE"; // XXX redirect
Messages.settings_driveRedirectHint = "DRIVE REDIRECT HINT"; // XXX redirect
Messages.settings_driveRedirect = "DRIVE REDIRECT"; // XXX redirect

create['redirect'] = function () {
if (!common.isLoggedIn()) { return; }
var $div = $('<div>', { 'class': 'cp-settings-redirect cp-sidebarlayout-element' });

$('<span>', { 'class': 'label' }).text(Messages.settings_driveRedirectTitle).appendTo($div);

$('<span>', { 'class': 'cp-sidebarlayout-description' })
.append(Messages.settings_driveRedirectHint)
.appendTo($div);

var $ok = $('<span>', { 'class': 'fa fa-check', title: Messages.saved });
var $spinner = $('<span>', { 'class': 'fa fa-spinner fa-pulse' });

var $cbox = $(UI.createCheckbox('cp-settings-redirect',
Messages.settings_driveRedirect,
false, { label: { class: 'noTitle' } }));
var $checkbox = $cbox.find('input').on('change', function() {
$spinner.show();
$ok.hide();
var val = $checkbox.is(':checked') || false;
common.setAttribute(['general', Constants.prefersDriveRedirectKey, val, function() {
$spinner.hide();
$ok.show();
sframeChan.query("Q_SET_DRIVE_REDIRECT_PREFERENCE", {
value: val,
}, console.log);
});
});

$cbox.appendTo($div);

$ok.hide().appendTo($cbox);
$spinner.hide().appendTo($cbox);

if (privateData.prefersDriveRedirect === true) {
$checkbox[0].checked = true;
}
return $div;
};

create['resettips'] = function() {
var $div = $('<div>', { 'class': 'cp-settings-resettips cp-sidebarlayout-element' });
Expand Down
3 changes: 3 additions & 0 deletions www/settings/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ define([
}
cb();
});
sframeChan.on('Q_SET_DRIVE_REDIRECT_PREFERENCE', function (data, cb) {
Cryptpad.setDriveRedirectPreference(data, cb);
});
};
var category;
if (window.location.hash) {
Expand Down

0 comments on commit 3fbb771

Please sign in to comment.