GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(browser): offer sign-ins and history from another browser on the… · anomalyco/opencode-rune@74b2ca7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/desktop/src
    • plugin_host/native
      • browser.rs
      • browser
        • cookies.rs
        • history.rs
    • surfaces/browser
      • app_icons.rs
      • cookie_import.rs
      • mod.rs
  • plugins/browser
    • init.luau
    • locales
      • en.json
    • panel.luau
    • signins.luau
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/desktop/src/plugin_host/native/browser.rs‎

Copy file name to clipboardExpand all lines: apps/desktop/src/plugin_host/native/browser.rs
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ pub fn version(app: &App) -> u64 {
579579
app.workspace_panes.browser.host.share_sign_ins().hash(&mut h);
580580
app.workspace_panes.browser.host.engine_preview().hash(&mut h);
581581
app.workspace_panes.browser.app_icons.finished().hash(&mut h);
582+
app.workspace_panes.browser.app_icons.sources.generation().hash(&mut h);
582583
for t in app.workspace_panes.browser.host.tabs() {
583584
if let Some(d) = &t.device { (&d.preset, d.width, d.height, d.scale.map(f32::to_bits)).hash(&mut h); }
584585
(t.id, &t.url, &t.title, t.loading, t.can_go_back, t.can_go_forward, t.zoom.to_bits(), t.inspecting, &t.load_error, &t.favicon, &t.refusal, t.rejected).hash(&mut h);
Collapse file

‎apps/desktop/src/plugin_host/native/browser/cookies.rs‎

Copy file name to clipboardExpand all lines: apps/desktop/src/plugin_host/native/browser/cookies.rs
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ pub(super) fn service_methods(lua: &Lua, vmx: &std::rc::Rc<Vmx>, t: &Table) -> m
4444
.set_name("=Browser:ImportCookieFileAsync")
4545
.call(raw)?;
4646
t.raw_set("ImportCookieFileAsync", call)?;
47+
// `Browser:ImportSignInsAsync(source, profile, sites?)`: another browser's sign-ins (`cookie_import`).
48+
let raw: Function = vmx.asyncs.raw_get("Browser.ImportSignInsAsync")?;
49+
let call: Function = lua
50+
.load("local raw = ... return function(self, source, profile, sites) return raw(source, profile, sites) end")
51+
.set_name("=Browser:ImportSignInsAsync")
52+
.call(raw)?;
53+
t.raw_set("ImportSignInsAsync", call)?;
4754
Ok(())
4855
}
4956

5057
pub(super) fn asyncs(host: &Host<'_>, t: &Table) -> mlua::Result<()> {
51-
t.raw_set("Browser.ImportCookieFileAsync", host.async_function("Browser:ImportCookieFileAsync", import_cookie_file)?)
58+
t.raw_set("Browser.ImportCookieFileAsync", host.async_function("Browser:ImportCookieFileAsync", import_cookie_file)?)?;
59+
t.raw_set("Browser.ImportSignInsAsync", host.async_function("Browser:ImportSignInsAsync", import_sign_ins)?)
5260
}
5361

5462
fn import_cookie_file(lua: &Lua, a: MultiValue, done: Completer) -> mlua::Result<()> {
@@ -59,3 +67,12 @@ fn import_cookie_file(lua: &Lua, a: MultiValue, done: Completer) -> mlua::Result
5967
Ok(())
6068
})
6169
}
70+
71+
fn import_sign_ins(lua: &Lua, a: MultiValue, done: Completer) -> mlua::Result<()> {
72+
let (source, profile, sites): (String, String, Option<Vec<String>>) = mlua::FromLuaMulti::from_lua_multi(a, lua)?;
73+
require_settings_caller(lua, "Browser:ImportSignInsAsync")?;
74+
with_app("Browser:ImportSignInsAsync", |app| {
75+
app.later(Box::new(move |s: &mut App, _: &mut Tx| s.start_browser_import(source, profile, sites, done)));
76+
Ok(())
77+
})
78+
}
Collapse file

‎apps/desktop/src/plugin_host/native/browser/history.rs‎

Copy file name to clipboardExpand all lines: apps/desktop/src/plugin_host/native/browser/history.rs
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::sync::{Mutex, OnceLock};
88

99
use browser_pane::cookies::BrowserEngineKind;
1010
use browser_pane::cookies::icons::AppIcon;
11-
use browser_pane::cookies::sources::{list_sources, source_history_database};
11+
use browser_pane::cookies::sources::source_history_database;
1212
use browser_pane::history::{
1313
HistoryStore, ImportEngine, PageVisit, read_profile_history_in, sweep_stale_import_dirs,
1414
};
@@ -155,7 +155,10 @@ pub(super) fn service_methods(lua: &Lua, vmx: &Vmx, t: &Table) -> mlua::Result<(
155155
// profile counts when it has a cookie database, named from `Local State` or `profiles.ini`.
156156
method(lua, t, "HistoryImportSources", |lua, ()| {
157157
require_builtin_browser(lua, "Browser:HistoryImportSources")?;
158-
let list: Vec<Data> = list_sources()
158+
// Listed off the UI thread; the page draws again when a listing lands.
159+
cx::read(Dep::Browser);
160+
let sources = with_app("Browser:HistoryImportSources", |app| Ok(app.workspace_panes.browser.app_icons.sources.get((*app.waker).clone())))?;
161+
let list: Vec<Data> = sources
159162
.into_iter()
160163
.map(|b| {
161164
let profiles: Vec<Data> = b
Collapse file

‎apps/desktop/src/surfaces/browser/app_icons.rs‎

Copy file name to clipboardExpand all lines: apps/desktop/src/surfaces/browser/app_icons.rs
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub type Known = Option<Arc<AppIcon>>;
1616
pub struct AppIcons {
1717
done: Arc<Mutex<HashMap<String, Known>>>,
1818
asked: RefCell<HashSet<String>>,
19+
/// The other browsers and their profiles (`ImportSources`).
20+
pub sources: ImportSources,
1921
}
2022

2123
impl AppIcons {
@@ -52,3 +54,50 @@ impl AppIcons {
5254
self.done.lock().map(|d| d.len()).unwrap_or(0)
5355
}
5456
}
57+
58+
/// The other browsers and their profiles (`cookies::sources::list_sources`), listed off the UI
59+
/// thread: it reads each browser's `Local State` / `profiles.ini`, which can be large. An ask returns
60+
/// the last listing at once (empty before the first) and, when that is older than `FRESH`, starts
61+
/// another; its end wakes the app and moves `Dep::Browser`'s version, so the page and the pane's
62+
/// sign-in offer draw again with it.
63+
#[derive(Default)]
64+
pub struct ImportSources {
65+
listed: Arc<Mutex<Option<(rune::time::Instant, Vec<browser_pane::cookies::BrowserSource>)>>>,
66+
listing: Arc<std::sync::atomic::AtomicBool>,
67+
generation: Arc<std::sync::atomic::AtomicUsize>,
68+
}
69+
70+
const FRESH: std::time::Duration = std::time::Duration::from_secs(5);
71+
72+
impl ImportSources {
73+
pub fn get(&self, waker: Option<rune::Waker>) -> Vec<browser_pane::cookies::BrowserSource> {
74+
use std::sync::atomic::Ordering;
75+
let current = self.listed.lock().ok().and_then(|l| l.clone());
76+
let stale = current.as_ref().is_none_or(|(at, _)| at.elapsed() >= FRESH);
77+
if stale && !self.listing.swap(true, Ordering::AcqRel) {
78+
let listed = self.listed.clone();
79+
let listing = self.listing.clone();
80+
let generation = self.generation.clone();
81+
let spawned = std::thread::Builder::new().name("browser-import-sources".into()).spawn(move || {
82+
let sources = browser_pane::cookies::sources::list_sources();
83+
if let Ok(mut l) = listed.lock() {
84+
*l = Some((rune::time::Instant::now(), sources));
85+
}
86+
generation.fetch_add(1, Ordering::AcqRel);
87+
listing.store(false, Ordering::Release);
88+
if let Some(w) = &waker {
89+
w();
90+
}
91+
});
92+
if spawned.is_err() {
93+
self.listing.store(false, Ordering::Release);
94+
}
95+
}
96+
current.map(|(_, s)| s).unwrap_or_default()
97+
}
98+
99+
/// Moves each time a listing lands: part of `Dep::Browser`'s version.
100+
pub fn generation(&self) -> usize {
101+
self.generation.load(std::sync::atomic::Ordering::Acquire)
102+
}
103+
}
Collapse file

‎apps/desktop/src/surfaces/browser/cookie_import.rs‎

Copy file name to clipboardExpand all lines: apps/desktop/src/surfaces/browser/cookie_import.rs
+61-1Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use std::collections::HashSet;
1414
use std::sync::{Arc, Mutex};
1515
use std::time::Duration;
1616

17+
use browser_pane::cookies::database::SnapshotScratch;
1718
use browser_pane::cookies::format::prepare_for_import;
19+
use browser_pane::cookies::sources::read_source_cookies;
1820
use browser_pane::cookies::{CookieRead, ImportFailure, ProfileEvent, read_cookie_file};
1921
use browser_pane::protocol::WireCookie;
2022
use rune::time::Instant;
@@ -44,6 +46,8 @@ enum Reading {
4446
pub struct CookieImport {
4547
done: Completer,
4648
read: Reading,
49+
/// Another browser's sign-ins (its read failures keep their own names), not a file.
50+
browser: bool,
4751
/// Batches still to send, the requests the engine has yet to answer, and its answers so far.
4852
batches: Vec<Vec<WireCookie>>,
4953
waiting: HashSet<u64>,
@@ -57,6 +61,17 @@ fn failure(reason: &str) -> Data {
5761
map([("error", Data::String(reason.into()))])
5862
}
5963

64+
/// A browser's read failure as official names it (`ReadFailure`: `key`, `access`, `locked`, `read`).
65+
fn browser_reason(f: ImportFailure) -> &'static str {
66+
match f {
67+
ImportFailure::Key => "key",
68+
ImportFailure::Access => "access",
69+
ImportFailure::Locked => "locked",
70+
ImportFailure::Storage => "storage",
71+
ImportFailure::Read | ImportFailure::Format => "read",
72+
}
73+
}
74+
6075
fn reason(f: ImportFailure) -> &'static str {
6176
match f {
6277
ImportFailure::Read | ImportFailure::Key | ImportFailure::Access | ImportFailure::Locked => "read",
@@ -127,6 +142,7 @@ impl App {
127142
pane.cookie_import = Some(CookieImport {
128143
done,
129144
read: Reading::Pending(slot),
145+
browser: false,
130146
batches: Vec::new(),
131147
waiting: HashSet::new(),
132148
sent: false,
@@ -137,6 +153,50 @@ impl App {
137153
});
138154
}
139155

156+
/// Imports the sign-ins of browser `source`'s profile `profile` (ids from `list_sources`, never
157+
/// a path), or with `sites` only those sites' (`profile/index.ts:478-486` `importBrowser`): `#286`'s
158+
/// `read_source_cookies` reads it on a worker thread (it copies databases and may ask the OS key
159+
/// store), then the cookies take the file's path: `prepare_for_import`, batches, the engine.
160+
/// `done` gets what a file import's does, with `error` one of `key`, `access`, `locked`, `read`,
161+
/// `storage`, `busy`, `failed`.
162+
pub(crate) fn start_browser_import(&mut self, source: String, profile: String, sites: Option<Vec<String>>, done: Completer) {
163+
if self.workspace_panes.browser.cookie_import.is_some() {
164+
return done.complete(failure("busy"));
165+
}
166+
let slot: Arc<Mutex<Option<Read>>> = Arc::new(Mutex::new(None));
167+
let filled = slot.clone();
168+
let waker = (*self.waker).clone();
169+
let spawned = std::thread::Builder::new().name("browser-signin-import".into()).spawn(move || {
170+
let scratch = SnapshotScratch::new(SnapshotScratch::default_dir());
171+
let read = read_source_cookies(&source, &profile, &scratch, sites.as_deref());
172+
if let Ok(mut s) = filled.lock() {
173+
*s = Some(read);
174+
}
175+
if let Some(w) = &waker {
176+
w();
177+
}
178+
});
179+
if spawned.is_err() {
180+
return done.complete(failure("failed"));
181+
}
182+
let start = !self.use_mock_browser() && !self.browser_unsupported();
183+
let pane = &mut self.workspace_panes.browser;
184+
if !pane.host.engine_cookies() && start {
185+
pane.host.prepare(ANSWER_TIMEOUT);
186+
}
187+
pane.cookie_import = Some(CookieImport {
188+
done,
189+
read: Reading::Pending(slot),
190+
browser: true,
191+
batches: Vec::new(),
192+
waiting: HashSet::new(),
193+
sent: false,
194+
imported: 0,
195+
failed: 0,
196+
deadline: Instant::now() + ANSWER_TIMEOUT,
197+
});
198+
}
199+
140200
/// Moves the waiting import on: takes the worker's read, sends its batches once the engine's
141201
/// cookie store is up, and answers once every batch is answered. Takes only its own profile
142202
/// events; others stay for whoever asked. True when an import ended.
@@ -154,7 +214,7 @@ impl App {
154214
job.read = Reading::Ready(CookieRead { cookies: Vec::new(), skipped: read.skipped + skipped, ..read });
155215
}
156216
Some(Err(f)) => {
157-
job.done.complete(failure(reason(f)));
217+
job.done.complete(failure(if job.browser { browser_reason(f) } else { reason(f) }));
158218
return true;
159219
}
160220
None if Instant::now() >= job.deadline => {
Collapse file

‎apps/desktop/src/surfaces/browser/mod.rs‎

Copy file name to clipboardExpand all lines: apps/desktop/src/surfaces/browser/mod.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ mod native {
136136
pub devtools: HashMap<u64, PendingDevtools>,
137137
/// Settings > Browser's cookie-file import waiting on the engine (`cookie_import`).
138138
pub cookie_import: Option<super::cookie_import::CookieImport>,
139-
/// Each other browser's icon for Settings > Browser, read off the UI thread (`app_icons`).
139+
/// Each other browser's icon and the browsers' list for Settings > Browser, read off the UI thread (`app_icons`).
140140
pub app_icons: super::app_icons::AppIcons,
141141
/// Last observed Luau store version for `plugin.browser/rune.sitePermissions`.
142142
pub site_permissions_version: u64,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.