-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(instance-settings): streamline modal state and save flow #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| "windows": [ | ||
| { | ||
| "title": "Anon", | ||
| "width": 800, | ||
| "width": 1100, | ||
| "height": 600 | ||
| } | ||
| ], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import MediaDevicesSection from "./settings/MediaDevicesSection.svelte"; | ||
| import BehaviorSection from "./settings/BehaviorSection.svelte"; | ||
| import AdvancedSection from "./settings/AdvancedSection.svelte"; | ||
| import { WINDOW_PRESETS } from "./settings/constants"; | ||
| import { fingerprintPresets } from "$lib/store"; | ||
| import type { Preset } from "$lib/store"; | ||
|
|
||
|
|
@@ -47,6 +48,8 @@ | |
|
|
||
| // AUTO mode state | ||
| let autoMode = false; | ||
| let autoChangeWindowSize = true; | ||
| let autoWindowPresetIndex = -1; | ||
| const accentGreen = '#10b981'; | ||
| const accentGreenBg = 'rgba(16, 185, 129, 0.05)'; | ||
|
|
||
|
|
@@ -62,6 +65,12 @@ | |
| globalCategory = instance.fingerprint?.global_category ?? ""; | ||
| globalPresetIndex = instance.fingerprint?.global_preset_index ?? -1; | ||
| autoMode = instance.fingerprint?.auto_fingerprint === true; | ||
| autoChangeWindowSize = instance.fingerprint?.auto_change_window_size !== false; | ||
| autoWindowPresetIndex = WINDOW_PRESETS.findIndex( | ||
| (p) => | ||
| p.w === instance.fingerprint?.outer_width && | ||
| p.h === instance.fingerprint?.outer_height | ||
| ); | ||
| } | ||
|
|
||
| // ── Save / Reset ─────────────────────────────────────────────────────────── | ||
|
|
@@ -118,6 +127,19 @@ | |
| fp.global_preset_index = globalPresetIndex >= 0 ? globalPresetIndex : null; | ||
| // Persist AUTO mode settings | ||
| fp.auto_fingerprint = autoMode || null; | ||
| fp.auto_change_window_size = autoMode ? autoChangeWindowSize : null; | ||
| if (autoMode) { | ||
| const preset = !autoChangeWindowSize && autoWindowPresetIndex >= 0 ? WINDOW_PRESETS[autoWindowPresetIndex] : null; | ||
| if (preset) { | ||
| fp.outer_width = preset.w; | ||
| fp.outer_height = preset.h; | ||
| } else { | ||
| fp.outer_width = null; | ||
| fp.outer_height = null; | ||
| } | ||
| fp.inner_width = null; | ||
| fp.inner_height = null; | ||
| } | ||
|
Comment on lines
+130
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic for setting window dimensions in AUTO mode can be refactored to be more concise and avoid repetition. The |
||
| await updateInstanceSettings(instance.id, fp); | ||
| dispatch("close"); | ||
| } catch (e) { | ||
|
|
@@ -135,6 +157,8 @@ | |
| globalCategory = ""; | ||
| globalPresetIndex = -1; | ||
| autoMode = false; | ||
| autoChangeWindowSize = true; | ||
| autoWindowPresetIndex = -1; | ||
| } | ||
| function handleClose() { | ||
| dispatch("close"); | ||
|
|
@@ -190,6 +214,41 @@ | |
| <p style="margin: 12px 0 0; font-size: 0.6rem; color: var(--text-secondary); letter-spacing: 0.03em; line-height: 1.5;"> | ||
| Camoufox's built-in browserforge will automatically generate a unique fingerprint on each launch. All fields — navigator, screen, WebGL, fonts, audio, canvas, and more — are handled automatically. | ||
| </p> | ||
| <div style="margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(16, 185, 129, 0.2); display: flex; align-items: center; justify-content: space-between; gap: 12px;"> | ||
| <div style="display: flex; flex-direction: column; gap: 4px;"> | ||
| <span style="font-size: 0.58rem; letter-spacing: 0.08em; color: var(--text-primary);">CHANGE WINDOW SIZE EACH LAUNCH</span> | ||
| <span style="font-size: 0.55rem; letter-spacing: 0.03em; color: var(--text-secondary);"> | ||
| {autoChangeWindowSize | ||
| ? 'Randomizes window size and position every launch.' | ||
| : 'Keeps window size and position deterministic for the selected profile.'} | ||
| </span> | ||
| </div> | ||
| <button | ||
| class="btn {autoChangeWindowSize ? 'btn-active' : ''}" | ||
| style="font-size: 0.58rem; padding: 4px 10px; min-width: 50px; letter-spacing: 0.05em; {autoChangeWindowSize ? `background: ${accentGreen}; color: #000; border-color: ${accentGreen};` : ''}" | ||
| on:click={() => { autoChangeWindowSize = !autoChangeWindowSize; }} | ||
| > | ||
| {autoChangeWindowSize ? 'ON' : 'OFF'} | ||
| </button> | ||
| </div> | ||
| <div style="margin-top: 10px; display: flex; flex-direction: column; gap: 6px; opacity: {autoChangeWindowSize ? 0.6 : 1};"> | ||
| <label for="auto-window-size-preset" style="font-size: 0.58rem; letter-spacing: 0.08em; color: var(--text-primary);">DEFAULT WINDOW SIZE PRESET</label> | ||
| <select | ||
| id="auto-window-size-preset" | ||
| class="input-field" | ||
| style="font-size: 0.65rem;" | ||
| bind:value={autoWindowPresetIndex} | ||
| disabled={autoChangeWindowSize} | ||
| > | ||
| <option value={-1}>AUTO DEFAULT</option> | ||
| {#each WINDOW_PRESETS as p, i} | ||
| <option value={i}>{p.label}</option> | ||
| {/each} | ||
| </select> | ||
| <span style="font-size: 0.54rem; letter-spacing: 0.03em; color: var(--text-secondary);"> | ||
| Applies when window-size changing is OFF. | ||
| </span> | ||
| </div> | ||
|
Comment on lines
+217
to
+251
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section contains a lot of inline styles. For better maintainability, readability, and separation of concerns, it's recommended to move these styles into the |
||
| {/if} | ||
| </div> | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block uses several magic numbers (
75..=100,800,600,0.9). To improve readability and maintainability, consider defining them as named constants at the top of the module. This makes the code self-documenting and easier to modify in the future.For example: