josh- / CloudyTabs

CloudyTabs is a simple menu bar application that lists your iCloud Tabs.
http://joshparnham.com/projects/cloudytabs/
789 stars 52 forks source link

Tabs are out of order #49

Closed garyking closed 3 years ago

garyking commented 6 years ago

At the moment, tabs in CloudyTabs appear in the order in the CloudTabs.db database, but this is not the correct order that actually appears in Safari on iPhone, and in Safari on Mac.

Safari on Mac is able to display the tabs in the correct order, so the information exists somewhere, likely in the position column, which is unfortunately in binary format.

peterjmag commented 5 years ago

It looks like the position column is just zlib-compressed JSON. Here are a couple existing sorting implementations:

icloudtabs2md.js: https://gist.github.com/mems/2c96233708c6b5b44ed1a26cb0ec5a0e/61235619601467603270a6ba0048804436437ddd#file-icloudtabs2md-js-L46

CloudTabs.py: https://gist.github.com/christianchristensen/76dde5fd8c5b187495372ffa189bf5e1/0823656db1e11f71e8dc27f3a94f2d4aaaa0deec#file-cloudtabs-py-L13

garyking commented 4 years ago

Thanks. I hadn't come around to this until just now. I wrote my own solution in Ruby, so I'll post it here as another option:

require 'json'
require 'sqlite3'
require 'zlib'

db_file_path = '/CloudTabs.db'

db = SQLite3::Database.new(db_file_path)
query = 'SELECT title, position FROM cloud_tabs'
rows = []

db.execute query do |row|
  title = row[0]
  position = row[1]

  parsed = JSON.parse(Zlib::Inflate.inflate(position))

  rows.push(
    title: title,
    position: parsed['sortValues'][0]['sortValue']
  )
end

puts rows.sort_by { |row| row[:position] }
josh- commented 3 years ago

Hey everyone, I've just released Version 2.0 which persists the position of tabs across devices – thanks so much for all the information here!

Please let me know if you have feedback on the feature 😄