Skip to content

Edge-Drop is a clipboard shelf on the edge of your screen. Hover to open it. Drag files and images into any app, click to copy text and links. Free and open-source for Windows.

feat(onboarding): welcome updaters with the new tour once, in the device's language

Deepender2583a935f23f69
diff --git a/electron/main/index.ts b/electron/main/index.ts
index 0454827..a5745c5 100644
--- a/electron/main/index.ts
+++ b/electron/main/index.ts
@@ -18,9 +18,10 @@ import { reconcileLaunchAtLoginOnStartup } from './loginItems'
import { isStoreBuild, shouldStartHidden } from './config'
import { prewarmDragIcons, setFileNameWords } from './drag'
import { mainT } from './i18n'
-import { initState, getWatcher, loadSettings, saveSettings, pushState, stopStateTimers, getStore } from './state'
+import { initState, getWatcher, loadSettings, pushState, stopStateTimers, getStore } from './state'
import { initAutoUpdater } from './updater'
import { createOnboardingWindow } from './onboardingWindow'
+import { onboardingDue } from '../../shared/onboarding'
import { startFullscreenMonitor, stopFullscreenMonitor, triggerFullscreenCheck } from './fullscreen'
import { flushStagedTempRegistry } from './stagedTemp'
import { extname, join, normalize } from 'node:path'
@@ -47,6 +48,9 @@ app.enableSandbox()
app.commandLine.appendSwitch('js-flags', '--max-old-space-size=512 --expose-gc')
// ---- single instance -------------------------------------------------------
+/** After an update, a silent start at login shows the new tour this long after launch (see onboardingDue). */
+const UPDATE_TOUR_DELAY_AT_LOGIN_MS = 15_000
+
const gotLock = app.requestSingleInstanceLock()
if (!gotLock) {
app.quit()
@@ -124,19 +128,23 @@ app.whenReady().then(() => {
prewarmDragIcons(isInteractive)
// Reflect settings immediately.
- let settings = loadSettings()
+ const settings = loadSettings()
const hiddenLaunch = shouldStartHidden()
if (hiddenLaunch) {
console.log('[Main] Login launch detected (--hidden / wasOpenedAtLogin) — starting silently in tray')
}
- if (!settings.tutorialCompleted && !hiddenLaunch) {
- // When onboarding is active (initial launch or reset tutorial), reset language to system default so onboarding always begins in System Default
- if (settings.language !== 'system') {
- settings = saveSettings({ language: 'system' })
- }
+ const tour = onboardingDue(settings)
+ // The tour plays in the device's own language (Onboarding.tsx); the saved language is left as it is.
+ if (tour === 'first-run' && !hiddenLaunch) {
setTimeout(() => {
createOnboardingWindow()
}, 2000)
+ } else if (tour === 'update') {
+ // Someone who finished an older tour sees this one once. Also on a silent start at login (many
+ // only ever start Edge-Drop that way), later, once Windows has settled.
+ setTimeout(() => {
+ createOnboardingWindow()
+ }, hiddenLaunch ? UPDATE_TOUR_DELAY_AT_LOGIN_MS : 2000)
}
setHotZoneWidth(settings.hotZoneWidth || 3)
// files the app writes (drag-out, paste into Explorer, Save to Downloads) are named in the user's language
diff --git a/electron/main/onboardingWindow.ts b/electron/main/onboardingWindow.ts
index bff8eb8..06fa1b5 100644
--- a/electron/main/onboardingWindow.ts
+++ b/electron/main/onboardingWindow.ts
@@ -1,6 +1,7 @@
import { BrowserWindow } from 'electron'
import { join } from 'node:path'
import { saveSettings, loadSettings, pushState } from './state'
+import { ONBOARDING_VERSION } from '../../shared/onboarding'
let onboardingWindow: BrowserWindow | null = null
@@ -49,10 +50,10 @@ export function createOnboardingWindow(): void {
onboardingWindow.on('closed', () => {
onboardingWindow = null
- // If closed, consider tutorial completed
+ // If closed, consider tutorial completed: this tour, so updates don't show it again (shared/onboarding.ts)
const settings = loadSettings()
- if (!settings.tutorialCompleted) {
- const next = saveSettings({ tutorialCompleted: true })
+ if (!settings.tutorialCompleted || (settings.onboardingVersion ?? 0) < ONBOARDING_VERSION) {
+ const next = saveSettings({ tutorialCompleted: true, onboardingVersion: ONBOARDING_VERSION })
pushState.settings(next)
}
})
diff --git a/electron/store/settings.ts b/electron/store/settings.ts
index 9bbe069..7a4cb71 100644
--- a/electron/store/settings.ts
+++ b/electron/store/settings.ts
@@ -50,6 +50,8 @@ function merge(base: Settings, patch: Partial<Settings>): Settings {
// persisted skip from older builds is self-healed away on load. This also
// un-sticks anyone whose prompt went permanently silent.
out.skippedUpdateVersion = undefined
+ // a hand-edited or odd value never hides the tour or shows it forever
+ if (typeof out.onboardingVersion !== 'number' || !Number.isFinite(out.onboardingVersion)) out.onboardingVersion = undefined
return out
}
diff --git a/shared/onboarding.ts b/shared/onboarding.ts
new file mode 100644
index 0000000..97f1ad6
--- /dev/null
+++ b/shared/onboarding.ts
@@ -0,0 +1,19 @@
+import type { Settings } from './types'
+
+/**
+ * The welcome tour's version. Everyone whose saved onboardingVersion is lower sees the tour once on
+ * their next launch, updaters included; finishing it (any way out of the window) saves this number.
+ * Raise it only when the tour changes enough that everyone should see it again.
+ * 1: the tour before 0.4.0 (never saved; those users only have tutorialCompleted)
+ * 2: the tour played by the real app (0.4.0)
+ */
+export const ONBOARDING_VERSION = 2
+
+/**
+ * Whether this launch should open the welcome tour: 'first-run' for a new install (or a reset
+ * tutorial), 'update' for someone who finished an older tour, null when they have seen this one.
+ */
+export function onboardingDue(s: Pick<Settings, 'tutorialCompleted' | 'onboardingVersion'>): 'first-run' | 'update' | null {
+ if ((s.onboardingVersion ?? 0) >= ONBOARDING_VERSION) return null
+ return s.tutorialCompleted ? 'update' : 'first-run'
+}
diff --git a/shared/types.ts b/shared/types.ts
index 30a1e41..7bc26b8 100644
--- a/shared/types.ts
+++ b/shared/types.ts
@@ -176,6 +176,8 @@ export interface Settings {
uiStyle: 'modern' | 'compact'
/** Flag to track if the onboarding tutorial is completed. */
tutorialCompleted: boolean
+ /** The welcome tour version the user has finished (shared/onboarding.ts); absent before 0.4.0. */
+ onboardingVersion?: number
stickPosition: StickPosition
stickDisplayId?: number
/**
@@ -253,6 +255,7 @@ export const DEFAULT_SETTINGS: Settings = {
autoDeleteHours: 0,
uiStyle: 'modern',
tutorialCompleted: false,
+ onboardingVersion: undefined,
stickPosition: 'left',
stickDisplayId: undefined,
stickDisplayWorkArea: undefined,
diff --git a/src/Onboarding.tsx b/src/Onboarding.tsx
index dd637df..baac62f 100644
--- a/src/Onboarding.tsx
+++ b/src/Onboarding.tsx
@@ -21,6 +21,7 @@ import { edge } from './lib/edge'
import { applyReduceMotion } from './lib/theme'
import { useTranslation } from './i18n'
import { DEFAULT_SETTINGS, type Settings, type StickPosition } from '../shared/types'
+import { ONBOARDING_VERSION } from '../shared/onboarding'
import { PEN_PATH, PEN_TRANSFORM, PEN_WIDTH, GLASS_BOX, SHADOW_BOX, BLUR_BOX, penProgress } from './onboarding/lettering'
import { CHOICE_VIEW, DEMOS, PREVIEW_PAN, Run, STOP, demoEdges, itemsFor, playLooped, resetDemoState, showEdge, watchActivity, type Stage } from './onboarding/tour'
import { realScreenTransform, realSidePanel, tourBar, shelfTransform, topBarLength, SHELF_SCALE, TOUR_SCREEN_TOP } from './onboarding/edgeBar'
@@ -174,8 +175,9 @@ export function Onboarding() {
.catch((e) => { if (e !== STOP) console.error(e) })
}
- // The tour's own store: the user's settings (language, motion, accent), the
- // shelf docked at the top for the demo, and no items of the user's.
+ // The tour's own store: the user's settings (motion, accent) in the device's own
+ // language, the shelf docked at the top for the demo, and no items of the user's.
+ // The language is the tour's alone: the user's saved choice is never changed by it.
useEffect(() => {
let cancelled = false
// Marks the page for shelf parts portaled outside the tour's scaled layer (see .ob-tour).
@@ -192,6 +194,7 @@ export function Onboarding() {
useStore.setState({
settings: {
...settings,
+ language: 'system',
stickPosition: 'top',
triggerAlignment: 'center',
horizontalOffset: DEFAULT_SETTINGS.horizontalOffset,
@@ -323,7 +326,7 @@ export function Onboarding() {
const finish = async () => {
runRef.current?.cancel()
- await edge.updateSettings({ tutorialCompleted: true })
+ await edge.updateSettings({ tutorialCompleted: true, onboardingVersion: ONBOARDING_VERSION })
window.close()
}
diff --git a/tests/onboardingOnUpdate.test.ts b/tests/onboardingOnUpdate.test.ts
new file mode 100644
index 0000000..7faf248
--- /dev/null
+++ b/tests/onboardingOnUpdate.test.ts
@@ -0,0 +1,96 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
+import { join } from 'node:path'
+import { tmpdir } from 'node:os'
+
+const fsRoots = vi.hoisted(() => ({ userData: '' }))
+
+vi.mock('electron', () => ({
+ app: {
+ isPackaged: false,
+ getAppPath: () => join(fsRoots.userData, 'app'),
+ getPath: (name: string) => (name === 'userData' ? fsRoots.userData : join(fsRoots.userData, name))
+ }
+}))
+
+import { ONBOARDING_VERSION, onboardingDue } from '../shared/onboarding'
+import { loadSettings, resetSettingsCache } from '../electron/store/settings'
+
+const read = (rel: string) => readFileSync(join(__dirname, '..', rel), 'utf8')
+
+describe('who sees the welcome tour', () => {
+ it('a new install sees it (first run)', () => {
+ expect(onboardingDue({ tutorialCompleted: false })).toBe('first-run')
+ })
+
+ it('someone updating from a version before 0.4.0 sees it once (they only finished the old tour)', () => {
+ expect(onboardingDue({ tutorialCompleted: true })).toBe('update')
+ expect(onboardingDue({ tutorialCompleted: true, onboardingVersion: 1 })).toBe('update')
+ })
+
+ it('someone who finished this tour never sees it again on later updates', () => {
+ expect(onboardingDue({ tutorialCompleted: true, onboardingVersion: ONBOARDING_VERSION })).toBeNull()
+ // a later, newer tour would show once again
+ expect(onboardingDue({ tutorialCompleted: true, onboardingVersion: ONBOARDING_VERSION - 1 })).toBe('update')
+ })
+
+ it('this is tour 2: everyone on 0.3.x and older counts as not having seen it', () => {
+ expect(ONBOARDING_VERSION).toBe(2)
+ })
+})
+
+describe('the saved tour version', () => {
+ beforeEach(() => {
+ fsRoots.userData = join(tmpdir(), `edge-drop-tour-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`)
+ mkdirSync(fsRoots.userData, { recursive: true })
+ resetSettingsCache()
+ })
+ afterEach(() => {
+ resetSettingsCache()
+ rmSync(fsRoots.userData, { recursive: true, force: true })
+ })
+
+ it('a settings file from 0.3.x (no version) loads as due for the update tour, keeping its language', () => {
+ writeFileSync(join(fsRoots.userData, 'settings.json'), JSON.stringify({ tutorialCompleted: true, language: 'de' }))
+ const s = loadSettings()
+ expect(s.onboardingVersion).toBeUndefined()
+ expect(s.language).toBe('de')
+ expect(onboardingDue(s)).toBe('update')
+ })
+
+ it('an odd saved value never hides the tour', () => {
+ for (const odd of ['2', null, Number.NaN, {}]) {
+ resetSettingsCache()
+ writeFileSync(join(fsRoots.userData, 'settings.json'), JSON.stringify({ tutorialCompleted: true, onboardingVersion: odd }))
+ expect(loadSettings().onboardingVersion).toBeUndefined()
+ }
+ })
+})
+
+describe('wiring', () => {
+ const index = read('electron/main/index.ts')
+ const win = read('electron/main/onboardingWindow.ts')
+ const tour = read('src/Onboarding.tsx')
+
+ it('launch opens the tour for a first run as before, and for an update even on a silent login start', () => {
+ expect(index).toContain("const tour = onboardingDue(settings)")
+ expect(index).toMatch(/tour === 'first-run' && !hiddenLaunch\)/)
+ expect(index).toMatch(/tour === 'update'\) \{[\s\S]*?createOnboardingWindow\(\)[\s\S]*?hiddenLaunch \? UPDATE_TOUR_DELAY_AT_LOGIN_MS : 2000/)
+ })
+
+ it("the tour plays in the device's own language, and the user's saved language is never changed for it", () => {
+ // the tour's own copy of the settings uses System Default ...
+ expect(tour).toMatch(/useStore\.setState\(\{\s*settings: \{\s*\.\.\.settings,\s*language: 'system',/)
+ // ... and launch saves no language, for a new install or an update
+ const launch = index.slice(index.indexOf('const tour = onboardingDue(settings)'), index.indexOf('setHotZoneWidth'))
+ expect(launch).not.toMatch(/saveSettings|language:/)
+ })
+
+ it('every way out of the tour saves this tour as seen', () => {
+ // closing the window (Skip, the close button, quitting) ...
+ expect(win).toMatch(/\(settings\.onboardingVersion \?\? 0\) < ONBOARDING_VERSION/)
+ expect(win).toContain('saveSettings({ tutorialCompleted: true, onboardingVersion: ONBOARDING_VERSION })')
+ // ... and Get Started
+ expect(tour).toContain('edge.updateSettings({ tutorialCompleted: true, onboardingVersion: ONBOARDING_VERSION })')
+ })
+})