-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
229 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
apps/content/src/browser/components/omnibox/ZoomDisplay.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
|
||
<script lang="ts"> | ||
export let zoom: number | ||
</script> | ||
|
||
{#if zoom != 1} | ||
<button on:click> | ||
{Math.round(zoom * 100)}% | ||
</button> | ||
{/if} | ||
|
||
<style> | ||
button { | ||
background: var(--surface); | ||
border: none; | ||
cursor: pointer; | ||
border-radius: 0.25rem; | ||
height: 2rem; | ||
margin-right: 0.125rem; | ||
} | ||
button:hover { | ||
background: var(--surface-1); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// @ts-check | ||
/// <reference types="@browser/link" /> | ||
import mitt from 'resource://app/modules/mitt.sys.mjs' | ||
|
||
const ZOOM_STORE_FILE = PathUtils.join(PathUtils.profileDir, 'zoomstore.json') | ||
|
||
/** @typedef {import("resource://app/modules/ZoomStore.sys.mjs").ZoomStoreInterface} ZoomStoreInterface */ | ||
|
||
/** @implements {ZoomStoreInterface} */ | ||
class ZoomStoreImpl { | ||
/** | ||
* @private | ||
* @type {Map<string, number> | null} | ||
*/ | ||
zoomPages = null | ||
|
||
/** @type {import('resource://app/modules/mitt.sys.mjs').Emitter<import('resource://app/modules/ZoomStore.sys.mjs').ZoomStoreEvents>} */ | ||
events = mitt() | ||
|
||
constructor() { | ||
this.init() | ||
} | ||
|
||
/** @protected */ | ||
async init() { | ||
if (this.zoomPages) { | ||
return | ||
} | ||
|
||
if (!(await IOUtils.exists(ZOOM_STORE_FILE))) { | ||
this.zoomPages = new Map() | ||
return | ||
} | ||
|
||
try { | ||
const pages = await IOUtils.readJSON(ZOOM_STORE_FILE) | ||
if (this.zoomPages) { | ||
return | ||
} | ||
|
||
this.zoomPages = new Map(pages) | ||
} catch (e) { | ||
console.error('Failed to load zoomStore from file: ', e) | ||
return | ||
} | ||
} | ||
|
||
/** @private */ | ||
async save() { | ||
if (!this.zoomPages) { | ||
return | ||
} | ||
|
||
const toWrite = Array.from(this.zoomPages.entries()) | ||
try { | ||
await IOUtils.writeJSON(ZOOM_STORE_FILE, toWrite) | ||
} catch (e) { | ||
console.error('Failed to write zoomStore to file:', e) | ||
return | ||
} | ||
} | ||
|
||
/** | ||
* @param {nsIURIType} uri The uri to check zoom for | ||
* @returns {number} | ||
*/ | ||
getZoomForUri(uri) { | ||
return this.zoomPages?.get(uri.asciiHost) || 1 | ||
} | ||
|
||
/** | ||
* @param {nsIURIType} uri | ||
* @param {number} zoom The zoom to store. If set to 1, will delete any stored values | ||
*/ | ||
setZoomForUri(uri, zoom) { | ||
try { | ||
uri.host | ||
} catch { | ||
return | ||
} | ||
|
||
if (zoom === 1) { | ||
this.zoomPages?.delete(uri.host) | ||
this.events.emit('setZoom', { host: uri.host, zoom }) | ||
return | ||
} | ||
|
||
this.zoomPages?.set(uri.host, Math.round(zoom * 100) / 100) | ||
|
||
// @ts-ignore | ||
Services.tm.dispatchToMainThread(() => { | ||
this.events.emit('setZoom', { host: uri.host, zoom }) | ||
this.save() | ||
}) | ||
} | ||
} | ||
|
||
export const ZoomStore = new ZoomStoreImpl() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
declare module 'resource://app/modules/ZoomStore.sys.mjs' { | ||
import { Emitter } from 'mitt' | ||
|
||
export type ZoomStoreEvents = { | ||
setZoom: { host: string; zoom: number } | ||
} | ||
|
||
export const ZoomStore: { | ||
events: Emitter<ZoomStoreEvents> | ||
|
||
getZoomForUri(uri: nsIURIType): number | ||
setZoomForUri(uri: nsIURIType, zoom: number): void | ||
} | ||
|
||
export type ZoomStoreInterface = typeof ZoomStore | ||
} | ||
|
||
declare interface MozESMExportFile { | ||
ZoomStore: 'resource://app/modules/ZoomStore.sys.mjs' | ||
} | ||
|
||
declare interface MozESMExportType { | ||
ZoomStore: typeof import('resource://app/modules/ZoomStore.sys.mjs').ZoomStore | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.