Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
f9238559
Commit
f9238559
authored
Jul 16, 2023
by
Jeffrey Morgan
Browse files
app: keep installer in foreground
parent
9386073e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
40 deletions
+49
-40
app/src/app.tsx
app/src/app.tsx
+12
-31
app/src/index.ts
app/src/index.ts
+13
-9
app/src/install.ts
app/src/install.ts
+24
-0
No files found.
app/src/app.tsx
View file @
f9238559
import
{
useState
}
from
'
react
'
import
{
useState
}
from
'
react
'
import
copy
from
'
copy-to-clipboard
'
import
copy
from
'
copy-to-clipboard
'
import
{
exec
as
cbExec
}
from
'
child_process
'
import
*
as
path
from
'
path
'
import
*
as
fs
from
'
fs
'
import
{
DocumentDuplicateIcon
}
from
'
@heroicons/react/24/outline
'
import
{
DocumentDuplicateIcon
}
from
'
@heroicons/react/24/outline
'
import
{
app
}
from
'
@electron/remote
'
import
Store
from
'
electron-store
'
import
OllamaIcon
from
'
./ollama.svg
'
import
{
getCurrentWindow
}
from
'
@electron/remote
'
import
{
promisify
}
from
'
util
'
const
ollama
=
app
.
isPackaged
?
path
.
join
(
process
.
resourcesPath
,
'
ollama
'
)
:
path
.
resolve
(
process
.
cwd
(),
'
..
'
,
'
ollama
'
)
const
exec
=
promisify
(
cbExec
)
async
function
installCLI
()
{
const
symlinkPath
=
'
/usr/local/bin/ollama
'
if
(
fs
.
existsSync
(
symlinkPath
)
&&
fs
.
readlinkSync
(
symlinkPath
)
===
ollama
)
{
return
}
const
command
=
`do shell script "ln -F -s
${
ollama
}
/usr/local/bin/ollama" with administrator privileges`
import
{
install
}
from
'
./install
'
import
OllamaIcon
from
'
./ollama.svg
'
try
{
const
store
=
new
Store
()
await
exec
(
`osascript -e '
${
command
}
'`
)
}
catch
(
error
)
{
console
.
error
(
`cli: failed to install cli:
${
error
.
message
}
`
)
return
}
}
enum
Step
{
enum
Step
{
WELCOME
=
0
,
WELCOME
=
0
,
...
@@ -40,7 +21,7 @@ export default function () {
...
@@ -40,7 +21,7 @@ export default function () {
const
command
=
'
ollama run orca
'
const
command
=
'
ollama run orca
'
return
(
return
(
<
div
className
=
'
drag
mx-auto flex min-h-screen w-full flex-col justify-between bg-white px-4 pt-16'
>
<
div
className
=
'mx-auto flex min-h-screen w-full flex-col justify-between bg-white px-4 pt-16'
>
{
step
===
Step
.
WELCOME
&&
(
{
step
===
Step
.
WELCOME
&&
(
<>
<>
<
div
className
=
'mx-auto text-center'
>
<
div
className
=
'mx-auto text-center'
>
...
@@ -49,9 +30,7 @@ export default function () {
...
@@ -49,9 +30,7 @@ export default function () {
Let's get you up and running with your own large language models.
Let's get you up and running with your own large language models.
</
p
>
</
p
>
<
button
<
button
onClick
=
{
()
=>
{
onClick
=
{
()
=>
setStep
(
Step
.
CLI
)
}
setStep
(
1
)
}
}
className
=
'rounded-dm mx-auto my-8 w-[40%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
className
=
'rounded-dm mx-auto my-8 w-[40%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
>
>
Next
Next
...
@@ -70,9 +49,10 @@ export default function () {
...
@@ -70,9 +49,10 @@ export default function () {
<
div
className
=
'mx-auto'
>
<
div
className
=
'mx-auto'
>
<
button
<
button
onClick
=
{
async
()
=>
{
onClick
=
{
async
()
=>
{
await
installCLI
()
await
install
()
window
.
focus
()
getCurrentWindow
().
show
()
setStep
(
2
)
getCurrentWindow
().
focus
()
setStep
(
Step
.
FINISH
)
}
}
}
}
className
=
'rounded-dm mx-auto w-[60%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
className
=
'rounded-dm mx-auto w-[60%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
>
>
...
@@ -107,6 +87,7 @@ export default function () {
...
@@ -107,6 +87,7 @@ export default function () {
</
div
>
</
div
>
<
button
<
button
onClick
=
{
()
=>
{
onClick
=
{
()
=>
{
store
.
set
(
'
first-time-run
'
,
true
)
window
.
close
()
window
.
close
()
}
}
}
}
className
=
'rounded-dm mx-auto w-[60%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
className
=
'rounded-dm mx-auto w-[60%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
...
...
app/src/index.ts
View file @
f9238559
...
@@ -6,6 +6,7 @@ import 'winston-daily-rotate-file'
...
@@ -6,6 +6,7 @@ import 'winston-daily-rotate-file'
import
*
as
path
from
'
path
'
import
*
as
path
from
'
path
'
import
{
analytics
,
id
}
from
'
./telemetry
'
import
{
analytics
,
id
}
from
'
./telemetry
'
import
{
installed
,
install
}
from
'
./install
'
require
(
'
@electron/remote/main
'
).
initialize
()
require
(
'
@electron/remote/main
'
).
initialize
()
...
@@ -40,12 +41,13 @@ function firstRunWindow() {
...
@@ -40,12 +41,13 @@ function firstRunWindow() {
frame
:
false
,
frame
:
false
,
fullscreenable
:
false
,
fullscreenable
:
false
,
resizable
:
false
,
resizable
:
false
,
movable
:
fals
e
,
movable
:
tru
e
,
transparent
:
tru
e
,
show
:
fals
e
,
webPreferences
:
{
webPreferences
:
{
nodeIntegration
:
true
,
nodeIntegration
:
true
,
contextIsolation
:
false
,
contextIsolation
:
false
,
},
},
alwaysOnTop
:
true
,
})
})
require
(
'
@electron/remote/main
'
).
enable
(
welcomeWindow
.
webContents
)
require
(
'
@electron/remote/main
'
).
enable
(
welcomeWindow
.
webContents
)
...
@@ -53,6 +55,8 @@ function firstRunWindow() {
...
@@ -53,6 +55,8 @@ function firstRunWindow() {
// and load the index.html of the app.
// and load the index.html of the app.
welcomeWindow
.
loadURL
(
MAIN_WINDOW_WEBPACK_ENTRY
)
welcomeWindow
.
loadURL
(
MAIN_WINDOW_WEBPACK_ENTRY
)
welcomeWindow
.
on
(
'
ready-to-show
'
,
()
=>
welcomeWindow
.
show
())
// for debugging
// for debugging
// welcomeWindow.webContents.openDevTools()
// welcomeWindow.webContents.openDevTools()
...
@@ -151,15 +155,15 @@ app.on('ready', () => {
...
@@ -151,15 +155,15 @@ app.on('ready', () => {
createSystemtray
()
createSystemtray
()
server
()
server
()
if
(
!
store
.
has
(
'
first-time-run
'
))
{
if
(
store
.
get
(
'
first-time-run
'
)
&&
installed
())
{
// This is the first run
app
.
setLoginItemSettings
({
openAtLogin
:
true
})
firstRunWindow
()
store
.
set
(
'
first-time-run
'
,
true
)
}
else
{
// The app has been run before
app
.
setLoginItemSettings
({
openAtLogin
:
app
.
getLoginItemSettings
().
openAtLogin
})
app
.
setLoginItemSettings
({
openAtLogin
:
app
.
getLoginItemSettings
().
openAtLogin
})
return
}
}
// This is the first run or the CLI is no longer installed
app
.
setLoginItemSettings
({
openAtLogin
:
true
})
firstRunWindow
()
})
})
// Quit when all windows are closed, except on macOS. There, it's common
// Quit when all windows are closed, except on macOS. There, it's common
...
...
app/src/install.ts
0 → 100644
View file @
f9238559
import
*
as
fs
from
'
fs
'
import
{
exec
as
cbExec
}
from
'
child_process
'
import
*
as
path
from
'
path
'
import
{
promisify
}
from
'
util
'
const
app
=
process
&&
process
.
type
===
'
renderer
'
?
require
(
'
@electron/remote
'
).
app
:
require
(
'
electron
'
).
app
const
ollama
=
app
.
isPackaged
?
path
.
join
(
process
.
resourcesPath
,
'
ollama
'
)
:
path
.
resolve
(
process
.
cwd
(),
'
..
'
,
'
ollama
'
)
const
exec
=
promisify
(
cbExec
)
const
symlinkPath
=
'
/usr/local/bin/ollama
'
export
function
installed
()
{
return
fs
.
existsSync
(
symlinkPath
)
&&
fs
.
readlinkSync
(
symlinkPath
)
===
ollama
}
export
async
function
install
()
{
const
command
=
`do shell script "ln -F -s
${
ollama
}
${
symlinkPath
}
" with administrator privileges`
try
{
await
exec
(
`osascript -e '
${
command
}
'`
)
}
catch
(
error
)
{
console
.
error
(
`cli: failed to install cli:
${
error
.
message
}
`
)
return
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment