Skip to content

Commit a5f0888

Browse files
committed
Update: Handle storage settings, misc URL fixes and HTML
1 parent 0a79d74 commit a5f0888

File tree

6 files changed

+207
-12
lines changed

6 files changed

+207
-12
lines changed

src/cron/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,19 @@ class DataStore {
4242
window_name: getMacAppWindowTitle(),
4343
}
4444

45-
if (appName === 'Google Chrome' || appName === 'Brave Browser') {
45+
if (
46+
appName === 'Google Chrome' ||
47+
appName === 'Brave Browser' ||
48+
appName === 'Safari'
49+
) {
4650
data.current_url = getMacBrowserCurrentTabURL(appName)
47-
data.page_html = getMacBrowserWindowHTML(appName)
48-
data.links = this._extractLinks(data.page_html)
51+
try {
52+
if (this.setupData.code_storage_enabled !== false)
53+
data.page_html = getMacBrowserWindowHTML(appName)
54+
else console.log('Code storage disabled, not storing HTML')
55+
} catch (err) {
56+
console.error("Error fetching browser's active tab HTML:", err)
57+
}
4958
}
5059

5160
return data
@@ -111,6 +120,7 @@ class DataStore {
111120
setup_check__server: storage_client.get('setup_check__server'),
112121
manual_stop: false,
113122
incognito_keywords: getIncognitoKeywords(),
123+
code_storage_enabled: storage_client.get('code_storage_enabled'),
114124
}
115125
}
116126

src/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ ipcMain.handle('dashboard-set-incognito-keywords', async (event, keywords) => {
112112
return resp
113113
})
114114

115+
ipcMain.handle('dashboard-get-code-storage-enabled', async (event) => {
116+
let val = storage_client.get('code_storage_enabled')
117+
return val
118+
})
119+
120+
ipcMain.handle('dashboard-set-code-storage-enabled', async (event, enabled) => {
121+
storage_client.set('code_storage_enabled', enabled)
122+
dataStoreCron.updateData()
123+
})
124+
115125
ipcMain.handle('show-window', async (event, window) => {
116126
await mainWindow.loadFile(path.join(__dirname, window))
117127
mainWindow.show()

src/pages/dashboard.html

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/>
2929
</head>
3030

31-
<body class="">
31+
<body class="mb-10 p-10">
3232
<!-- Nav Bar -->
3333
<nav class="navbar bg-body-tertiary">
3434
<div class="container-fluid">
@@ -89,6 +89,108 @@ <h5 class="card-title">
8989
</div>
9090
-->
9191

92+
<!-- Modal -->
93+
<div
94+
class="modal fade"
95+
id="how_to_enable_applescript_js_modal"
96+
tabindex="-1"
97+
aria-labelledby="how_to_enable_applescript_js_modal"
98+
aria-hidden="true"
99+
>
100+
<div class="modal-dialog">
101+
<div class="modal-content">
102+
<div class="modal-header">
103+
<h1
104+
class="modal-title fs-5"
105+
id="how_to_enable_applescript_js_modal"
106+
>
107+
Enable Applescript on Your Browsers
108+
</h1>
109+
<button
110+
type="button"
111+
class="btn-close"
112+
data-bs-dismiss="modal"
113+
aria-label="Close"
114+
></button>
115+
</div>
116+
<div class="modal-body">
117+
<p class="">
118+
To enable granular storage, you will need to allow
119+
applescript execution in Brave, Chrome and Safari.
120+
</p>
121+
122+
<p>For Brave and Chrome:</p>
123+
<ol>
124+
<li>Open the browsers (Brave and Chrome)</li>
125+
<li>Go to "View"</li>
126+
<li>Go to "Developer"</li>
127+
<li>
128+
Click on "Allow Javascript from Apple Events"
129+
</li>
130+
<li>Restart Chrome, Brave and Infr</li>
131+
</ol>
132+
133+
<p>For Safari:</p>
134+
<ol>
135+
<li>Open the Safari Browser</li>
136+
<li>Go to "Develop"</li>
137+
<li>
138+
Click on "Allow Javascript from Apple Events"
139+
</li>
140+
<li>Restart Safari and Infr</li>
141+
</ol>
142+
<img
143+
class="img-fluid"
144+
src="https://res.cloudinary.com/dcwz20wdd/video/upload/q_auto:eco/v1694600455/Enable_AppleScript_Access_trjggc.gif"
145+
/>
146+
</div>
147+
<div class="modal-footer"></div>
148+
</div>
149+
</div>
150+
</div>
151+
152+
<!-- Code Storage -->
153+
<div class="container mt-5">
154+
<div class="card">
155+
<h5 class="card-header bg-primary text-white">
156+
Granular Storage
157+
<button class="mb-n2 btn btn-success btn-sm ml-3">
158+
Recommended
159+
</button>
160+
</h5>
161+
<div class="card-body">
162+
<p class="card-text">
163+
Allow Infr to store relivable snippets from websites you
164+
visit. This will allow you to revisit the page at any
165+
time in the future.
166+
</p>
167+
<p
168+
class="h6 mb-3"
169+
type="button"
170+
class="btn btn-primary"
171+
data-bs-toggle="modal"
172+
data-bs-target="#how_to_enable_applescript_js_modal"
173+
>
174+
How do I enable this on the browser?
175+
</p>
176+
<input
177+
type="checkbox"
178+
class="btn-check"
179+
id="btn_is_code_storage_enabled"
180+
onclick="handleChangeInCodeStorage()"
181+
autocomplete="off"
182+
checked
183+
/>
184+
<label
185+
class="btn btn-outline-success"
186+
for="btn_is_code_storage_enabled"
187+
id="btn_is_code_storage_enabled_label"
188+
>Code Storage Enabled</label
189+
><br />
190+
</div>
191+
</div>
192+
</div>
193+
92194
<!-- incognito Keywords -->
93195
<div class="container mt-5">
94196
<div class="card">
@@ -98,8 +200,8 @@ <h5 class="card-header bg-primary d-flex text-white">
98200
<div class="card-body">
99201
<p class="card-text">
100202
Apps or websites that include any of the following
101-
keywords will not be tracked. Capitalization does not
102-
matter.
203+
keywords will not be tracked, stored or recorded in any
204+
way. Capitalization does not matter.
103205
</p>
104206
<p class="h6">Useful defaults</p>
105207

src/preload.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ contextBridge.exposeInMainWorld('infrDashboard', {
3737
)
3838
return resp
3939
},
40+
getCodeStorageEnabled: async function () {
41+
let resp = await ipcRenderer.invoke(
42+
'dashboard-get-code-storage-enabled',
43+
)
44+
return resp
45+
},
46+
setCodeStorageEnabled: async function (enabled) {
47+
let resp = await ipcRenderer.invoke(
48+
'dashboard-set-code-storage-enabled',
49+
enabled,
50+
)
51+
return resp
52+
},
4053
})
4154

