Skip to content

Commit

Permalink
Merge pull request #1100 from brave/sync-v2-this-device
Browse files Browse the repository at this point in the history
Use thisDeviceId to identify "This Device"
  • Loading branch information
darkdh committed Dec 14, 2018
2 parents 3c8f70e + 9ee5bcb commit d45f42c
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ void CustomizeWebUIHTMLSource(const std::string &name, content::WebUIDataSource*
{ "braveSync", IDS_BRAVE_SYNC_ENABLED_BRAVE_TITLE },
{ "syncChainDevices", IDS_BRAVE_SYNC_ENABLED_DEVICES_CHAIN_TITLE },
{ "deviceName", IDS_BRAVE_SYNC_ENABLED_TABLE_DEVICE_NAME_TITLE },
{ "mainDevice", IDS_BRAVE_SYNC_ENABLED_TABLE_MAIN_DEVICE_TEXT },
{ "thisDevice", IDS_BRAVE_SYNC_ENABLED_TABLE_THIS_DEVICE_TEXT },
{ "addedOn", IDS_BRAVE_SYNC_ENABLED_TABLE_ADDED_ON_TITLE },
{ "addDevice", IDS_BRAVE_SYNC_ENABLED_ADD_DEVICE_BUTTON },
{ "viewSyncCode", IDS_BRAVE_SYNC_ENABLED_VIEW_CODE_BUTTON },
Expand All @@ -464,8 +464,8 @@ void CustomizeWebUIHTMLSource(const std::string &name, content::WebUIDataSource*
{ "enterSyncCodeDescription", IDS_BRAVE_SYNC_ENTER_CODE_DESCRIPTION },
{ "confirmCode", IDS_BRAVE_SYNC_ENTER_CODE_CONFIRM_CODE_BUTTON },
// [modal] Remove Main Device
{ "thisDeviceRemovalDescription", IDS_BRAVE_SYNC_REMOVE_MAIN_DEVICE_DESCRIPTION },
{ "joinSyncChain", IDS_BRAVE_SYNC_REMOVE_MAIN_DEVICE_JOIN_CHAIN_INSTRUCTIONS },
{ "thisDeviceRemovalDescription", IDS_BRAVE_SYNC_REMOVE_THIS_DEVICE_DESCRIPTION },
{ "joinSyncChain", IDS_BRAVE_SYNC_REMOVE_THIS_DEVICE_JOIN_CHAIN_INSTRUCTIONS },
// [modal] Remove Other Device
{ "otherDeviceRemovalDescription", IDS_BRAVE_SYNC_REMOVE_OTHER_DEVICE_DESCRIPTION },
// [modal] Reset Sync
Expand Down
1 change: 1 addition & 0 deletions components/brave_sync/brave_sync_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ std::unique_ptr<brave_sync::Settings> Prefs::GetBraveSyncSettings() const {
auto settings = std::make_unique<brave_sync::Settings>();

settings->this_device_name_ = GetThisDeviceName();
settings->this_device_id_ = GetThisDeviceId();
settings->sync_this_device_ = GetSyncEnabled();
settings->sync_bookmarks_ = GetSyncBookmarksEnabled();
settings->sync_settings_ = GetSyncSiteSettingsEnabled();
Expand Down
1 change: 1 addition & 0 deletions components/brave_sync/brave_sync_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ TEST_F(BraveSyncServiceTest, GetSettingsAndDevices) {
[](std::unique_ptr<brave_sync::Settings> settings,
std::unique_ptr<brave_sync::SyncDevices> devices) {
EXPECT_TRUE(settings->this_device_name_.empty());
EXPECT_TRUE(settings->this_device_id_.empty());
EXPECT_FALSE(settings->sync_configured_);
EXPECT_FALSE(settings->sync_this_device_);
EXPECT_FALSE(settings->sync_bookmarks_);
Expand Down
1 change: 1 addition & 0 deletions components/brave_sync/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Settings {
public:
Settings();
std::string this_device_name_;
std::string this_device_id_;
bool sync_this_device_;
bool sync_bookmarks_;
bool sync_settings_;
Expand Down
3 changes: 1 addition & 2 deletions components/brave_sync/ui/components/enabledContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class SyncEnabledContent extends React.PureComponent<Props, State
content: [
{ content:
<TableRowDevice>
{device.name} {Number(device.id) === 0 ? getLocale('mainDevice') : null }
{device.name} {device.id === this.props.syncData.thisDeviceId ? getLocale('thisDevice') : null }
</TableRowDevice>
},
{ content: device.lastActive },
Expand All @@ -90,7 +90,6 @@ export default class SyncEnabledContent extends React.PureComponent<Props, State
<TableRowRemoveButton
data-id={device.id}
data-name={device.name}
data-main={device.thisDeviceName}
onClick={this.onClickRemoveDeviceButton}
>
&times;
Expand Down
3 changes: 2 additions & 1 deletion components/brave_sync/ui/reducers/sync_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const syncReducer: Reducer<Sync.State | undefined> = (state: Sync.State | undefi
devices: [ ...devices ],
isSyncConfigured: payload.settings.sync_configured,
thisDeviceName: payload.settings.this_device_name,
thisDeviceId: payload.settings.this_device_id,
syncBookmarks: payload.settings.sync_bookmarks,
syncSavedSiteSettings: payload.settings.sync_settings,
syncBrowsingHistory: payload.settings.sync_history
Expand Down Expand Up @@ -87,7 +88,7 @@ const syncReducer: Reducer<Sync.State | undefined> = (state: Sync.State | undefi
}

// if the device removed is the this device, reset sync
if (payload.deviceName === state.thisDeviceName && payload.id === 0) {
if (payload.id === state.thisDeviceId) {
state = { ...storage.defaultState }
chrome.send('resetSync')
break
Expand Down
1 change: 1 addition & 0 deletions components/brave_sync/ui/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const keyName = 'sync-data_t'

export const defaultState = {
thisDeviceName: '',
thisDeviceId: '',
devices: [],
isSyncConfigured: false,
seedQRImageSource: '',
Expand Down
1 change: 1 addition & 0 deletions components/brave_sync/values_conv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ std::unique_ptr<Value> BraveSyncSettingsToValue(brave_sync::Settings *brave_sync
auto result = std::make_unique<Value>(Value::Type::DICTIONARY);

result->SetKey("this_device_name", Value(brave_sync_settings->this_device_name_));
result->SetKey("this_device_id", Value(brave_sync_settings->this_device_id_));
result->SetKey("sync_this_device", Value(brave_sync_settings->sync_this_device_));
result->SetKey("sync_bookmarks", Value(brave_sync_settings->sync_bookmarks_));
result->SetKey("sync_settings", Value(brave_sync_settings->sync_settings_));
Expand Down
2 changes: 2 additions & 0 deletions components/definitions/sync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare namespace Sync {
device_id: number
last_active: number
}

export interface Devices {
name: string
id: number
Expand All @@ -32,6 +33,7 @@ export type SetupErrorType =

export interface State {
thisDeviceName: string
thisDeviceId: string
devices: Devices[]
isSyncConfigured: boolean
seedQRImageSource: string
Expand Down
6 changes: 3 additions & 3 deletions components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
<message name="IDS_BRAVE_SYNC_ENABLED_BRAVE_TITLE" desc="The Brae Sync title">Brave Sync</message>
<message name="IDS_BRAVE_SYNC_ENABLED_DEVICES_CHAIN_TITLE" desc="The Sync title for the table of devices synced">Devices in your sync chain</message>
<message name="IDS_BRAVE_SYNC_ENABLED_TABLE_DEVICE_NAME_TITLE" desc="The Sync table title for the device column">device name</message>
<message name="IDS_BRAVE_SYNC_ENABLED_TABLE_MAIN_DEVICE_TEXT" desc="The Sync table title for the device column">(This Device)</message>
<message name="IDS_BRAVE_SYNC_ENABLED_TABLE_THIS_DEVICE_TEXT" desc="The Sync table title for the device column">(This Device)</message>
<message name="IDS_BRAVE_SYNC_ENABLED_TABLE_ADDED_ON_TITLE" desc="The Sync table title indicating when a device was added to the chain">added on</message>
<message name="IDS_BRAVE_SYNC_ENABLED_ADD_DEVICE_BUTTON" desc="The Sync button `add device` for adding a new device to the sync chain. triggers a modal with device options">add device</message>
<message name="IDS_BRAVE_SYNC_ENABLED_VIEW_CODE_BUTTON" desc="The Sync button `view sync code` for viewing the passphrase needed to add a new device. triggers a modal with sync code">view sync code</message>
Expand All @@ -469,8 +469,8 @@
<message name="IDS_BRAVE_SYNC_ENTER_CODE_DESCRIPTION" desc="The Sync modal text for `enter sync code`">Go to Brave Settings &gt; Sync &gt; Display sync code</message>
<message name="IDS_BRAVE_SYNC_ENTER_CODE_CONFIRM_CODE_BUTTON" desc="The Sync modal button for `enter sync code` to confirm sync code">Confirm Sync Code</message>
<!-- WebUI brave sync resources: [modal] Remove Main Device -->
<message name="IDS_BRAVE_SYNC_REMOVE_MAIN_DEVICE_DESCRIPTION" desc="The Sync phrase in `remove this device` modal explaining how data behaves on all devices">Local device data will remain intact on all devices. Other devices in this sync chain will remain synced.</message>
<message name="IDS_BRAVE_SYNC_REMOVE_MAIN_DEVICE_JOIN_CHAIN_INSTRUCTIONS" desc="The Sync phrase in `remove this device` modal explaining how to join a sync chain again">To join a sync chain again, choose “Enter a sync chain code”.</message>
<message name="IDS_BRAVE_SYNC_REMOVE_THIS_DEVICE_DESCRIPTION" desc="The Sync phrase in `remove this device` modal explaining how data behaves on all devices">Local device data will remain intact on all devices. Other devices in this sync chain will remain synced.</message>
<message name="IDS_BRAVE_SYNC_REMOVE_THIS_DEVICE_JOIN_CHAIN_INSTRUCTIONS" desc="The Sync phrase in `remove this device` modal explaining how to join a sync chain again">To join a sync chain again, choose “Enter a sync chain code”.</message>
<!-- WebUI brave sync resources: [modal] Remove Other Device -->
<message name="IDS_BRAVE_SYNC_REMOVE_OTHER_DEVICE_DESCRIPTION" desc="The Sync phrase in `remove other device` modal explaining what happens when the device is removed">Note: Removing this device from this sync chain does not clear previously synced data from the device.</message>
<!-- WebUI brave sync resources: [modal] Reset Sync -->
Expand Down

0 comments on commit d45f42c

Please sign in to comment.