4255
contextBridge.exposeInMainWorld('infrWindow', {

src/scripts/dashboard.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,58 @@ function addTagOnClick(tag_name) {
6060
tagify.addTags(tag_name)
6161
}
6262

63+
function handleChangeInCodeStorage() {
64+
let btn = document.getElementById('btn_is_code_storage_enabled')
65+
let label = document.getElementById('btn_is_code_storage_enabled_label')
66+
67+
if (btn.checked) {
68+
window.infrDashboard.setCodeStorageEnabled(true)
69+
70+
// Update text & class
71+
label.classList.remove('btn-outline-danger')
72+
label.classList.add('btn-outline-success')
73+
label.innerHTML = 'Code Storage Enabled'
74+
} else {
75+
window.infrDashboard.setCodeStorageEnabled(false)
76+
77+
// Update text
78+
label.classList.remove('btn-outline-success')
79+
label.classList.add('btn-outline-danger')
80+
label.innerHTML = 'Code Storage Disabled'
81+
}
82+
}
83+
84+
function loadCodeStorageEnabled() {
85+
try {
86+
window.infrDashboard.getCodeStorageEnabled().then((enabled) => {
87+
let btn = document.getElementById('btn_is_code_storage_enabled')
88+
let label = document.getElementById(
89+
'btn_is_code_storage_enabled_label',
90+
)
91+
92+
// Null is considered true
93+
if (enabled === false) {
94+
btn.checked = false
95+
96+
// Update text
97+
label.classList.remove('btn-outline-success')
98+
label.classList.add('btn-outline-danger')
99+
label.innerHTML = 'Code Storage Disabled'
100+
} else {
101+
btn.checked = true
102+
103+
// Update text & class
104+
label.classList.remove('btn-outline-danger')
105+
label.classList.add('btn-outline-success')
106+
label.innerHTML = 'Code Storage Enabled'
107+
}
108+
})
109+
} catch (err) {}
110+
}
111+
63112
function loadPage() {
64113
loadIncognitoKeywords()
114+
loadCodeStorageEnabled()
65115
}
66116

67117
loadPage()

src/tools/systemCall.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,25 @@ function getMacAppWindowTitle() {
2727

2828
function getMacBrowserCurrentTabURL(browserName) {
2929
try {
30-
const url = execSync(
31-
`osascript -e \'tell app "${browserName}" to get the URL of the active tab of its first window\'`,
32-
)
33-
.toString()
34-
.trim()
30+
let script = ''
31+
32+
if (browserName === 'Safari') {
33+
script =
34+
'tell application "Safari" to get URL of current tab of front window'
35+
} else if (
36+
browserName === 'Google Chrome' ||
37+
browserName === 'Brave Browser'
38+
) {
39+
script = `tell application "${browserName}" to get the URL of the active tab of its first window`
40+
} else {
41+
throw new Error(`Unsupported browser: ${browserName}`)
42+
}
3543

44+
const url = execSync(`osascript -e '${script}'`).toString().trim()
45+
console.log(`${browserName} URL: ${url}`)
3646
return url
3747
} catch (err) {
38-
console.error("Error fetching Chrome's active tab URL:", err)
48+
console.error(`Error fetching ${browserName}'s active tab URL:`, err)
3949
return null
4050
}
4151
}

0 commit comments

Comments
 (0)